Line data Source code
1 0 : //#define ENABLE_UTILITY_TEST
2 :
3 : #include "gtest/gtest.h"
4 : #include "../../utility/header/commonTypes.h"
5 : #include "../../utility/header/mathUtility.h"
6 :
7 : #include <fstream>
8 : #include <sys/stat.h>
9 : #include <cstdio>
10 : #ifdef _WIN32
11 : #include <direct.h>
12 : #elif __linux__
13 : #include <unistd.h>
14 : #endif
15 :
16 :
17 0 : using namespace Coruh::Utility;
18 :
19 0 : class MathUtilityTest : public ::testing::Test {
20 : public:
21 0 : int a;
22 : protected:
23 0 : void SetUp() override {
24 : //Setup test data
25 : }
26 :
27 0 : void TearDown() override {
28 : // Clean up test data
29 : }
30 : };
31 :
32 :
33 :
34 0 : TEST_F(MathUtilityTest, CalculateMean) {
35 : // Test data
36 : const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
37 : const int datalen = sizeof(data) / sizeof(data[0]);
38 : // Perform the calculation
39 : double result = MathUtility::calculateMean(data, datalen);
40 : // Check the result
41 : EXPECT_DOUBLE_EQ(result, 3.0);
42 : }
43 :
44 :
45 0 : TEST_F(MathUtilityTest, CalculateMedianOdd) {
46 : // Test data
47 : const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
48 : const int datalen = sizeof(data) / sizeof(data[0]);
49 : // Perform the calculation
50 : double result = MathUtility::calculateMedian(data, datalen);
51 : // Check the result
52 : EXPECT_DOUBLE_EQ(result, 3.0);
53 : }
54 :
55 0 : TEST_F(MathUtilityTest, CalculateMedianEven) {
56 : // Test data
57 : const double data[] = { 1.0, 2.0, 3.0, 4.0 };
58 : const int datalen = sizeof(data) / sizeof(data[0]);
59 : // Perform the calculation
60 : double result = MathUtility::calculateMedian(data, datalen);
61 : // Check the result
62 : EXPECT_DOUBLE_EQ(result, 2.5);
63 : }
64 :
65 0 : TEST_F(MathUtilityTest, CompareDoubleLessTest) {
66 : // Test data
67 : const double val1 = 2.0;
68 : const double val2 = 4.0;
69 : // Perform the comparison
70 : int result = MathUtility::compareDouble(&val1, &val2);
71 : // Check the result
72 : EXPECT_EQ(result, -1);
73 : }
74 :
75 0 : TEST_F(MathUtilityTest, CompareDoubleGreaterTest) {
76 : // Test data
77 : const double val1 = 4.0;
78 : const double val2 = 2.0;
79 : // Perform the comparison
80 : int result = MathUtility::compareDouble(&val1, &val2);
81 : // Check the result
82 : EXPECT_EQ(result, 1);
83 : }
84 :
85 0 : TEST_F(MathUtilityTest, CompareDoubleEqualTest) {
86 : // Test data
87 : const double val1 = 3.0;
88 : const double val2 = 3.0;
89 : // Perform the comparison
90 : int result = MathUtility::compareDouble(&val1, &val2);
91 : // Check the result
92 : EXPECT_EQ(result, 0);
93 : }
94 :
95 0 : TEST_F(MathUtilityTest, CalculateMinMaxTest_1) {
96 : // Test data
97 : const double data[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
98 : const int datalen = sizeof(data) / sizeof(data[0]);
99 : double min, max;
100 : // Perform the calculation
101 : MathUtility::calculateMinMax(data, datalen, &min, &max);
102 : // Check the result
103 : EXPECT_DOUBLE_EQ(min, 1.0);
104 : EXPECT_DOUBLE_EQ(max, 5.0);
105 : }
106 :
107 0 : TEST_F(MathUtilityTest, CalculateMinMaxTest_2) {
108 : double data[] = { 3.14, 1.0, -2.5, 7.2, -5.0 };
109 : double min, max;
110 : MathUtility::calculateMinMax(data, sizeof(data) / sizeof(data[0]), &min, &max);
111 : EXPECT_DOUBLE_EQ(min, -5.0);
112 : EXPECT_DOUBLE_EQ(max, 7.2);
113 : }
114 :
115 :
116 :
117 :
118 :
119 : /**
120 : * @brief The main function of the test program.
121 : *
122 : * @param argc The number of command-line arguments.
123 : * @param argv An array of command-line argument strings.
124 : * @return int The exit status of the program.
125 : */
126 1 : int main(int argc, char **argv) {
127 : #ifdef ENABLE_UTILITY_TEST
128 : ::testing::InitGoogleTest(&argc, argv);
129 : return RUN_ALL_TESTS();
130 : #else
131 : return 0;
132 : #endif
133 : }
|