Macaulay2 Engine
Loading...
Searching...
No Matches
PolyRingTest.cpp
Go to the documentation of this file.
1// In BUILD tree in Macaulay2/e:
2// ./M2-unit-tests --gtest_filter="*F4*"
3
35
36#include <vector>
37#include <iostream>
38#include <memory>
39#include <gtest/gtest.h>
40
41#include "../error.h"
42#include "../buffer.hpp"
43#include "../util.hpp"
44#include "../ring.hpp"
45#include "../polyring.hpp"
47#include "../interface/monoid.h"
48#include "../interface/ring.h"
49#include "../interface/aring.h"
50
52
53TEST(PolyRing, createDegreesRing)
54{
55 const Ring* DR = degreeRing(1);
56 EXPECT_FALSE(error());
57 EXPECT_TRUE(DR != nullptr);
58
59 buffer o;
60 DR->text_out(o);
61 std::cout << "ring is " << o.str() << std::endl;
62}
63
64TEST(PolyRing, createDegreesRing2)
65{
66 const Ring* DR = degreeRing({"t1", "t2"});
67 EXPECT_FALSE(error());
68 EXPECT_TRUE(DR != nullptr);
69
70 buffer o;
71 DR->text_out(o);
72 std::cout << "ring is " << o.str() << std::endl;
73}
74
75TEST(PolyRing, create1)
76{
77 // Creaating a polynomial ring from C++.
78 // Plan: this should be a simple constructor call!
79
80 // Create coefficient ring
81 const Ring* kk = rawARingZZpFlint(101); // or IM2_Ring_ZZ(), IM2_Ring_QQ(), and others...
82 EXPECT_TRUE(kk != nullptr);
83
84 // Now create the monomial order. This one is a pain in the butt!
85 std::vector<std::string> varnames { "a", "b", "c", "d" };
86 std::vector<int> degs {1,1,1,1};
87 std::vector<int> heft {1};
88
90 const Monoid* M = Monoid::create(
91 mo,
92 degreeRing(1),
93 varnames,
94 degs,
95 heft
96 );
97 EXPECT_TRUE(M != nullptr);
98
99 const Ring* R = PolyRing::create(kk, M);
100
101 EXPECT_TRUE(R != nullptr);
102 buffer o;
103 R->text_out(o);
104 std::cout << "ring is " << o.str() << std::endl;
105}
106
107TEST(PolyRing, createSimple)
108{
109 // Creaating a polynomial ring from C++.
110 // Plan: this should be a simple constructor call!
111
112 // Create coefficient ring
113 const Ring* R = simplePolynomialRing(101, { "a", "b", "c", "d" });
114
115 EXPECT_TRUE(R != nullptr);
116 buffer o;
117 R->text_out(o);
118 std::cout << "ring is " << o.str() << std::endl;
119}
TEST(PolyRing, createDegreesRing)
Engine-boundary C API for constructing aring-backed coefficient rings.
Append-only GC-backed byte buffer used throughout the engine for text output.
static Monoid * create(const MonomialOrdering *mo, const PolynomialRing *DR, const std::vector< std::string > &names, const std::vector< int > &degs, const std::vector< int > &hefts)
Definition monoid.cpp:61
Engine-side commutative monomial monoid: variable names, ordering, multidegree machinery,...
Definition monoid.hpp:89
static const PolyRing * create(const Ring *K, const Monoid *M)
Definition poly.cpp:101
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
Definition poly.hpp:64
virtual void text_out(buffer &o) const =0
xxx xxx xxx
Definition ring.hpp:102
char * str()
Definition buffer.hpp:72
int error()
Definition error.c:48
Engine error-reporting primitives: ERROR, INTERNAL_ERROR, error, error_message.
const Ring * rawARingZZpFlint(unsigned long p)
Definition aring.cpp:51
Engine-boundary C API for constructing and inspecting Monoid objects.
MonomialOrdering * rawGRevLexMonomialOrdering(M2_arrayint degs, int packing)
Engine-boundary C API for assembling block-level MonomialOrderings from declarative pieces.
PolynomialRing — abstract polynomial-ring base, the engine's most-reused class.
Engine-boundary C API for the legacy Ring hierarchy — coefficient, polynomial, and composite rings.
Ring — the legacy abstract base class for every coefficient and polynomial ring.
Front-end-side description of a monomial ordering as a list of mon_part blocks.
const PolynomialRing * degreeRing(const std::vector< std::string > &names)
const PolynomialRing * simplePolynomialRing(const Ring *kk, const std::vector< std::string > &names, MonomialOrdering *monorder)
One-line helpers for building degree monoids and polynomial rings inside gtest cases.
M2_arrayint stdvector_to_M2_arrayint(const std::vector< T > &v)
Definition util.hpp:79
Conversion helpers between M2 boundary types and standard C++ containers.