From 105485a3aa59339c0992c656d57202fbd7a60afc Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 2 Sep 2011 00:06:24 +0000 Subject: [PATCH] test: new test for trigonometric functions. --- test/Makefile.am | 2 +- test/trig.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/trig.cpp diff --git a/test/Makefile.am b/test/Makefile.am index 0abbdd62..c22d752e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -18,7 +18,7 @@ noinst_PROGRAMS = quad lol-bench $(cppunit_tests) TESTS = $(cppunit_tests) -lol_test_SOURCES = lol-test.cpp matrix.cpp half.cpp +lol_test_SOURCES = lol-test.cpp matrix.cpp half.cpp trig.cpp lol_test_CXXFLAGS = $(CPPUNIT_CFLAGS) lol_test_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ lol_test_LDADD = $(CPPUNIT_LIBS) diff --git a/test/trig.cpp b/test/trig.cpp new file mode 100644 index 00000000..474f6d17 --- /dev/null +++ b/test/trig.cpp @@ -0,0 +1,63 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#include + +#include + +#include "core.h" + +namespace lol +{ + +class TrigTest : public CppUnit::TestCase +{ + CPPUNIT_TEST_SUITE(TrigTest); + CPPUNIT_TEST(test_sin); + CPPUNIT_TEST_SUITE_END(); + +public: + TrigTest() : CppUnit::TestCase("Trigonometry Test") {} + + void setUp() {} + + void tearDown() {} + + void test_sin() + { + for (int i = -10000; i < 10000; i++) + { + float f = (float)i * (1.0f / 1000.0f); + double a = __builtin_sin(f); + double b = lol_sin(f); + CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-10f); + } + + for (int i = -10000; i < 10000; i++) + { + float f = (float)i * (1.0f / 100000.0f); + double a = __builtin_sin(f); + double b = lol_sin(f); + CPPUNIT_ASSERT(fabs(a - b) <= fabs(f) * 1e-10f); + } + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(TrigTest); + +} /* namespace lol */ +