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 <cmath> |
---|
16 | |
---|
17 | #include "core.h" |
---|
18 | #include "lol/unit.h" |
---|
19 | |
---|
20 | namespace lol |
---|
21 | { |
---|
22 | |
---|
23 | LOLUNIT_FIXTURE(TrigTest) |
---|
24 | { |
---|
25 | public: |
---|
26 | void setUp() {} |
---|
27 | void tearDown() {} |
---|
28 | |
---|
29 | LOLUNIT_TEST(test_sin) |
---|
30 | { |
---|
31 | for (int i = -10000; i < 10000; i++) |
---|
32 | { |
---|
33 | double f = (double)i * (1.0 / 1000.0); |
---|
34 | #if defined __GNUC__ |
---|
35 | double a = __builtin_sin(f); |
---|
36 | #else |
---|
37 | double a = sin(f); |
---|
38 | #endif |
---|
39 | double b = lol_sin(f); |
---|
40 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
41 | } |
---|
42 | |
---|
43 | for (int i = -10000; i < 10000; i++) |
---|
44 | { |
---|
45 | double f = (double)i * (1.0 / 100000.0); |
---|
46 | #if defined __GNUC__ |
---|
47 | double a = __builtin_sin(f); |
---|
48 | #else |
---|
49 | double a = sin(f); |
---|
50 | #endif |
---|
51 | double b = lol_sin(f); |
---|
52 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | LOLUNIT_TEST(test_cos) |
---|
57 | { |
---|
58 | for (int i = -10000; i < 10000; i++) |
---|
59 | { |
---|
60 | double f = (double)i * (1.0 / 1000.0); |
---|
61 | #if defined __GNUC__ |
---|
62 | double a = __builtin_cos(f); |
---|
63 | #else |
---|
64 | double a = cos(f); |
---|
65 | #endif |
---|
66 | double b = lol_cos(f); |
---|
67 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
68 | } |
---|
69 | |
---|
70 | for (int i = -10000; i < 10000; i++) |
---|
71 | { |
---|
72 | double f = (double)i * (1.0 / 100000.0); |
---|
73 | #if defined __GNUC__ |
---|
74 | double a = __builtin_cos(f); |
---|
75 | #else |
---|
76 | double a = cos(f); |
---|
77 | #endif |
---|
78 | double b = lol_cos(f); |
---|
79 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | LOLUNIT_TEST(test_sincos) |
---|
84 | { |
---|
85 | for (int i = -10000; i < 10000; i++) |
---|
86 | { |
---|
87 | double f = (double)i * (1.0 / 1000.0); |
---|
88 | #if defined __GNUC__ |
---|
89 | double a1 = __builtin_sin(f); |
---|
90 | double a2 = __builtin_cos(f); |
---|
91 | #else |
---|
92 | double a1 = sin(f); |
---|
93 | double a2 = cos(f); |
---|
94 | #endif |
---|
95 | double b1, b2; |
---|
96 | lol_sincos(f, &b1, &b2); |
---|
97 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); |
---|
98 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); |
---|
99 | } |
---|
100 | |
---|
101 | for (int i = -10000; i < 10000; i++) |
---|
102 | { |
---|
103 | double f = (double)i * (1.0 / 100000.0); |
---|
104 | #if defined __GNUC__ |
---|
105 | double a1 = __builtin_sin(f); |
---|
106 | double a2 = __builtin_cos(f); |
---|
107 | #else |
---|
108 | double a1 = sin(f); |
---|
109 | double a2 = cos(f); |
---|
110 | #endif |
---|
111 | double b1, b2; |
---|
112 | lol_sincos(f, &b1, &b2); |
---|
113 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a1, b1, fabs(f) * 1e-11); |
---|
114 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a2, b2, fabs(f) * 1e-11); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | LOLUNIT_TEST(test_tan) |
---|
119 | { |
---|
120 | for (int i = -100000; i < 100000; i++) |
---|
121 | { |
---|
122 | double f = (double)i * (1.0 / 10000.0); |
---|
123 | #if defined __GNUC__ |
---|
124 | double a = __builtin_tan(f); |
---|
125 | #else |
---|
126 | double a = tan(f); |
---|
127 | #endif |
---|
128 | double b = lol_tan(f); |
---|
129 | if (fabs(a) > 1e4) |
---|
130 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); |
---|
131 | else if (fabs(a) > 1.0) |
---|
132 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); |
---|
133 | else |
---|
134 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
135 | } |
---|
136 | |
---|
137 | for (int i = -10000; i < 10000; i++) |
---|
138 | { |
---|
139 | double f = (double)i * (1.0 / 100000.0); |
---|
140 | #if defined __GNUC__ |
---|
141 | double a = __builtin_tan(f); |
---|
142 | #else |
---|
143 | double a = tan(f); |
---|
144 | #endif |
---|
145 | double b = lol_tan(f); |
---|
146 | if (fabs(a) > 1e4) |
---|
147 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * fabs(a) * 1e-11); |
---|
148 | else if (fabs(a) > 1.0) |
---|
149 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(a) * 1e-11); |
---|
150 | else |
---|
151 | LOLUNIT_ASSERT_DOUBLES_EQUAL(a, b, fabs(f) * 1e-11); |
---|
152 | } |
---|
153 | } |
---|
154 | }; |
---|
155 | |
---|
156 | } /* namespace lol */ |
---|
157 | |
---|