2017-08-02 13:29:22 +02:00
|
|
|
#include "../math/math.h"
|
2017-09-03 20:13:27 +02:00
|
|
|
#include "../tests/testutils.h"
|
2017-08-02 13:29:22 +02:00
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace MathUtilities;
|
2017-09-03 20:13:27 +02:00
|
|
|
using namespace TestUtilities::Literals;
|
2017-08-02 13:29:22 +02:00
|
|
|
|
|
|
|
using namespace CPPUNIT_NS;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The MathTests class tests functions of the MathUtilities namespace.
|
|
|
|
*/
|
|
|
|
class MathTests : public TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(MathTests);
|
|
|
|
CPPUNIT_TEST(testRandom);
|
|
|
|
CPPUNIT_TEST(testDigitsum);
|
|
|
|
CPPUNIT_TEST(testFactorial);
|
|
|
|
CPPUNIT_TEST(testPowerModulo);
|
|
|
|
CPPUNIT_TEST(testInverseModulo);
|
|
|
|
CPPUNIT_TEST(testOrderModulo);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void testRandom();
|
|
|
|
void testDigitsum();
|
|
|
|
void testFactorial();
|
|
|
|
void testPowerModulo();
|
|
|
|
void testInverseModulo();
|
|
|
|
void testOrderModulo();
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(MathTests);
|
|
|
|
|
|
|
|
void MathTests::testRandom()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(6, random(5, 7));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathTests::testDigitsum()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, digitsum(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(7, digitsum(16));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, digitsum(16, 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathTests::testFactorial()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(6, factorial(3));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathTests::testPowerModulo()
|
|
|
|
{
|
2017-09-03 20:13:27 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(25_uint64, powerModulo(5, 2, 30));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(5_uint64, powerModulo(5, 2, 20));
|
2017-08-02 13:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MathTests::testInverseModulo()
|
|
|
|
{
|
2017-09-03 20:13:27 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(-12_int64, inverseModulo(2, 25));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-8_int64, inverseModulo(3, 25));
|
2017-08-02 13:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MathTests::testOrderModulo()
|
|
|
|
{
|
2017-09-03 20:13:27 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(20_uint64, orderModulo(2, 25));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(5_uint64, orderModulo(6, 25));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0_uint64, orderModulo(5, 25));
|
2017-08-02 13:29:22 +02:00
|
|
|
}
|