aboutsummaryrefslogtreecommitdiffstats
path: root/test/fp_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/fp_test.cpp')
-rw-r--r--test/fp_test.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/fp_test.cpp b/test/fp_test.cpp
index 26f97b1..7e78773 100644
--- a/test/fp_test.cpp
+++ b/test/fp_test.cpp
@@ -565,6 +565,43 @@ void setArrayMaskTest2(mcl::fp::Mode mode)
}
}
+void setArrayModTest()
+{
+ const mpz_class& p = Fp::getOp().mp;
+ const mpz_class tbl[] = {
+ 0,
+ 1,
+ p - 1,
+ p,
+ p + 1,
+ p * 2 - 1,
+ p * 2,
+ p * 2 + 1,
+ p * (p - 1) - 1,
+ p * (p - 1),
+ p * (p - 1) + 1,
+ p * p - 1,
+ p * p,
+ p * p + 1,
+ (mpz_class(1) << Fp::getOp().N * mcl::fp::UnitBitSize * 2) - 1,
+ };
+ const size_t unitByteSize = sizeof(mcl::fp::Unit);
+ for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) {
+ const mpz_class& x = tbl[i];
+ const mcl::fp::Unit *px = mcl::gmp::getUnit(x);
+ const size_t xn = mcl::gmp::getUnitSize(x);
+ const size_t xByteSize = xn * unitByteSize;
+ const size_t fpByteSize = unitByteSize * Fp::getOp().N;
+ Fp y;
+ bool b;
+ y.setArray(&b, px, xn, mcl::fp::Mod);
+ bool expected = xByteSize <= fpByteSize * 2;
+ CYBOZU_TEST_EQUAL(b, expected);
+ if (!b) continue;
+ CYBOZU_TEST_EQUAL(y.getMpz(), x % p);
+ }
+}
+
CYBOZU_TEST_AUTO(set64bit)
{
Fp::init("0x1000000000000000000f");
@@ -911,6 +948,7 @@ void sub(mcl::fp::Mode mode)
powGmp();
setArrayTest1();
setArrayMaskTest1();
+ setArrayModTest();
getUint64Test();
getInt64Test();
divBy2Test();