forked from 0ad/0ad
janwas
623e649acb
all cpu-related stuff is now defined in cpu.h (with cpu_ prefix and fully encapsulated). fix quite brittle core/HT unit/package detection. implement mkdir on VC8, where it is deprecated add strdup on MacOSX move ia32 code into separate subdir. functions implemented in asm are called ia32_asm_*. add some unix versions of sysdep functions (cannot test them) timer: fix for amd64 linux This was SVN commit r4995.
55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
#include "lib/self_test.h"
|
|
|
|
#include "lib/sysdep/sysdep.h"
|
|
#include "lib/posix/posix.h" // fminf etc.
|
|
|
|
class TestSysdep : public CxxTest::TestSuite
|
|
{
|
|
public:
|
|
void test_float_int()
|
|
{
|
|
TS_ASSERT_EQUALS(cpu_i32_from_float(0.99999f), 0);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_float(1.0f), 1);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_float(1.01f), 1);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_float(5.6f), 5);
|
|
|
|
TS_ASSERT_EQUALS(cpu_i32_from_double(0.99999), 0);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_double(1.0), 1);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_double(1.01), 1);
|
|
TS_ASSERT_EQUALS(cpu_i32_from_double(5.6), 5);
|
|
|
|
TS_ASSERT_EQUALS(cpu_i64_from_double(0.99999), 0LL);
|
|
TS_ASSERT_EQUALS(cpu_i64_from_double(1.0), 1LL);
|
|
TS_ASSERT_EQUALS(cpu_i64_from_double(1.01), 1LL);
|
|
TS_ASSERT_EQUALS(cpu_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), 6.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), 6.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);
|
|
}
|
|
};
|