From a7da90a79e095e5589ff6184f3d06b69573f3c81 Mon Sep 17 00:00:00 2001 From: Nick Thompson Date: Mon, 29 Oct 2018 13:10:02 -0600 Subject: [PATCH] Make changes suggested by reviewer. --- include/boost/integer/extended_euclidean.hpp | 6 ++---- include/boost/integer/mod_inverse.hpp | 2 +- test/extended_euclidean_test.cpp | 8 ++++---- test/mod_inverse_test.cpp | 10 +++++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/boost/integer/extended_euclidean.hpp b/include/boost/integer/extended_euclidean.hpp index 6bb63b5..83d9a71 100644 --- a/include/boost/integer/extended_euclidean.hpp +++ b/include/boost/integer/extended_euclidean.hpp @@ -22,15 +22,13 @@ struct euclidean_result_t { Z y; }; -using std::numeric_limits; - template -euclidean_result_t::is_signed, Z>::type> +euclidean_result_t::is_signed, Z>::type> extended_euclidean(Z m, Z n) { if (m < 1 || n < 1) { - BOOST_THROW_EXCEPTION(std::domain_error("Arguments must be strictly positive.\n")); + BOOST_THROW_EXCEPTION(std::domain_error("Arguments must be strictly positive.")); } bool swapped = false; diff --git a/include/boost/integer/mod_inverse.hpp b/include/boost/integer/mod_inverse.hpp index 8836524..2f07227 100644 --- a/include/boost/integer/mod_inverse.hpp +++ b/include/boost/integer/mod_inverse.hpp @@ -25,7 +25,7 @@ boost::optional mod_inverse(Z a, Z modulus) { if (modulus < 2) { - BOOST_THROW_EXCEPTION(std::domain_error("Modulus must be > 1.\n")); + BOOST_THROW_EXCEPTION(std::domain_error("Modulus must be > 1.")); } // make sure a < modulus: a = a % modulus; diff --git a/test/extended_euclidean_test.cpp b/test/extended_euclidean_test.cpp index ae7b866..91b2533 100644 --- a/test/extended_euclidean_test.cpp +++ b/test/extended_euclidean_test.cpp @@ -11,7 +11,7 @@ #endif #ifndef DISABLE_MP_TESTS -#include +#include #include #include #include @@ -35,8 +35,8 @@ void test_extended_euclidean() int256_t gcdmn = gcd(m, n); int256_t x = u.x; int256_t y = u.y; - assert(u.gcd == gcdmn); - assert(m*x + n*y == gcdmn); + BOOST_TEST_EQ(u.gcd, gcdmn); + BOOST_TEST_EQ(m*x + n*y, gcdmn); } } } @@ -50,7 +50,7 @@ int main() test_extended_euclidean(); test_extended_euclidean(); - return 0; + return boost::report_errors();; } #else int main() diff --git a/test/mod_inverse_test.cpp b/test/mod_inverse_test.cpp index bc29804..7d75a54 100644 --- a/test/mod_inverse_test.cpp +++ b/test/mod_inverse_test.cpp @@ -11,7 +11,7 @@ #endif #ifndef DISABLE_MP_TESTS -#include +#include #include #include #include @@ -39,17 +39,17 @@ void test_mod_inverse() // Should fail if gcd(a, mod) != 1: if (gcdam > 1) { - assert(!inv_a); + BOOST_TEST(!inv_a); } else { - assert(inv_a.value() > 0); + BOOST_TEST(inv_a.value() > 0); // Cast to a bigger type so the multiplication won't overflow. int256_t a_inv = inv_a.value(); int256_t big_a = a; int256_t m = modulus; int256_t outta_be_one = (a_inv*big_a) % m; - assert(outta_be_one == 1); + BOOST_TEST_EQ(outta_be_one, 1); } } } @@ -62,7 +62,7 @@ int main() test_mod_inverse(); test_mod_inverse(); - return 0; + return boost::report_errors(); } #else int main()