Debian Codegraph @

tests/mathtests.cpp

raw symbols SCIP
1 #include "../misc/math.h"
2 #include "../tests/testutils.h"
3
4 #include <cppunit/TestFixture.h>
5 #include <cppunit/extensions/HelperMacros.h>
6
7 using namespace std;
8 using namespace CppUtilities;
9 using namespace CppUtilities::Literals;
10
11 using namespace CPPUNIT_NS;
12
13 namespace CppUtilities {
14
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");
23
24 } // namespace CppUtilities
25
26 /*!
27 * \brief The MathTests class tests functions provided by misc/math.h.
28 */
29 class 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
38 public:
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
53 CPPUNIT_TEST_SUITE_REGISTRATION(MathTests);
54
55 void MathTests::testDigitsum()
56 {
57 CPPUNIT_ASSERT_EQUAL(0, digitsum(0));
58 CPPUNIT_ASSERT_EQUAL(7, digitsum(16));
59 CPPUNIT_ASSERT_EQUAL(1, digitsum(16, 16));
60 }
61
62 void MathTests::testFactorial()
63 {
64 CPPUNIT_ASSERT_EQUAL(6, factorial(3));
65 }
66
67 void MathTests::testPowerModulo()
68 {
69 CPPUNIT_ASSERT_EQUAL(25u, powerModulo(5u, 2u, 30u));
70 CPPUNIT_ASSERT_EQUAL(5u, powerModulo(5u, 2u, 20u));
71 }
72
73 void MathTests::testInverseModulo()
74 {
75 CPPUNIT_ASSERT_EQUAL(-12u, inverseModulo(2u, 25u));
76 CPPUNIT_ASSERT_EQUAL(-8u, inverseModulo(3u, 25u));
77 }
78
79 void MathTests::testOrderModulo()
80 {
81 CPPUNIT_ASSERT_EQUAL(20u, orderModulo(2u, 25u));
82 CPPUNIT_ASSERT_EQUAL(5u, orderModulo(6u, 25u));
83 CPPUNIT_ASSERT_EQUAL(0u, orderModulo(5u, 25u));
84 }