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.
This commit is contained in:
Martchus 2017-09-03 20:13:27 +02:00
parent 04050069c3
commit 840700d7af
2 changed files with 28 additions and 7 deletions

View File

@ -1,10 +1,12 @@
#include "../math/math.h"
#include "../tests/testutils.h"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
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));
}

View File

@ -2,6 +2,7 @@
#define TESTUTILS_H
#include "../application/argumentparser.h"
#include "../conversion/types.h"
#include "../misc/traits.h"
#include <ostream>
@ -198,6 +199,24 @@ constexpr std::size_t operator"" _st(unsigned long long size)
{
return static_cast<std::size_t>(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<uint64>(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<int64>(size);
}
}
}