Macaulay2 Engine
Loading...
Searching...
No Matches
ARingQQGmpTest.cpp
Go to the documentation of this file.
1// Copyright 2012-2013 Michael E. Stillman
2
29
30#include <cstdio>
31#include <string>
32#include <iostream>
33#include <sstream>
34#include <memory>
35#include <gtest/gtest.h>
36#include <mpfr.h>
37
38#include "aring-qq-gmp.hpp"
39
40#include "ARingTest.hpp"
41
43
44template <>
46 int index,
48{
49 if (index < 50)
50 R.set_from_long(result, index - 25);
51 else
52 {
53 R.random(result);
54 }
55}
56
57TEST(ARingQQGMP, create)
58{
60
62 buffer o;
63
65 R.init(a);
66 gen.nextElement(a);
67
68 EXPECT_EQ(ringName(R), "QQGMP");
69 EXPECT_EQ(R.cardinality(), static_cast<size_t>(-1));
70 EXPECT_EQ(R.characteristic(), 0);
71 R.clear(a);
72}
73
74TEST(ARingQQGMP, display)
75{
77
79 buffer o;
80
82 R.init(a);
83 R.init(b);
84 gen.nextElement(a);
85 gen.nextElement(b);
86 R.divide(a, a, b);
87 R.elem_text_out(o, a, true, false, false);
88 EXPECT_TRUE(strcmp(o.str(), "24/23") == 0);
89 std::cout << "a = ." << o.str() << "." << std::endl;
90
91 EXPECT_EQ(ringName(R), "QQGMP");
92 EXPECT_EQ(R.cardinality(), static_cast<size_t>(-1));
93 EXPECT_EQ(R.characteristic(), 0);
94 R.clear(a);
95 R.clear(b);
96}
97
98TEST(ARingQQGMP, arithmetic)
99{
101
102 testCoercions(R);
104 testAdd(R, ntrials);
109 // testPower(R, ntrials); // this test can't work, as it expects a finite
110 // field
112}
113
114// Local Variables:
115// compile-command: "make -C $M2BUILDDIR/Macaulay2/e/unit-tests check "
116// indent-tabs-mode: nil
117// End:
TEST(ARingQQGMP, create)
gmp_ZZ getRandomInteger()
void getElement< M2::ARingQQGMP >(const M2::ARingQQGMP &R, int index, M2::ARingQQGMP::ElementType &result)
void testAdd(const T &R, int ntrials)
void testNegate(const T &R, int ntrials)
void testReciprocal(const T &R, int ntrials)
void testCoercions(const T &R)
void testAxioms(const T &R, int ntrials)
const int ntrials
Definition ARingTest.hpp:42
void testSubtract(const T &R, int ntrials)
void testMultiply(const T &R, int ntrials)
std::string ringName(const T &R)
Shared gtest harness for the ARing*Test.cpp suite.
M2::ARingQQGMP — arbitrary-precision rationals backed straight by GMP mpq_t.
void nextElement(typename RingType::ElementType &result)
Definition ARingTest.hpp:56
size_t cardinality() const
size_t characteristic() const
static void clear(ElementType &result)
void random(ElementType &result) const
void set_from_long(ElementType &result, long a) const
void divide(ElementType &result, const ElementType &a, const ElementType &b) const
test doc
void elem_text_out(buffer &o, const ElementType &a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
__mpq_struct ElementType
void init(ElementType &result) const
wrapper for the gmp mpq_t integer representation
char * str()
Definition buffer.hpp:72
void testDivide()
VALGRIND_MAKE_MEM_DEFINED & result(result)
mpz_srcptr gmp_ZZ
Definition m2-types.h:141