Macaulay2 Engine
Loading...
Searching...
No Matches

◆ TEST() [7/9]

TEST ( RingRRR ,
power  )

Definition at line 159 of file RingRRRTest.cpp.

160{
161 RingRRR *R = RingRRR::create(std::make_unique<M2::ARingRRR>(100));
162
163 mpz_t gmp1;
164 mpz_init(gmp1);
166 for (int i = 0; i < ntrials; i++)
167 {
168 ring_elem a = gen.nextElement();
169 // TODO: what should the answer here be?
170 // EXPECT_TRUE(R->is_equal(R->power(a, 0), R->one())); // 0^0 == 1 too?
171 EXPECT_TRUE(R->is_equal(R->power(a, 1), a));
172
173 int e1 = rawRandomInt(10) + 1;
174 int e2 = rawRandomInt(10) + 1;
175 // std::cout << "(" << e1 << "," << e2 << ")" << std::endl;
176 ring_elem b = R->power(a, e1);
177 ring_elem c = R->power(a, e2);
178 ring_elem d = R->power(a, e1 + e2);
179 EXPECT_TRUE(almostEqual(R, 96, R->mult(b, c), d));
180
181 // Make sure that powers via mpz work (at least for small exponents)
182 mpz_set_si(gmp1, e1);
183 ring_elem b1 = R->power(a, gmp1);
184 EXPECT_TRUE(R->is_equal(b1, b));
185 }
186 mpz_clear(gmp1);
187}
const int ntrials
Definition ARingTest.hpp:42
M2::ConcreteRing< M2::ARingRRR > RingRRR
bool almostEqual(const RingRRR *R, int nbits, ring_elem a, ring_elem b)
virtual ring_elem mult(const ring_elem f, const ring_elem g) const
static ConcreteRing< M2::ARingRRR > * create(std::unique_ptr< M2::ARingRRR > R)
virtual ring_elem power(const ring_elem f, mpz_srcptr n) const
Exponentiation. This is the default function, if a class doesn't define this.
virtual bool is_equal(const ring_elem f, const ring_elem g) const
int32_t rawRandomInt(int32_t max)
Definition random.cpp:44

References almostEqual(), M2::ConcreteRing< M2::ARingRRR >::create(), M2::ConcreteRing< RingType >::is_equal(), M2::ConcreteRing< RingType >::mult(), RingElementGenerator< RingType >::nextElement(), ntrials, M2::ConcreteRing< RingType >::power(), and rawRandomInt().