C++ Utilities
5.0.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
|
Go to the documentation of this file. 1 #include "../misc/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(testDigitsum);
32 CPPUNIT_TEST(testFactorial);
33 CPPUNIT_TEST(testPowerModulo);
34 CPPUNIT_TEST(testInverseModulo);
35 CPPUNIT_TEST(testOrderModulo);
36 CPPUNIT_TEST_SUITE_END();
48 void testPowerModulo();
49 void testInverseModulo();
50 void testOrderModulo();
57 CPPUNIT_ASSERT_EQUAL(0,
digitsum(0));
58 CPPUNIT_ASSERT_EQUAL(7,
digitsum(16));
59 CPPUNIT_ASSERT_EQUAL(1,
digitsum(16, 16));
69 CPPUNIT_ASSERT_EQUAL(25u,
powerModulo(5u, 2u, 30u));
The MathTests class tests functions provided by misc/math.h.
constexpr IntegralType digitsum(IntegralType number, IntegralType base=10)
Returns the digitsum of the given number using the specified base.
constexpr IntegralType orderModulo(const IntegralType number, const IntegralType module)
Computes the order of number modulo module.
constexpr IntegralType factorial(IntegralType number)
Returns the factorial of the given number.
constexpr IntegralType inverseModulo(IntegralType number, IntegralType module)
Computes the inverse of number modulo module.
CPPUNIT_TEST_SUITE_REGISTRATION(MathTests)
constexpr T max(T first, T second)
Returns the greatest of the given items.
Contains all utilities provides by the c++utilities library.
constexpr T min(T first, T second)
Returns the smallest of the given items.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
constexpr IntegralType powerModulo(const IntegralType base, const IntegralType exponent, const IntegralType module)
Computes base power exponent modulo module.