From 840700d7afc8ad8a47c613862029f74e33a4bc29 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sun, 3 Sep 2017 20:13:27 +0200 Subject: [PATCH] Fix compiling math tests under 32-bit architectures Same problem as with size_t. The types must match exactly when using CPPUNIT_ASSERT_EQUAL and using 'l' or 'ul' suffix is not sufficient under 32-bit. --- tests/mathtests.cpp | 16 +++++++++------- tests/testutils.h | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/mathtests.cpp b/tests/mathtests.cpp index 53407e3..bf3df16 100644 --- a/tests/mathtests.cpp +++ b/tests/mathtests.cpp @@ -1,10 +1,12 @@ #include "../math/math.h" +#include "../tests/testutils.h" #include #include using namespace std; using namespace MathUtilities; +using namespace TestUtilities::Literals; using namespace CPPUNIT_NS; @@ -58,19 +60,19 @@ void MathTests::testFactorial() void MathTests::testPowerModulo() { - CPPUNIT_ASSERT_EQUAL(25ul, powerModulo(5, 2, 30)); - CPPUNIT_ASSERT_EQUAL(5ul, powerModulo(5, 2, 20)); + CPPUNIT_ASSERT_EQUAL(25_uint64, powerModulo(5, 2, 30)); + CPPUNIT_ASSERT_EQUAL(5_uint64, powerModulo(5, 2, 20)); } void MathTests::testInverseModulo() { - CPPUNIT_ASSERT_EQUAL(-12l, inverseModulo(2, 25)); - CPPUNIT_ASSERT_EQUAL(-8l, inverseModulo(3, 25)); + CPPUNIT_ASSERT_EQUAL(-12_int64, inverseModulo(2, 25)); + CPPUNIT_ASSERT_EQUAL(-8_int64, inverseModulo(3, 25)); } void MathTests::testOrderModulo() { - CPPUNIT_ASSERT_EQUAL(20ul, orderModulo(2, 25)); - CPPUNIT_ASSERT_EQUAL(5ul, orderModulo(6, 25)); - CPPUNIT_ASSERT_EQUAL(0ul, orderModulo(5, 25)); + CPPUNIT_ASSERT_EQUAL(20_uint64, orderModulo(2, 25)); + CPPUNIT_ASSERT_EQUAL(5_uint64, orderModulo(6, 25)); + CPPUNIT_ASSERT_EQUAL(0_uint64, orderModulo(5, 25)); } diff --git a/tests/testutils.h b/tests/testutils.h index e31a6cf..e739dd4 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -2,6 +2,7 @@ #define TESTUTILS_H #include "../application/argumentparser.h" +#include "../conversion/types.h" #include "../misc/traits.h" #include @@ -198,6 +199,24 @@ constexpr std::size_t operator"" _st(unsigned long long size) { return static_cast(size); } + +/*! + * \brief Literal for uint64 to ease asserting uint64 with CPPUNIT_ASSERT_EQUAL. + * \remarks Just using "ul"-suffix does not compile under 32-bit architecture! + */ +constexpr uint64 operator"" _uint64(unsigned long long size) +{ + return static_cast(size); +} + +/*! + * \brief Literal for int64 to ease asserting int64 with CPPUNIT_ASSERT_EQUAL. + * \remarks Just using "l"-suffix does not compile under 32-bit architecture! + */ +constexpr int64 operator"" _int64(unsigned long long size) +{ + return static_cast(size); +} } }