1 #include "../math/math.h" 2 #include "../tests/testutils.h" 4 #include <cppunit/TestFixture.h> 5 #include <cppunit/extensions/HelperMacros.h> 11 using namespace CPPUNIT_NS;
15 static_assert(
min(1, 2, 3) == 1,
"min");
16 static_assert(
min(3, 2, 1) == 1,
"min");
17 static_assert(
min(3, 4, 2, 1) == 1,
"min");
18 static_assert(
min(3, 4, -2, 2, 1) == -2,
"min");
19 static_assert(
max(1, 2, 3) == 3,
"max");
20 static_assert(
max(3, 2, 1) == 3,
"max");
21 static_assert(
max(3, 4, 2, 1) == 4,
"max");
22 static_assert(
max(3, -2, 4, 2, 1) == 4,
"max");
31 CPPUNIT_TEST(testRandom);
32 CPPUNIT_TEST(testDigitsum);
33 CPPUNIT_TEST(testFactorial);
34 CPPUNIT_TEST(testPowerModulo);
35 CPPUNIT_TEST(testInverseModulo);
36 CPPUNIT_TEST(testOrderModulo);
37 CPPUNIT_TEST_SUITE_END();
50 void testPowerModulo();
51 void testInverseModulo();
52 void testOrderModulo();
59 #ifndef PLATFORM_WINDOWS 60 CPPUNIT_ASSERT_EQUAL(6,
random(5, 7));
66 CPPUNIT_ASSERT_EQUAL(0,
digitsum(0));
67 CPPUNIT_ASSERT_EQUAL(7,
digitsum(16));
68 CPPUNIT_ASSERT_EQUAL(1,
digitsum(16, 16));
78 CPPUNIT_ASSERT_EQUAL(25_uint64,
powerModulo(5, 2, 30));
79 CPPUNIT_ASSERT_EQUAL(5_uint64,
powerModulo(5, 2, 20));
90 CPPUNIT_ASSERT_EQUAL(20_uint64,
orderModulo(2, 25));
CPP_UTILITIES_EXPORT int factorial(int number)
Returns the factorial of the given number.
CPP_UTILITIES_EXPORT uint64 orderModulo(uint64 number, uint64 module)
Computes the order of number modulo module.
CPP_UTILITIES_EXPORT int64 inverseModulo(int64 number, int64 module)
Computes the inverse of number modulo module.
Contains various mathematical functions.
The MathTests class tests functions of the MathUtilities namespace.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
CPP_UTILITIES_EXPORT int random(int lowerbounds, int upperbounds)
Returns a pseudo random number between lowerbounds and upperbounds.
constexpr T max(T first, T second)
Returns the greatest of the given items.
CPPUNIT_TEST_SUITE_REGISTRATION(MathTests)
CPP_UTILITIES_EXPORT int digitsum(int number, int base=10)
Returns the digitsum of the given number using the specified base.
constexpr T min(T first, T second)
Returns the smallest of the given items.
CPP_UTILITIES_EXPORT uint64 powerModulo(uint64 base, uint64 expontent, uint64 module)
Computes base power exponent modulo module.