@@ -224,9 +224,29 @@ void test_square_variants(const M& mf, typename M::MontgomeryValue x,
224224 fusedSquareAdd<hc::LowuopsTag>(x,zc)) == answer);
225225}
226226
227+ template <typename M>
228+ void test_remainder (const M& mf)
229+ {
230+ using T = typename M::IntegerType;
231+ namespace hc = ::hurchalla;
232+
233+ T max = hc::ut_numeric_limits<T>::max ();
234+ T mid = static_cast <T>(max/2 );
235+ T modulus = mf.getModulus ();
236+
237+ EXPECT_TRUE (mf.remainder (0 ) == (0 % modulus));
238+ EXPECT_TRUE (mf.remainder (1 ) == (1 % modulus));
239+ EXPECT_TRUE (mf.remainder (2 ) == (2 % modulus));
240+ EXPECT_TRUE (mf.remainder (static_cast <T>(max-0 )) == ((max-0 ) % modulus));
241+ EXPECT_TRUE (mf.remainder (static_cast <T>(max-1 )) == ((max-1 ) % modulus));
242+ EXPECT_TRUE (mf.remainder (static_cast <T>(max-2 )) == ((max-2 ) % modulus));
243+ EXPECT_TRUE (mf.remainder (static_cast <T>(mid-1 )) == ((mid-1 ) % modulus));
244+ EXPECT_TRUE (mf.remainder (static_cast <T>(mid-0 )) == ((mid-0 ) % modulus));
245+ EXPECT_TRUE (mf.remainder (static_cast <T>(mid+1 )) == ((mid+1 ) % modulus));
246+ }
227247
228248template <typename M>
229- void test_mf_general_checks (M& mf, typename M::IntegerType a,
249+ void test_mf_general_checks (const M& mf, typename M::IntegerType a,
230250 typename M::IntegerType b, typename M::IntegerType c)
231251{
232252 namespace hc = ::hurchalla;
@@ -590,6 +610,18 @@ void test_MontgomeryForm()
590610 M mf (modulus);
591611 EXPECT_TRUE (mf.gcd_with_modulus (mf.convertIn (12 ), GcdFunctor ()) == 3 );
592612 }
613+
614+ // test remainder()
615+ {
616+ T max = M::max_modulus ();
617+ T mid = static_cast <T>(max/2 );
618+ mid = (mid % 2 == 0 ) ? static_cast <T>(mid + 1 ) : mid;
619+ test_remainder (M (3 )); // smallest possible modulus
620+ test_remainder (M (max)); // largest possible modulus
621+ if (121 <= max)
622+ test_remainder (M (121 ));
623+ test_remainder (M (mid));
624+ }
593625}
594626
595627
0 commit comments