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(fabs(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(fabs(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(fabs(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(fabs(a - b) <= fabs(f) * 1e-11); |
---|
72 | } |
---|
73 | } |
---|
74 | }; |
---|
75 | |
---|
76 | CPPUNIT_TEST_SUITE_REGISTRATION(TrigTest); |
---|
77 | |
---|
78 | } /* namespace lol */ |
---|
79 | |
---|