0ad/source/lib/sysdep/tests/test_sysdep.h
janwas 9542ecdd7e # boatload of fixes to get self-tests to compile+mostly run
refs #117

stub_impl_hack: defines a function otherwise provided by main.cpp

remove old self_test.h contents (e.g. TEST); superceded by cxxtestgen
TS_ASSERT etc.
only include self_test from a test (otherwise, cxxtest include dir won't
be set)
cxxtest won't run tests named only "test"; add more descriptive name

FIXES uncovered by self tests
lib: infinite loop in log2
lockfree: incorrect params

This was SVN commit r3979.
2006-06-08 19:03:43 +00:00

54 lines
1.6 KiB
C++

#include "lib/self_test.h"
#include "lib/sysdep/sysdep.h"
#include "lib/posix.h" // fminf etc.
class TestSysdep : public CxxTest::TestSuite
{
public:
void test_float_int()
{
TS_ASSERT_EQUALS(i32_from_float(0.99999f), 0);
TS_ASSERT_EQUALS(i32_from_float(1.0f), 1);
TS_ASSERT_EQUALS(i32_from_float(1.01f), 1);
TS_ASSERT_EQUALS(i32_from_float(5.6f), 5);
TS_ASSERT_EQUALS(i32_from_double(0.99999), 0);
TS_ASSERT_EQUALS(i32_from_double(1.0), 1);
TS_ASSERT_EQUALS(i32_from_double(1.01), 1);
TS_ASSERT_EQUALS(i32_from_double(5.6), 5);
TS_ASSERT_EQUALS(i64_from_double(0.99999), 0LL);
TS_ASSERT_EQUALS(i64_from_double(1.0), 1LL);
TS_ASSERT_EQUALS(i64_from_double(1.01), 1LL);
TS_ASSERT_EQUALS(i64_from_double(5.6), 5LL);
}
void test_round()
{
TS_ASSERT_EQUALS(rintf(0.99999f), 1.0f);
TS_ASSERT_EQUALS(rintf(1.0f), 1.0f);
TS_ASSERT_EQUALS(rintf(1.01f), 1.0f);
TS_ASSERT_EQUALS(rintf(5.6f), 5.0f);
TS_ASSERT_EQUALS(rint(0.99999), 1.0);
TS_ASSERT_EQUALS(rint(1.0), 1.0);
TS_ASSERT_EQUALS(rint(1.01), 1.0);
TS_ASSERT_EQUALS(rint(5.6), 5.0);
}
void test_min_max()
{
TS_ASSERT_EQUALS(fminf(0.0f, 10000.0f), 0.0f);
TS_ASSERT_EQUALS(fminf(100.0f, 10000.0f), 100.0f);
TS_ASSERT_EQUALS(fminf(-1.0f, 2.0f), -1.0f);
TS_ASSERT_EQUALS(fminf(-2.0f, 1.0f), -2.0f);
TS_ASSERT_EQUALS(fminf(0.001f, 0.00001f), 0.00001f);
TS_ASSERT_EQUALS(fmaxf(0.0f, 10000.0f), 10000.0f);
TS_ASSERT_EQUALS(fmaxf(100.0f, 10000.0f), 10000.0f);
TS_ASSERT_EQUALS(fmaxf(-1.0f, 2.0f), 2.0f);
TS_ASSERT_EQUALS(fmaxf(-2.0f, 1.0f), 1.0f);
TS_ASSERT_EQUALS(fmaxf(0.001f, 0.00001f), 0.001f);
}
};