3#ifndef __ring_test_hpp__
4#define __ring_test_hpp__
49#include <gtest/gtest.h>
61 typename T::ElementType&
result);
75template <
typename RingType>
78template <
typename RingType>
101 for (
int i = 0; i <
ntrials; i++)
107 EXPECT_TRUE(R->is_zero(c));
114 for (
int i = 0; i <
ntrials; i++)
122 EXPECT_TRUE(R->is_equal(e, a));
129 for (
int i = 0; i <
ntrials; i++)
136 EXPECT_TRUE(R->is_equal(e, a));
142 auto zero = R->zero();
143 auto a = R->from_long(3);
144 EXPECT_ANY_THROW(R->divide(a,
zero));
147 for (
int i = 0; i <
ntrials; i++)
154 EXPECT_TRUE(R->is_zero(c));
158 EXPECT_TRUE(R->is_equal(d, a));
167 for (
int i = 0; i <
ntrials; i++)
178 EXPECT_TRUE(R->is_equal(d, e));
181 EXPECT_TRUE(R->is_equal(d, e));
186 d = R->add(a, R->add(b, c));
187 e = R->add(R->add(a, b), c);
188 EXPECT_TRUE(R->is_equal(d, e));
189 d = R->mult(a, R->mult(b, c));
190 e = R->mult(R->mult(a, b), c);
191 EXPECT_TRUE(R->is_equal(d, e));
195 d = R->mult(a, R->add(b, c));
196 e = R->add(R->mult(a, b), R->mult(a, c));
197 EXPECT_TRUE(R->is_equal(d, e));
206 for (
int i = 0; i <
ntrials; i++)
211 EXPECT_TRUE(R->is_equal(R->power(a, 1), a));
219 EXPECT_TRUE(R->is_equal(R->mult(b, c), d));
222 mpz_set_si(gmp1, e1);
224 EXPECT_TRUE(R->is_equal(b1, b));
232 for (
int i = 0; i <
ntrials; i++)
240 ring_elem d = R->gcd_extended(a, b, u, v);
242 EXPECT_TRUE(R->is_equal(c, d));
243 EXPECT_TRUE(R->is_equal(c, R->add(R->mult(a, u), R->mult(b, v))));
244 EXPECT_TRUE(R->is_equal(a, R->mult(R->divide(a, c), c)));
251 for (
int i = 0; i <
ntrials; i++)
257 ring_elem c = R->remainder(a, R->zero());
258 EXPECT_TRUE(R->is_equal(c,a));
264 r1 = R->remainderAndQuotient(a, b, q1);
266 EXPECT_TRUE(R->is_equal(r, r1));
267 EXPECT_TRUE(R->is_equal(q, q1));
269 EXPECT_TRUE(R->is_equal(a, a1));
276 for (
int i = 0; i <
ntrials; i++)
281 if (R->is_zero(b))
continue;
285 R->syzygy(R->zero(), b, u, v);
286 EXPECT_TRUE(R->is_equal(u, R->one()));
287 EXPECT_TRUE(R->is_equal(v, R->zero()));
289 R->syzygy(a, R->one(), u, v);
290 EXPECT_TRUE(R->is_equal(u, R->one()));
291 EXPECT_TRUE(R->is_equal(v, R->negate(a)));
293 R->syzygy(a, R->minus_one(), u, v);
294 EXPECT_TRUE(R->is_equal(u, R->one()));
295 EXPECT_TRUE(R->is_equal(v, a));
297 R->syzygy(a, b, u, v);
302 R->elem_text_out(o,a);
304 R->elem_text_out(o,b);
306 R->elem_text_out(o,u);
308 R->elem_text_out(o,v);
309 std::cout << o.
str() << std::endl;
311 EXPECT_TRUE(R->is_zero(
result));
void testRingPower(const T *R, int ntrials)
void testRingDivide(const T *R, int ntrials)
void testRingSyzygy(const T *R, int ntrials)
ring_elem getElement(const RingType &R, int index)
void testRingGCD(const T *R, int ntrials)
void testRingCoercions(const T *R, int ntrials)
void testRingAxioms(const T *R, int ntrials)
std::istream & fromStream(std::istream &i, const T &R, typename T::ElementType &result)
void testRingRemainder(const T *R, int ntrials)
void testRingAdd(const T *R, int ntrials)
std::string ringName(const T &R)
void testRingSubtract(const T *R, int ntrials)
void testRingNegate(const T *R, int ntrials)
Legacy RingZZ — a Ring-derived integer ring backed by GMP mpz_t.
RingElementGenerator(const RingType &R)
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
VALGRIND_MAKE_MEM_DEFINED & result(result)
int32_t rawRandomInt(int32_t max)
Engine-boundary C API for the engine's PRNG and rational / real / complex random draws.