1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #include <cppunit/extensions/HelperMacros.h> |
---|
16 | #include <cppunit/TestCaller.h> |
---|
17 | #include <cppunit/TestCase.h> |
---|
18 | #include <cppunit/TestSuite.h> |
---|
19 | |
---|
20 | #include <cmath> |
---|
21 | |
---|
22 | #include "core.h" |
---|
23 | |
---|
24 | namespace lol |
---|
25 | { |
---|
26 | |
---|
27 | class TrigTest : public CppUnit::TestCase |
---|
28 | { |
---|
29 | CPPUNIT_TEST_SUITE(TrigTest); |
---|
30 | CPPUNIT_TEST(test_sin); |
---|
31 | CPPUNIT_TEST_SUITE_END(); |
---|
32 | |
---|
33 | public: |
---|
34 | TrigTest() : CppUnit::TestCase("Trigonometry Test") {} |
---|
35 | |
---|
36 | void setUp() {} |
---|
37 | |
---|
38 | void tearDown() {} |
---|
39 | |
---|
40 | void test_sin() |
---|
41 | { |
---|
42 | for (int i = -10000; i < 10000; i++) |
---|
43 | { |
---|
44 | double f = (double)i * (1.0 / 1000.0); |
---|
45 | double a = __builtin_sin(f); |
---|
46 | double b = lol_sin(f); |
---|
47 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
48 | } |
---|
49 | |
---|
50 | for (int i = -10000; i < 10000; i++) |
---|
51 | { |
---|
52 | double f = (double)i * (1.0 / 100000.0); |
---|
53 | double a = __builtin_sin(f); |
---|
54 | double b = lol_sin(f); |
---|
55 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
56 | } |
---|
57 | |
---|
58 | for (int i = -10000; i < 10000; i++) |
---|
59 | { |
---|
60 | double f = (double)i * (1.0 / 1000.0); |
---|
61 | double a = __builtin_cos(f); |
---|
62 | double b = lol_cos(f); |
---|
63 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
64 | } |
---|
65 | |
---|
66 | for (int i = -10000; i < 10000; i++) |
---|
67 | { |
---|
68 | double f = (double)i * (1.0 / 100000.0); |
---|
69 | double a = __builtin_cos(f); |
---|
70 | double b = lol_cos(f); |
---|
71 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
72 | } |
---|
73 | |
---|
74 | for (int i = -10000; i < 10000; i++) |
---|
75 | { |
---|
76 | double f = (double)i * (1.0 / 1000.0); |
---|
77 | double a1 = __builtin_sin(f); |
---|
78 | double a2 = __builtin_cos(f); |
---|
79 | double b1, b2; |
---|
80 | lol_sincos(f, &b1, &b2); |
---|
81 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); |
---|
82 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); |
---|
83 | } |
---|
84 | |
---|
85 | for (int i = -10000; i < 10000; i++) |
---|
86 | { |
---|
87 | double f = (double)i * (1.0 / 100000.0); |
---|
88 | double a1 = __builtin_sin(f); |
---|
89 | double a2 = __builtin_cos(f); |
---|
90 | double b1, b2; |
---|
91 | lol_sincos(f, &b1, &b2); |
---|
92 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); |
---|
93 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); |
---|
94 | } |
---|
95 | |
---|
96 | for (int i = -100000; i < 100000; i++) |
---|
97 | { |
---|
98 | double f = (double)i * (1.0 / 10000.0); |
---|
99 | double a = __builtin_tan(f); |
---|
100 | double b = lol_tan(f); |
---|
101 | if (fabs(a) > 1e4) |
---|
102 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); |
---|
103 | else if (fabs(a) > 1.0) |
---|
104 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); |
---|
105 | else |
---|
106 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
107 | } |
---|
108 | |
---|
109 | for (int i = -10000; i < 10000; i++) |
---|
110 | { |
---|
111 | double f = (double)i * (1.0 / 100000.0); |
---|
112 | double a = __builtin_tan(f); |
---|
113 | double b = lol_tan(f); |
---|
114 | if (fabs(a) > 1e4) |
---|
115 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); |
---|
116 | else if (fabs(a) > 1.0) |
---|
117 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); |
---|
118 | else |
---|
119 | CPPUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
120 | } |
---|
121 | } |
---|
122 | }; |
---|
123 | |
---|
124 | CPPUNIT_TEST_SUITE_REGISTRATION(TrigTest); |
---|
125 | |
---|
126 | } /* namespace lol */ |
---|
127 | |
---|