xorshiftrandomtests.cpp 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * xorshiftrandomtests.c
  3. *
  4. * Created on: Dec 1, 2013
  5. * Author: mmm
  6. */
  7. #include <CppUTest/TestHarness.h>
  8. #include <stdint.h>
  9. extern "C" {
  10. #include <xorshiftrandom.h>
  11. }
  12. TEST_GROUP(XorShiftRandom)
  13. {
  14. };
  15. /*This test should always return 0 as the next random number (see XorShift algorithm*/
  16. TEST(XorShiftRandom, SeedZeroInitResult)
  17. {
  18. uint32_t nResult;
  19. nResult = 1;
  20. setXorShiftSeed(0);
  21. nResult = nextXorShiftUInt32();
  22. LONGS_EQUAL(0, nResult);
  23. }
  24. /*Characterization test*/
  25. TEST(XorShiftRandom, SeedOneCharacterization)
  26. {
  27. uint32_t nResult;
  28. setXorShiftSeed(1);
  29. nResult = nextXorShiftUInt32();
  30. LONGS_EQUAL(270369, nResult);
  31. nResult = nextXorShiftUInt32();
  32. LONGS_EQUAL(67634689, nResult);
  33. nResult = nextXorShiftUInt32();
  34. LONGS_EQUAL(2647435461, nResult);
  35. nResult = nextXorShiftUInt32();
  36. LONGS_EQUAL(307599695, nResult);
  37. }