C++ Utilities 5.24.8
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
mathtests.cpp
Go to the documentation of this file.
1#include "../misc/math.h"
3
4#include <cppunit/TestFixture.h>
5#include <cppunit/extensions/HelperMacros.h>
6
7using namespace std;
8using namespace CppUtilities;
9using namespace CppUtilities::Literals;
10
11using namespace CPPUNIT_NS;
12
13namespace CppUtilities {
14
15static_assert(min(1, 2, 3) == 1, "min");
16static_assert(min(3, 2, 1) == 1, "min");
17static_assert(min(3, 4, 2, 1) == 1, "min");
18static_assert(min(3, 4, -2, 2, 1) == -2, "min");
19static_assert(max(1, 2, 3) == 3, "max");
20static_assert(max(3, 2, 1) == 3, "max");
21static_assert(max(3, 4, 2, 1) == 4, "max");
22static_assert(max(3, -2, 4, 2, 1) == 4, "max");
23
24} // namespace CppUtilities
25
29class MathTests : public TestFixture {
30 CPPUNIT_TEST_SUITE(MathTests);
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();
37
38public:
39 void setUp()
40 {
41 }
42 void tearDown()
43 {
44 }
45
46 void testDigitsum();
47 void testFactorial();
48 void testPowerModulo();
49 void testInverseModulo();
50 void testOrderModulo();
51};
52
54
61
66
68{
69 CPPUNIT_ASSERT_EQUAL(25u, powerModulo(5u, 2u, 30u));
70 CPPUNIT_ASSERT_EQUAL(5u, powerModulo(5u, 2u, 20u));
71}
72
78
The MathTests class tests functions provided by misc/math.h.
Definition mathtests.cpp:29
void testPowerModulo()
Definition mathtests.cpp:67
void testOrderModulo()
Definition mathtests.cpp:79
void tearDown()
Definition mathtests.cpp:42
void testDigitsum()
Definition mathtests.cpp:55
void setUp()
Definition mathtests.cpp:39
void testFactorial()
Definition mathtests.cpp:62
void testInverseModulo()
Definition mathtests.cpp:73
CPPUNIT_TEST_SUITE_REGISTRATION(MathTests)
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
Definition testutils.h:368
Contains all utilities provides by the c++utilities library.
constexpr IntegralType factorial(IntegralType number)
Returns the factorial of the given number.
Definition math.h:29
IntegralType stringToNumber(const StringType &string, BaseType base=10)
Converts the given string to an unsigned/signed number assuming string uses the specified base.
constexpr IntegralType inverseModulo(IntegralType number, IntegralType module)
Computes the inverse of number modulo module.
Definition math.h:61
constexpr IntegralType digitsum(IntegralType number, IntegralType base=10)
Returns the digitsum of the given number using the specified base.
Definition math.h:16
constexpr T max(T first, T second)
Returns the greatest of the given items.
Definition math.h:100
constexpr IntegralType powerModulo(const IntegralType base, const IntegralType exponent, const IntegralType module)
Computes base power exponent modulo module.
Definition math.h:42
constexpr T min(T first, T second)
Returns the smallest of the given items.
Definition math.h:88
constexpr IntegralType orderModulo(const IntegralType number, const IntegralType module)
Computes the order of number modulo module.
Definition math.h:79
STL namespace.