Browse Source

Moved HEL Unit Tests

Thomas Buck 10 years ago
parent
commit
fa79492b6b
7 changed files with 326 additions and 287 deletions
  1. 3
    3
      Makefile
  2. 0
    238
      src/hel/Matrix.cpp
  3. 0
    26
      src/hel/Quaternion.cpp
  4. 0
    20
      src/hel/math.cpp
  5. 259
    0
      test/hel/Matrix.cpp
  6. 43
    0
      test/hel/Quaternion.cpp
  7. 21
    0
      test/hel/math.cpp

+ 3
- 3
Makefile View File

@@ -323,7 +323,7 @@ Matrix.test:
323 323
 	mkdir -p $(BUILD_TEST_DIR)
324 324
 	$(CC) -Wall -g -DMATRIX_UNIT_TEST -lm -lstdc++ -Iinclude \
325 325
 	src/hel/Matrix.cpp src/hel/Quaternion.cpp src/hel/Vector3d.cpp \
326
-	-o $(BUILD_TEST_DIR)/Matrix.test
326
+	test/hel/Matrix.cpp -o $(BUILD_TEST_DIR)/Matrix.test
327 327
 	@-echo "================================================="
328 328
 	@-echo "Running Matrix unit test"
329 329
 	$(BUILD_TEST_DIR)/Matrix.test
@@ -332,7 +332,7 @@ Quaternion.test:
332 332
 	@-echo "Building Quaternion unit test"
333 333
 	mkdir -p $(BUILD_TEST_DIR)
334 334
 	$(CC) -Wall -g -DUNIT_TEST_QUATERNION -lm -lstdc++ -Iinclude \
335
-	src/hel/Quaternion.cpp -o $(BUILD_TEST_DIR)/Quaternion.test
335
+	src/hel/Quaternion.cpp test/hel/Quaternion.cpp -o $(BUILD_TEST_DIR)/Quaternion.test
336 336
 	@-echo "================================================="
337 337
 	@-echo "Running Quaternion unit test"
338 338
 	$(BUILD_TEST_DIR)/Quaternion.test
@@ -341,7 +341,7 @@ Math.test:
341 341
 	@-echo "Building Math unit test"
342 342
 	mkdir -p $(BUILD_TEST_DIR)
343 343
 	$(CC) -Wall -g -DMATH_UNIT_TEST -lm -lstdc++ -Iinclude \
344
-	src/hel/math.cpp src/hel/Vector3d.cpp -o $(BUILD_TEST_DIR)/Math.test
344
+	src/hel/math.cpp src/hel/Vector3d.cpp test/hel/math.cpp -o $(BUILD_TEST_DIR)/Math.test
345 345
 	@-echo "================================================="
346 346
 	@-echo "Running hel unit test"
347 347
 	$(BUILD_TEST_DIR)/Math.test

+ 0
- 238
src/hel/Matrix.cpp View File

@@ -488,241 +488,3 @@ void Matrix::multiply(const matrix_t a, const matrix_t b, matrix_t result)
488 488
 #endif
489 489
 }
490 490
 
