1#ifndef __ring_test_hpp__
2#define __ring_test_hpp__
46template <
typename RingType>
49 typename RingType::ElementType&
result);
51template <
typename RingType>
69 typename T::ElementType&
result);
74 typename T::ElementType a, b, c, d;
80 R.set_from_long(a, 27);
81 R.set_from_long(b,
static_cast<int>(R.characteristic()) - 11);
82 R.set_from_long(c, 16);
87 R.elem_text_out(o, a,
true);
89 R.elem_text_out(o, b,
true);
91 R.elem_text_out(o, c,
true);
93 R.elem_text_out(o, d,
true);
94 std::cout << o.
str() << std::endl;
96 EXPECT_TRUE(R.is_equal(c, d));
108 typename T::ElementType a, b;
111 for (
int i = 0; i <
ntrials; i++)
116 EXPECT_TRUE(R.is_zero(b));
134 typename T::ElementType a, b, c;
145 mpz_set_str(
base,
"2131236127486324783264782364", 10);
146 R.set_from_mpz(c,
base);
147 for (
int i = -1000; i < 1000; i++)
151 R.set_from_mpz(a, m);
152 R.set_from_long(b, i);
154 EXPECT_TRUE(R.is_equal(a, b));
158 for (
int i = 1; i < 300; i++)
160 mpq_set_si(n1, 43999, i);
161 mpq_canonicalize(n1);
165 if (R.characteristic() == 0 or (i % R.characteristic()) == 0)
continue;
166 bool ok = R.set_from_mpq(a, n1);
168 R.set_from_long(b, 43999);
169 R.set_from_long(c, i);
173 EXPECT_TRUE(R.is_equal(a, c));
189 typename T::ElementType a, b, c, d, e, f;
196 for (
int i = 0; i <
ntrials; i++)
207 EXPECT_TRUE(R.is_equal(d, e));
210 EXPECT_TRUE(R.is_equal(d, e));
219 EXPECT_TRUE(R.is_equal(d, e));
224 EXPECT_TRUE(R.is_equal(d, e));
233 EXPECT_TRUE(R.is_equal(d, e));
247 typename T::ElementType a, b, c, d;
252 for (
int i = 0; i <
ntrials; i++)
262 R.elem_text_out(o, a ,
true,
false,
false);
264 R.elem_text_out(o, b ,
true,
false,
false);
266 R.elem_text_out(o, c ,
true,
false,
false);
268 R.elem_text_out(o, d ,
true,
false,
false);
275 R.elem_text_out(o, d ,
true,
false,
false);
276 std::cout << o.
str() << std::endl;
278 EXPECT_TRUE(R.is_equal(d, a));
290 typename T::ElementType a, b, c, d;
295 for (
int i = 0; i <
ntrials; i++)
303 EXPECT_TRUE(R.is_equal(d, a));
315 typename T::ElementType a, b, c, d,
zero;
321 R.set_from_long(
zero, 0);
322 for (
int i = 0; i <
ntrials; i++)
329 EXPECT_TRUE(R.is_equal(c,
zero));
343 typename T::ElementType a, b, c, d,
zero;
349 R.set_from_long(
zero, 0);
350 for (
int i = 0; i <
ntrials; i++)
358 if (R.is_zero(a))
continue;
361 EXPECT_TRUE(R.is_equal(b, d));
374 typename T::ElementType a, b, c, one;
379 R.set_from_long(one, 1);
380 for (
int i = 0; i <
ntrials; i++)
385 if (R.is_zero(a))
continue;
388 EXPECT_TRUE(R.is_equal(c, one));
411 typename T::ElementType a, b, c, d, one;
412 int q =
static_cast<int>(R.cardinality());
418 R.set_from_long(one, 1);
419 for (
int i = 0; i <
ntrials; i++)
425 EXPECT_TRUE(R.is_equal(c, a));
427 if (R.is_zero(a))
continue;
429 R.power(c, a, q - 1);
430 EXPECT_TRUE(R.is_equal(c, one));
434 EXPECT_TRUE(R.is_equal(c, one));
439 EXPECT_TRUE(R.is_equal(d, a));
473 std::cout <<
"ring ID: " << rid << std::endl;
void testAdd(const T &R, int ntrials)
void testNegate(const T &R, int ntrials)
void testReciprocal(const T &R, int ntrials)
void testPower(const T &R, int ntrials)
void testARingInterface(const T &R)
void testCoercions(const T &R)
std::istream & fromStream(std::istream &i, const T &R, typename T::ElementType &result)
void testAxioms(const T &R, int ntrials)
void testFiniteField(const T &R, int ntrials)
void getElement(const RingType &R, int index, typename RingType::ElementType &result)
void testSubtract(const T &R, int ntrials)
void testSomeMore(const T &R)
void testMultiply(const T &R, int ntrials)
std::string ringName(const T &R)
void nextElement(typename RingType::ElementType &result)
ARingElementGenerator(const RingType &R)
static CanonicalForm base
VALGRIND_MAKE_MEM_DEFINED & result(result)
Engine-boundary C API for the engine's PRNG and rational / real / complex random draws.