|
@@ -1,21 +1,93 @@
|
|
1
|
+/*!
|
|
2
|
+ * \file test/MatMath.cpp
|
|
3
|
+ * \brief Mat Math Unit Test
|
|
4
|
+ *
|
|
5
|
+ * \todo Also test the geometric methods (intersection, distance, midpoint)
|
|
6
|
+ *
|
|
7
|
+ * \author xythobuz
|
|
8
|
+ */
|
1
|
9
|
#include <stdio.h>
|
2
|
10
|
#include <math.h>
|
3
|
|
-
|
4
|
11
|
#include <MatMath.h>
|
|
12
|
+#include "greatest.h"
|
|
13
|
+
|
|
14
|
+vec_t testDegrees[] = { 0.0, 30.0, 45.0, 60.0, 90.0, 360.0, -100.0 };
|
|
15
|
+vec_t testRads[] = { 0.0, 0.5236, 0.7854, 1.0472, 1.5708, 6.2832, -1.7453 };
|
|
16
|
+vec_t testBounds[][2] = {
|
|
17
|
+ { 0.0, 1.0 },
|
|
18
|
+ { -5.0, 5.0 },
|
|
19
|
+ { 1.0, 1.0 },
|
|
20
|
+};
|
|
21
|
+
|
|
22
|
+TEST constants() {
|
|
23
|
+ ASSERT_EQm("Pi not correct!", HEL_PI, M_PI);
|
|
24
|
+ ASSERT_EQm("Pi/2 not correct!", HEL_PI_OVER_2, (M_PI / 2.0));
|
|
25
|
+ ASSERT_EQm("2Pi not correct!", HEL_2_PI, (M_PI * 2.0));
|
|
26
|
+ ASSERT_EQm("Pi/4 not correct!", HEL_PI_OVER_4, (M_PI / 4.0));
|
|
27
|
+ ASSERT_EQm("Pi/180 not correct!", HEL_PI_OVER_180, (M_PI / 180.0));
|
|
28
|
+ ASSERT_EQm("180/Pi not correct!", HEL_180_OVER_PI, (180.0 / M_PI));
|
|
29
|
+ PASS();
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+TEST types() {
|
|
33
|
+ ASSERT_EQ(sizeof(vec2_t), (2 * sizeof(vec_t)));
|
|
34
|
+ ASSERT_EQ(sizeof(vec3_t), (3 * sizeof(vec_t)));
|
|
35
|
+ ASSERT_EQ(sizeof(vec4_t), (4 * sizeof(vec_t)));
|
|
36
|
+ ASSERT_EQ(sizeof(matrix_t), (16 * sizeof(vec_t)));
|
|
37
|
+ PASS();
|
|
38
|
+}
|
5
|
39
|
|
6
|
|
-void helMathTest()
|
7
|
|
-{
|
8
|
|
- printf("180/PI: %f, %f, %f\n",
|
9
|
|
- HEL_180_OVER_PI,
|
10
|
|
- 180.0f / HEL_PI,
|
11
|
|
- 180.0 / M_PI);
|
|
40
|
+TEST conversionToRad(vec_t deg) {
|
|
41
|
+ vec_t conv = HEL_DEG_TO_RAD(deg);
|
|
42
|
+ vec_t hand = (deg * M_PI / 180.0);
|
|
43
|
+ if (conv != hand) {
|
|
44
|
+ printf("Degree to Radian conversion failed: %f != %f\n", conv, hand);
|
|
45
|
+ FAIL();
|
|
46
|
+ } else {
|
|
47
|
+ PASS();
|
|
48
|
+ }
|
12
|
49
|
}
|
13
|
50
|
|
|
51
|
+TEST conversionToDeg(vec_t rad) {
|
|
52
|
+ vec_t conv = HEL_RAD_TO_DEG(rad);
|
|
53
|
+ vec_t hand = (rad * 180.0 / M_PI);
|
|
54
|
+ if (conv != hand) {
|
|
55
|
+ printf("Radian to Degree conversion failed: %f != %f\n", conv, hand);
|
|
56
|
+ FAIL();
|
|
57
|
+ } else {
|
|
58
|
+ PASS();
|
|
59
|
+ }
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+#define TESTNUMS 100
|
|
63
|
+TEST random(vec_t bound[2]) {
|
|
64
|
+ for (int i = 0; i < TESTNUMS; i++) {
|
|
65
|
+ vec_t number = helRandomNum(bound[0], bound[1]);
|
|
66
|
+ ASSERT(number >= bound[0]);
|
|
67
|
+ ASSERT(number <= bound[1]);
|
|
68
|
+ }
|
|
69
|
+ PASS();
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+SUITE(mathSuite) {
|
|
73
|
+ RUN_TEST(constants);
|
|
74
|
+ RUN_TEST(types);
|
|
75
|
+ for (int i = 0; i < (sizeof(testDegrees) / sizeof(testDegrees[0])); i++) {
|
|
76
|
+ RUN_TESTp(conversionToRad, testDegrees[i]);
|
|
77
|
+ }
|
|
78
|
+ for (int i = 0; i < (sizeof(testRads) / sizeof(testRads[0])); i++) {
|
|
79
|
+ RUN_TESTp(conversionToDeg, testRads[i]);
|
|
80
|
+ }
|
|
81
|
+ for (int i = 0; i < sizeof(testBounds) / sizeof(testBounds[0]); i++) {
|
|
82
|
+ RUN_TESTp(random, testBounds[i]);
|
|
83
|
+ }
|
|
84
|
+}
|
14
|
85
|
|
15
|
|
-int main(int argc, char *argv[])
|
16
|
|
-{
|
17
|
|
- helMathTest();
|
|
86
|
+GREATEST_MAIN_DEFS();
|
18
|
87
|
|
19
|
|
- return 0;
|
|
88
|
+int main(int argc, char *argv[]) {
|
|
89
|
+ GREATEST_MAIN_BEGIN();
|
|
90
|
+ RUN_SUITE(mathSuite);
|
|
91
|
+ GREATEST_MAIN_END();
|
20
|
92
|
}
|
21
|
93
|
|