491
-
492
-////////////////////////////////////////////////////////////
493
-// Unit Test
494
-////////////////////////////////////////////////////////////
495
-
496
-#ifdef MATRIX_UNIT_TEST
497
-#include <strings.h>
498
-/* <Order> is (r)ow or (c)ol */
499
-void generateMatrixSourceTest(char order)
500
-{
501
-	int i, j, k;
502
-
503
-
504
-	if (order == 'r')
505
-	{
506
-		printf("/* Row order */\n");
507
-	}
508
-	else
509
-	{
510
-		printf("/* Column order */\n");
511
-	}
512
-
513
-	for (i = 0; i < 4; ++i)
514
-	{
515
-		for (j = 0; j < 4; ++j)
516
-		{
517
-			if (order == 'r')
518
-			{
519
-				printf("result[%2i] = ", j+i*4);
520
-			}
521
-			else
522
-			{
523
-				printf("result[%2i] = ", j+i*4);
524
-			}
525
-
526
-			for (k = 0; k < 4; ++k)
527
-			{
528
-				if (order == 'r')
529
-				{
530
-					printf("a[%2i] * b[%2i]%s",
531
-							  k+i*4, j+k*4, (k == 3) ? ";\n" : " + ");
532
-				}
533
-				else
534
-				{
535
-					printf("a[%2i] * b[%2i]%s",
536
-							 i+k*4, k+j*4, (k == 3) ? ";\n" : " + ");
537
-				}
538
-
539
-				//sum+=(elements[i+k*4]*m.elements[k+j*4]);
540
-			}
541
-
542
-			//result.elements[i+j*4]=sum;
543
-		}
544
-
545
-		printf("\n");
546
-	}
547
-
548
-	printf("\n");
549
-
550
-	printf("/* Transpose */\n");
551
-	for(i = 0; i < 4; ++i)
552
-	{
553
-		for (j = 0; j < 4; ++j)
554
-		{
555
-			printf("a[%2i] = b[%2i]%s",
556
-					 j+i*4, i+j*4, (j == 3) ? ";\n" : "; ");
557
-		}
558
-	}
559
-}
560
-
561
-
562
-int runMatrixUnitTest()
563
-{
564
-	unsigned int i, errs;
565
-	Matrix a, b, c;
566
-	matrix_t m;
567
-
568
-
569
-	// Test 3 cases of identity use
570
-	for (errs = 0, i = 0; i < 3; ++i)
571
-	{
572
-		// Fill A matrix with garbage
573
-		m[ 0] = m[ 1] = m[ 2] = m[ 3] = 45.0f;
574
-		m[ 4] = m[ 5] = m[ 6] = m[ 7] = 90.0f;
575
-		m[ 8] = m[ 9] = m[10] = m[11] = 180.0f;
576
-		m[12] = m[13] = m[14] = m[15] = 270.0f;
577
-		a.setMatrix(m);
578
-
579
-		switch (i)
580
-		{
581
-		case 0:
582
-			printf("Set to Identity");
583
-			a.setIdentity();
584
-			break;
585
-		case 1:
586
-			printf("Identity * Identity");
587
-			c.setIdentity();
588
-			b.setIdentity();
589
-			a = c * b;
590
-			break;
591
-		case 2:
592
-			printf("Identity *= Identity");
593
-			a.setIdentity();
594
-			b.setIdentity();
595
-			a = a * b;
596
-			break;
597
-		}
598
-
599
-		if (a.isIdentity())
600
-		{
601
-			printf(" \t[ Passed ]\n");
602
-		}
603
-		else
604
-		{
605
-			++errs;
606
-			printf(" \t[ Failed ]\a\n"); // beep
607
-			a.print();
608
-		}
609
-
610
-		printf("\n");
611
-	}
612
-
613
-	/* 2003.06.18, Mongoose - These tests are weak and
614
-		only spot check some of the matrix */
615
-
616
-
617
-	/* Cheap translation test */
618
-	a.setIdentity();
619
-	printf("I -> Translate (10, 20, 30)\n");
620
-	a.translate(10, 20, 30);
621
-
622
-#ifdef COLUMN_ORDER
623
-	unsigned char i0  = 0, i1  = 4, i2  =  8, i3  = 12;
624
-	unsigned char i4  = 1, i5  = 5, i6  =  9, i7  = 13;
625
-	unsigned char i8  = 2, i9  = 6, i10 = 10, i11 = 14;
626
-	unsigned char i12 = 3, i13 = 7, i14 = 11, i15 = 15;
627
-#else
628
-	unsigned char i0  =  0, i1  =  1, i2  =  2; // i3  =  3
629
-	unsigned char i4  =  4, i6  =  6; // i5  =  5, i7  =  7
630
-	unsigned char i8  =  8, i9  =  9, i10 = 10; // i11 = 11
631
-	unsigned char i12 = 12, i13 = 13, i14 = 14, i15 = 15;
632
-#endif
633
-
634
-	if (a.mMatrix[i12] != 10 ||
635
-		 a.mMatrix[i13] != 20 ||
636
-		 a.mMatrix[i14] != 30)
637
-	{
638
-			++errs;
639
-			printf(" \t[ Failed ]\a\n"); // beep
640
-			a.print();
641
-	}
642
-
643
-	/* Cheap X rotation test */
644
-	a.setIdentity();
645
-	printf("I -> Rotate (90 degrees, 0, 0)\n");
646
-	a.rotate(90*0.01745329251994329f, 0, 0);
647
-
648
-	if (a.mMatrix[i0] != 1 || a.mMatrix[i15] != 1 ||
649
-		 a.mMatrix[i9] != -1 || a.mMatrix[i6] != 1)
650
-	{
651
-			++errs;
652
-			printf(" \t[ Failed ]\a\n"); // beep
653
-			a.print();
654
-	}
655
-
656
-	/* Cheap Y rotation test */
657
-	a.setIdentity();
658
-	printf("I -> Rotate (0, 90 degrees, 0)\n");
659
-	a.rotate(0, 90*0.01745329251994329f, 0);
660
-
661
-	if (a.mMatrix[i8] != 1 || a.mMatrix[i2] != -1 ||
662
-		 a.mMatrix[i15] != 1)
663
-	{
664
-			++errs;
665
-			printf(" \t[ Failed ]\a\n"); // beep
666
-			a.print();
667
-	}
668
-
669
-	/* Cheap Z rotation test */
670
-	a.setIdentity();
671
-	printf("I -> Rotate (0, 0, 90 degrees)\n");
672
-	a.rotate(0, 0, 90*0.01745329251994329f);
673
-
674
-	if (a.mMatrix[i4] != -1 || a.mMatrix[i15] != 1 ||
675
-		 a.mMatrix[i1] != 1 || a.mMatrix[i10] != 1)
676
-	{
677
-			++errs;
678
-			printf(" \t[ Failed ]\a\n"); // beep
679
-			a.print();
680
-	}
681
-
682
-	printf("\n%i errors\n", errs);
683
-	printf("\n");
684
-
685
-	printf("Prescision test...\n");
686
-	printf("I ->\n");
687
-	a.setIdentity();
688
-	printf(" -> Rotate (0, 0, 90 degrees)\n");
689
-	a.rotate(0, 0, 90*0.01745329251994329f);
690
-	printf(" -> Translate (10, 20, 30)\n");
691
-	a.translate(10, 20, 30);
692
-	printf(" -> scale (10, 10, 10)\n");
693
-	a.scale(10, 10, 10);
694
-	a.print();
695
-
696
-	printf("\n");
697
-
698
-	printf(" -> scale (0.1, 0.1, 0.1)\n");
699
-	a.scale(0.1, 0.1, 0.1);
700
-	printf(" -> Translate (-10, -20, -30)\n");
701
-	a.translate(-10, -20, -30);
702
-	printf(" -> Rotate (0, 0, -90 degrees)\n");
703
-	a.rotate(0, 0, -90*0.01745329251994329f);
704
-	a.print();
705
-
706
-	printf("\n%i errors\n", errs);
707
-
708
-	return errs;
709
-}
710
-
711
-
712
-int main(int argc, char *argv[])
713
-{
714
-	if (argc > 2)
715
-	{
716
-		if (strcmp(argv[1], "-src") == 0)
717
-		{
718
-			generateMatrixSourceTest(argv[2][0]);
719
-			return 0;
720
-		}
721
-	}
722
-
723
-	printf("[Matrix class test]\n");
724
-	runMatrixUnitTest();
725
-
726
-	return 0;
727
-}
728
-#endif

