source: trunk/test/trig.cpp @ 894

Last change on this file since 894 was 894, checked in by sam, 8 years ago

test: do the trigonometry tests on doubles instead of floats.

  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
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
24namespace lol
25{
26
27class TrigTest : public CppUnit::TestCase
28{
29    CPPUNIT_TEST_SUITE(TrigTest);
30    CPPUNIT_TEST(test_sin);
31    CPPUNIT_TEST_SUITE_END();
32
33public:
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};
59
60CPPUNIT_TEST_SUITE_REGISTRATION(TrigTest);
61
62} /* namespace lol */
63
Note: See TracBrowser for help on using the repository browser.