Macaulay2 Engine
Loading...
Searching...
No Matches
RingZZpTest.cpp
Go to the documentation of this file.
1// Copyright 2013 Michael E. Stillman
2
32
33#include "RingTest.hpp"
34#include "ZZp.hpp"
35
36template <>
37ring_elem getElement<Z_mod>(const Z_mod& R, int index)
38{
40 return R.from_int(a.get_mpz());
41}
42
43TEST(RingZZmod32003, fromStream)
44{
45 std::istringstream i("+1234 +345 -235*a");
46 Z_mod* R = Z_mod::create(32003);
47 ring_elem a;
48 while (fromStream(i, *R, a))
49 {
50 buffer o;
51 R->elem_text_out(o, a);
52 std::cout << o.str() << " peek: "
53 << "." << static_cast<char>(i.peek()) << "." << std::endl;
54 }
55}
56
58TEST(RingZZmod101, create)
59{
60 Ring* R = Z_mod::create(101);
61 EXPECT_TRUE(R != nullptr);
62
63 EXPECT_TRUE(dynamic_cast<const Z_mod*>(R) != nullptr);
64 EXPECT_EQ(R->coefficient_type(), Ring::COEFF_BASIC);
65 EXPECT_FALSE(R->is_ZZ());
66 EXPECT_EQ(ringName(*R), "ZZ/101");
67}
68TEST(RingZZmod101, ones)
69{
70 Z_mod* R = Z_mod::create(101);
71 EXPECT_TRUE(R->is_equal(R->one(), R->from_long(1)));
72 EXPECT_TRUE(R->is_equal(R->minus_one(), R->from_long(-1)));
73 EXPECT_TRUE(R->is_equal(R->zero(), R->from_long(0)));
74 EXPECT_TRUE(R->is_zero(R->from_long(0)));
75}
76TEST(RingZZmod101, negate)
77{
78 Z_mod* R = Z_mod::create(101);
80}
81TEST(RingZZmod101, add)
82{
83 Z_mod* R = Z_mod::create(101);
85}
86TEST(RingZZmod101, subtract)
87{
88 Z_mod* R = Z_mod::create(101);
90}
91TEST(RingZZmod101, multDivide)
92{
93 Z_mod* R = Z_mod::create(101);
95}
96TEST(RingZZmod101, axioms)
97{
98 Z_mod* R = Z_mod::create(101);
100}
101TEST(RingZZmod101, power)
102{
103 Z_mod* R = Z_mod::create(101);
105}
106TEST(RingZZmod101, syzygy)
107{
108 Z_mod* R = Z_mod::create(101);
110}
111
112TEST(RingZZmod2, create)
113{
114 Ring* R = Z_mod::create(2);
115 EXPECT_TRUE(R != nullptr);
116
117 EXPECT_TRUE(dynamic_cast<const Z_mod*>(R) != nullptr);
118 EXPECT_EQ(R->coefficient_type(), Ring::COEFF_BASIC);
119 EXPECT_FALSE(R->is_ZZ());
120 EXPECT_EQ(ringName(*R), "ZZ/2");
121}
122TEST(RingZZmod2, ones)
123{
124 Z_mod* R = Z_mod::create(2);
125 EXPECT_TRUE(R->is_equal(R->one(), R->from_long(1)));
126 EXPECT_TRUE(R->is_equal(R->minus_one(), R->from_long(-1)));
127 EXPECT_TRUE(R->is_equal(R->zero(), R->from_long(0)));
128 EXPECT_TRUE(R->is_zero(R->from_long(0)));
129}
130TEST(RingZZmod2, negate)
131{
132 Z_mod* R = Z_mod::create(2);
134}
135TEST(RingZZmod2, add)
136{
137 Z_mod* R = Z_mod::create(2);
139}
140TEST(RingZZmod2, subtract)
141{
142 Z_mod* R = Z_mod::create(2);
144}
145TEST(RingZZmod2, multDivide)
146{
147 Z_mod* R = Z_mod::create(2);
149}
150TEST(RingZZmod2, axioms)
151{
152 Z_mod* R = Z_mod::create(2);
154}
155TEST(RingZZmod2, power)
156{
157 Z_mod* R = Z_mod::create(2);
159}
160TEST(RingZZmod2, syzygy)
161{
162 Z_mod* R = Z_mod::create(2);
164}
165// Local Variables:
166// compile-command: "make -C $M2BUILDDIR/Macaulay2/e/unit-tests check "
167// indent-tabs-mode: nil
168// End:
std::istream & fromStream(std::istream &i, const T &R, typename T::ElementType &result)
const int ntrials
Definition ARingTest.hpp:42
std::string ringName(const T &R)
void testRingPower(const T *R, int ntrials)
Definition RingTest.hpp:201
void testRingDivide(const T *R, int ntrials)
Definition RingTest.hpp:140
void testRingSyzygy(const T *R, int ntrials)
Definition RingTest.hpp:273
void testRingAxioms(const T *R, int ntrials)
Definition RingTest.hpp:164
void testRingAdd(const T *R, int ntrials)
Definition RingTest.hpp:111
void testRingSubtract(const T *R, int ntrials)
Definition RingTest.hpp:126
void testRingNegate(const T *R, int ntrials)
Definition RingTest.hpp:98
Shared gtest fixture for the legacy Ring-based Ring*Test.cpp suite.
ring_elem getElement< RingZZ >(const RingZZ &R, int index)
TEST(RingZZmod32003, fromStream)
ring_elem getElement< Z_mod >(const Z_mod &R, int index)
Legacy Z_mod — a Ring-derived Z/p with log / exp tables.
virtual bool is_ZZ() const
Definition ring.hpp:171
ring_elem one() const
Definition ring.hpp:357
ring_elem zero() const
Definition ring.hpp:359
ring_elem minus_one() const
Definition ring.hpp:358
@ COEFF_BASIC
Definition ring.hpp:222
virtual CoefficientType coefficient_type() const
Definition ring.hpp:223
xxx xxx xxx
Definition ring.hpp:102
virtual ring_elem from_long(long n) const
Definition ZZp.cpp:132
virtual bool is_zero(const ring_elem f) const
Definition ZZp.cpp:188
virtual ring_elem from_int(mpz_srcptr n) const
Definition ZZp.cpp:140
virtual void elem_text_out(buffer &o, const ring_elem f, bool p_one=true, bool p_plus=false, bool p_parens=false) const
Definition ZZp.cpp:114
static Z_mod * create(int p)
Definition ZZp.cpp:64
virtual bool is_equal(const ring_elem f, const ring_elem g) const
Definition ZZp.cpp:189
Engine-side Z/p ring for small primes (p < 32767), using a discrete-log (Zech) representation.
Definition ZZp.hpp:63
char * str()
Definition buffer.hpp:72
RingZZ * globalZZ
Definition relem.cpp:13
void subtract(int &result, int a, int b)
std::ostringstream & ones(std::ostringstream &o, int len)
mpz_srcptr get_mpz() const
Definition ringelem.hpp:127