+ 0
- 26
src/hel/Quaternion.cpp View File

@@ -403,29 +403,3 @@ Quaternion Quaternion::subtract(Quaternion a, Quaternion b)
403 403
 // Private Mutators
404 404
 ////////////////////////////////////////////////////////////
405 405
 
406
-
407
-////////////////////////////////////////////////////////////
408
-// Unit Test code
409
-////////////////////////////////////////////////////////////
410
-
411
-#ifdef UNIT_TEST_QUATERNION
412
-
413
-#include <stdio.h>
414
-
415
-int runQuaternionUnitTest(int argc, char *argv[])
416
-{
417
-    //! \todo Implement Quaternion Unit Tests!
418
-    printf("Not implemented!\n");
419
-	return 0;
420
-}
421
-
422
-
423
-int main(int argc, char *argv[])
424
-{
425
-	printf("[Quaternion class test]\n");
426
-
427
-	runQuaternionUnitTest(argc, argv);
428
-
429
-	return 0;
430
-}
431
-#endif

+ 0
- 20
src/hel/math.cpp View File

@@ -328,23 +328,3 @@ vec_t helRadToDeg(vec_t rad)
328 328
 #endif
329 329
 }
330 330
 
331
-
332
-#ifdef MATH_UNIT_TEST
333
-#include <stdio.h>
334
-
335
-void helMathTest()
336
-{
337
-	printf("180/PI: %f, %f, %f\n",
338
-			 HEL_180_OVER_PI,
339
-			 180.0f / HEL_PI,
340
-			 180.0 / M_PI);
341
-}
342
-
343
-
344
-int main(int argc, char *argv[])
345
-{
346
-	helMathTest();
347
-
348
-	return 0;
349
-}
350
-#endif

