1
0
forked from 0ad/0ad
0ad/source/lib/tests/test_rand.h
janwas ffdff6888d add NUMA and shared-L2-cache detect code (required at work)
enable most of IA-32 specific code to be used in amd64 (resides in
directory lib/sysdep/x86_x64)

bits: add IsBitSet
remove mem_PageSize (use os_cpu_PageSize instead)
cpuid: change interface to allow gracefully supporting later
subfunctions that require input parameters
amd64_asm.asm: add amd64 implementation of cpuid
cpu: move functions provided by OS to sysdep/os_cpu.cpp
cpu topology: avoid trouble when process affinity is set by remapping
processor numbers to 0..PopulationCount(processAffinity)
topology.cpp: move ex-ia32 topology code here.

This was SVN commit r5945.
2008-05-12 18:15:08 +00:00

43 lines
975 B
C++

#include "lib/self_test.h"
#include "lib/rand.h"
class TestRand : public CxxTest::TestSuite
{
public:
// complain if huge interval or min > max
void TestParam()
{
debug_skip_next_err(ERR::INVALID_PARAM);
TS_ASSERT_EQUALS(rand(1, 0), size_t(0));
debug_skip_next_err(ERR::INVALID_PARAM);
TS_ASSERT_EQUALS(rand(2, ~0u), size_t(0));
}
// returned number must be in [min, max)
void TestReturnedRange()
{
for(int i = 0; i < 100; i++)
{
size_t min = rand(), max = min+rand();
size_t x = rand(min, max);
TS_ASSERT(min <= x && x < max);
}
}
// make sure both possible values are hit
void TestTwoValues()
{
size_t ones = 0, twos = 0;
for(int i = 0; i < 100; i++)
{
size_t x = rand(1, 3);
// paranoia: don't use array (x might not be 1 or 2 - checked below)
if(x == 1) ones++;
if(x == 2) twos++;
}
TS_ASSERT_EQUALS(ones+twos, size_t(100));
TS_ASSERT(ones > 10 && twos > 10);
}
};