1
0
forked from 0ad/0ad
0ad/source/lib/tests/test_rand.h
janwas 9d2acce9d8 # SwEng/cleanup
- deleted most old libraries/headers in codepit to avoid confusion (they
are now in SVN anyway). updated required-libraries-linux.txt accordingly
- moved rand() into separate file, out of lib.cpp
- removed CGUIScrollBarStyle.cpp to avoid empty-file warning
- wxwidgets.h: remove redundant #pragma lib and include wxw PCH
- move openal-specific stuff to external_libraries/openal.h
- cpu, bsd: macosx is-a bsd, so only test OS_BSD

This was SVN commit r5082.
2007-05-18 00:14:26 +00:00

43 lines
943 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), 0);
debug_skip_next_err(ERR::INVALID_PARAM);
TS_ASSERT_EQUALS(rand(2, ~0u), 0);
}
// returned number must be in [min, max)
void TestReturnedRange()
{
for(int i = 0; i < 100; i++)
{
uint min = rand(), max = min+rand();
uint x = rand(min, max);
TS_ASSERT(min <= x && x < max);
}
}
// make sure both possible values are hit
void TestTwoValues()
{
uint ones = 0, twos = 0;
for(int i = 0; i < 100; i++)
{
uint 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, 100);
TS_ASSERT(ones > 10 && twos > 10);
}
};