+ 259
- 0
test/hel/Matrix.cpp View File

@@ -0,0 +1,259 @@
1
+/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
+/*================================================================
3
+ *
4
+ * Project : Freyja
5
+ * Author  : Terry 'Mongoose' Hendrix II
6
+ * Website : http://www.westga.edu/~stu7440/
7
+ * Email   : stu7440@westga.edu
8
+ * Object  : Matrix
9
+ * License : No use w/o permission (C) 2002 Mongoose
10
+ * Comments: 3d Matrix class
11
+ *
12
+ *
13
+ *           This file was generated using Mongoose's C++
14
+ *           template generator script.  <stu7440@westga.edu>
15
+ *
16
+ *-- History -------------------------------------------------
17
+ *
18
+ * 2002.05.11:
19
+ * Mongoose - Created
20
+ =================================================================*/
21
+
22
+#include <stdio.h>
23
+#include <math.h>
24
+#include <strings.h>
25
+
26
+#include <hel/Matrix.h>
27
+
28
+
29
+/* <Order> is (r)ow or (c)ol */
30
+void generateMatrixSourceTest(char order)
31
+{
32
+	int i, j, k;
33
+
34
+
35
+	if (order == 'r')
36
+	{
37
+		printf("/* Row order */\n");
38
+	}
39
+	else
40
+	{
41
+		printf("/* Column order */\n");
42
+	}
43
+
44
+	for (i = 0; i < 4; ++i)
45
+	{
46
+		for (j = 0; j < 4; ++j)
47
+		{
48
+			if (order == 'r')
49
+			{
50
+				printf("result[%2i] = ", j+i*4);
51
+			}
52
+			else
53
+			{
54
+				printf("result[%2i] = ", j+i*4);
55
+			}
56
+
57
+			for (k = 0; k < 4; ++k)
58
+			{
59
+				if (order == 'r')
60
+				{
61
+					printf("a[%2i] * b[%2i]%s",
62
+							  k+i*4, j+k*4, (k == 3) ? ";\n" : " + ");
63
+				}
64
+				else
65
+				{
66
+					printf("a[%2i] * b[%2i]%s",
67
+							 i+k*4, k+j*4, (k == 3) ? ";\n" : " + ");
68
+				}
69
+
70
+				//sum+=(elements[i+k*4]*m.elements[k+j*4]);
71
+			}
72
+
73
+			//result.elements[i+j*4]=sum;
74
+		}
75
+
76
+		printf("\n");
77
+	}
78
+
79
+	printf("\n");
80
+
81
+	printf("/* Transpose */\n");
82
+	for(i = 0; i < 4; ++i)
83
+	{
84
+		for (j = 0; j < 4; ++j)
85
+		{
86
+			printf("a[%2i] = b[%2i]%s",
87
+					 j+i*4, i+j*4, (j == 3) ? ";\n" : "; ");
88
+		}
89
+	}
90
+}
91
+
92
+
93
+int runMatrixUnitTest()
94
+{
95
+	unsigned int i, errs;
96
+	Matrix a, b, c;
97
+	matrix_t m;
98
+
99
+
100
+	// Test 3 cases of identity use
101
+	for (errs = 0, i = 0; i < 3; ++i)
102
+	{
103
+		// Fill A matrix with garbage
104
+		m[ 0] = m[ 1] = m[ 2] = m[ 3] = 45.0f;
105
+		m[ 4] = m[ 5] = m[ 6] = m[ 7] = 90.0f;
106
+		m[ 8] = m[ 9] = m[10] = m[11] = 180.0f;
107
+		m[12] = m[13] = m[14] = m[15] = 270.0f;
108
+		a.setMatrix(m);
109
+
110
+		switch (i)
111
+		{
112
+		case 0:
113
+			printf("Set to Identity");
114
+			a.setIdentity();
115
+			break;
116
+		case 1:
117
+			printf("Identity * Identity");
118
+			c.setIdentity();
119
+			b.setIdentity();
120
+			a = c * b;
121
+			break;
122
+		case 2:
123
+			printf("Identity *= Identity");
124
+			a.setIdentity();
125
+			b.setIdentity();
126
+			a = a * b;
127
+			break;
128
+		}
129
+
130
+		if (a.isIdentity())
131
+		{
132
+			printf(" \t[ Passed ]\n");
133
+		}
134
+		else
135
+		{
136
+			++errs;
137
+			printf(" \t[ Failed ]\a\n"); // beep
138
+			a.print();
139
+		}
140
+
141
+		printf("\n");
142
+	}
143
+
144
+	/* 2003.06.18, Mongoose - These tests are weak and
145
+		only spot check some of the matrix */
146
+
147
+
148
+	/* Cheap translation test */
149
+	a.setIdentity();
150
+	printf("I -> Translate (10, 20, 30)\n");
151
+	a.translate(10, 20, 30);
152
+
153
+#ifdef COLUMN_ORDER
154
+	unsigned char i0  = 0, i1  = 4, i2  =  8, i3  = 12;
155
+	unsigned char i4  = 1, i5  = 5, i6  =  9, i7  = 13;
156
+	unsigned char i8  = 2, i9  = 6, i10 = 10, i11 = 14;
157
+	unsigned char i12 = 3, i13 = 7, i14 = 11, i15 = 15;
158
+#else
159
+	unsigned char i0  =  0, i1  =  1, i2  =  2; // i3  =  3
160
+	unsigned char i4  =  4, i6  =  6; // i5  =  5, i7  =  7
161
+	unsigned char i8  =  8, i9  =  9, i10 = 10; // i11 = 11
162
+	unsigned char i12 = 12, i13 = 13, i14 = 14, i15 = 15;
163
+#endif
164
+
165
+	if (a.mMatrix[i12] != 10 ||
166
+		 a.mMatrix[i13] != 20 ||
167
+		 a.mMatrix[i14] != 30)
168
+	{
169
+			++errs;
170
+			printf(" \t[ Failed ]\a\n"); // beep
171
+			a.print();
172
+	}
173
+
174
+	/* Cheap X rotation test */
175
+	a.setIdentity();
176
+	printf("I -> Rotate (90 degrees, 0, 0)\n");
177
+	a.rotate(90*0.01745329251994329f, 0, 0);
178
+
179
+	if (a.mMatrix[i0] != 1 || a.mMatrix[i15] != 1 ||
180
+		 a.mMatrix[i9] != -1 || a.mMatrix[i6] != 1)
181
+	{
182
+			++errs;
183
+			printf(" \t[ Failed ]\a\n"); // beep
184
+			a.print();
185
+	}
186
+
187
+	/* Cheap Y rotation test */
188
+	a.setIdentity();
189
+	printf("I -> Rotate (0, 90 degrees, 0)\n");
190
+	a.rotate(0, 90*0.01745329251994329f, 0);
191
+
192
+	if (a.mMatrix[i8] != 1 || a.mMatrix[i2] != -1 ||
193
+		 a.mMatrix[i15] != 1)
194
+	{
195
+			++errs;
196
+			printf(" \t[ Failed ]\a\n"); // beep
197
+			a.print();
198
+	}
199
+
200
+	/* Cheap Z rotation test */
201
+	a.setIdentity();
202
+	printf("I -> Rotate (0, 0, 90 degrees)\n");
203
+	a.rotate(0, 0, 90*0.01745329251994329f);
204
+
205
+	if (a.mMatrix[i4] != -1 || a.mMatrix[i15] != 1 ||
206
+		 a.mMatrix[i1] != 1 || a.mMatrix[i10] != 1)
207
+	{
208
+			++errs;
209
+			printf(" \t[ Failed ]\a\n"); // beep
210
+			a.print();
211
+	}
212
+
213
+	printf("\n%i errors\n", errs);
214
+	printf("\n");
215
+
216
+	printf("Prescision test...\n");
217
+	printf("I ->\n");
218
+	a.setIdentity();
219
+	printf(" -> Rotate (0, 0, 90 degrees)\n");
220
+	a.rotate(0, 0, 90*0.01745329251994329f);
221
+	printf(" -> Translate (10, 20, 30)\n");
222
+	a.translate(10, 20, 30);
223
+	printf(" -> scale (10, 10, 10)\n");
224
+	a.scale(10, 10, 10);
225
+	a.print();
226
+
227
+	printf("\n");
228
+
229
+	printf(" -> scale (0.1, 0.1, 0.1)\n");
230
+	a.scale(0.1, 0.1, 0.1);
231
+	printf(" -> Translate (-10, -20, -30)\n");
232
+	a.translate(-10, -20, -30);
233
+	printf(" -> Rotate (0, 0, -90 degrees)\n");
234
+	a.rotate(0, 0, -90*0.01745329251994329f);
235
+	a.print();
236
+
237
+	printf("\n%i errors\n", errs);
238
+
239
+	return errs;
240
+}
241
+
242
+
243
+int main(int argc, char *argv[])
244
+{
245
+	if (argc > 2)
246
+	{
247
+		if (strcmp(argv[1], "-src") == 0)
248
+		{
249
+			generateMatrixSourceTest(argv[2][0]);
250
+			return 0;
251
+		}
252
+	}
253
+
254
+	printf("[Matrix class test]\n");
255
+	runMatrixUnitTest();
256
+
257
+	return 0;
258
+}
259
+

