36#include <gtest/gtest.h>
54 mpz_set_str(
maxH,
"100000000000", 10);
76 long top1 = (R.characteristic() > 10000 ? 10000 : R.characteristic());
77 long bottom2 = (R.characteristic() > 10000 ? R.characteristic() - 10000 : 0);
78 for (
long i = 0; i < top1; i++)
80 typename RT::ElementType a;
82 R.set_from_long(a, i);
83 long b = R.coerceToLongInteger(a);
84 if (b < 0) b += R.characteristic();
87 for (
long i = bottom2; i < R.characteristic(); i++)
89 typename RT::ElementType a;
91 R.set_from_long(a, i);
92 long b = R.coerceToLongInteger(a);
93 if (b < 0) b += R.characteristic();
100 EXPECT_FALSE(R ==
nullptr);
102 o <<
"Ring being tested: ";
104 fprintf(stdout,
"%s\n", o.
str());
125 std::cout <<
"generator is " << o.
str() << std::endl;
159 std::istringstream i(
"+1234 +345 -235*a");
165 while (isspace(i.peek())) i.get();
167 if (!isdigit(i.peek()) && i.peek() !=
'+' && i.peek() !=
'-')
break;
173 std::cout << o.
str() <<
" peek: " << i.peek() << std::endl;
196 EXPECT_EQ(
ringName(R),
"ZZpFPACK(101,1)");
199 std::cout <<
"max modulus for ffpack zzp: "
210TEST(ARingZZpFFPACK, arithmetic101)
219TEST(ARingZZpFFPACK, arithmetic2)
227TEST(ARingZZpFFPACK, arithmetic3)
235TEST(ARingZZpFFPACK, arithmetic66000007)
254TEST(ARingZZpFFPACK, arithmetic67108859)
271TEST(ARingZZpFFPACK, arithmetic33500479)
290 std::string a =
"-42378489327498312749c3";
291 std::istringstream i(a);
326 EXPECT_EQ(
ringName(R),
"AZZFlint/101");
337TEST(ARingZZpFlint, arithmetic101)
344TEST(ARingZZpFlint, arithmetic2)
351TEST(ARingZZpFlint, arithmetic3)
358TEST(ARingZZpFlint, arithmetic66000007)
375TEST(ARingZZpFlint, arithmetic67108859)
392TEST(ARingZZpFlint, arithmetic33500479)
409TEST(ARingZZpFlint, arithmetic9223372036854775783)
412 if (
sizeof(
unsigned long) <= 4)
413 std::cout <<
"seems to be a 32bit machine: skipping the test" << std::endl;
437TEST(ARingZZpFlint, arithmetic18446744073709551557)
440 if (
sizeof(
unsigned long) <= 4)
441 std::cout <<
"seems to be a 32bit machine: skipping the test" << 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 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 testSubtract(const T &R, int ntrials)
void testSomeMore(const T &R)
void testMultiply(const T &R, int ntrials)
std::string ringName(const T &R)
Shared gtest harness for the ARing*Test.cpp suite.
void testCoerceToLongInteger(const RT &R)
void getElement< M2::ARingZZpFlint >(const M2::ARingZZpFlint &R, int index, M2::ARingZZpFlint::ElementType &result)
void getElement< M2::ARingZZp >(const M2::ARingZZp &R, int index, M2::ARingZZp::ElementType &result)
static bool maxH_initialized
gmp_ZZ getRandomInteger()
void getElement< M2::ARingZZpFFPACK >(const M2::ARingZZpFFPACK &R, int index, M2::ARingZZpFFPACK::ElementType &result)
Legacy Z_mod — a Ring-derived Z/p with log / exp tables.
M2::ARingZZpFFPACK — Z/p via FFLAS-FFPACK's Givaro::Modular<double> field.
M2::ARingZZpFlint — Z/p via FLINT's nmod_t precomputed-reciprocal reduction.
M2::ARingZZp — portable Z/p for small primes via log / exp tables.
void nextElement(typename RingType::ElementType &result)
void set_from_long(elem &result, long a) const
size_t characteristic() const
void init(elem &result) const
static void clear(elem &result)
void elem_text_out(buffer &o, ElementType a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
void set_from_mpz(elem &result, mpz_srcptr a) const
size_t cardinality() const
bool is_equal(ElementType f, ElementType g) const
void set_var(elem &result, int v) const
void set_from_mpz(ElementType &result, mpz_srcptr a) const
void set_from_long(ElementType &result, long a) const
static void clear(ElementType &result)
void init(ElementType &result) const
static double getMaxModulus()
FieldType::Element ElementType
wrapper for the FFPACK::ModularBalanced<double> field implementation
static void clear(ElementType &result)
void set_from_mpz(ElementType &result, mpz_srcptr a) const
void set_from_long(ElementType &result, long a) const
void init(ElementType &result) const
aring-style adapter for Z/p with p a word-size prime, backed by FLINT's nmod_* routines.
aring-style adapter for Z/p using a discrete-log (Zech) representation: every non-zero residue is its...
void read(std::istream &i, ElementType &result)
virtual void text_out(buffer &o) const
static Z_mod * create(int p)
Engine-side Z/p ring for small primes (p < 32767), using a discrete-log (Zech) representation.
VALGRIND_MAKE_MEM_DEFINED & result(result)
gmp_ZZ rawRandomInteger(gmp_ZZ maxN)
M2::Reader<RingType> — parse a single ring element from a std::istream.