+ 43
- 0
test/hel/Quaternion.cpp View File

@@ -0,0 +1,43 @@
1
+/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2
+/*================================================================
3
+ *
4
+ * Project : Hel
5
+ * Author  : Terry 'Mongoose' Hendrix II
6
+ * Website : http://www.westga.edu/~stu7440/
7
+ * Email   : stu7440@westga.edu
8
+ * Object  : Quaternion
9
+ * License : No use w/o permission (C) 2002 Mongoose
10
+ * Comments: Quaternion now in C++ class form fresh from the grove
11
+ *
12
+ *
13
+ *           This file was generated using Mongoose's C++
14
+ *           template generator script.  <stu7440@westga.edu>
15
+ *
16
+ *-- History -------------------------------------------------
17
+ *
18
+ * 2002.12.16:
19
+ * Mongoose - Created, based on mtk3d ( freyja )
20
+ =================================================================*/
21
+
22
+#include <stdio.h>
23
+#include <math.h>
24
+
25
+#include <hel/Quaternion.h>
26
+
27
+int runQuaternionUnitTest(int argc, char *argv[])
28
+{
29
+    //! \todo Implement Quaternion Unit Tests!
30
+    printf("Not implemented!\n");
31
+	return 0;
32
+}
33
+
34
+
35
+int main(int argc, char *argv[])
36
+{
37
+	printf("[Quaternion class test]\n");
38
+
39
+	runQuaternionUnitTest(argc, argv);
40
+
41
+	return 0;
42
+}
43
+

+ 21
- 0
test/hel/math.cpp View File

@@ -0,0 +1,21 @@
1
+#include <stdio.h>
2
+#include <math.h>
3
+
4
+#include <hel/math.h>
5
+
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);
12
+}
13
+
14
+
15
+int main(int argc, char *argv[])
16
+{
17
+	helMathTest();
18
+
19
+	return 0;
20
+}
21
+

Loading…
Cancel
Save