xorshiftrandomtests.cpp 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*******************************************************************************
  2. * Copyright (c) 2015, Rockwell Automation, Inc.
  3. * All rights reserved.
  4. *
  5. ******************************************************************************/
  6. #include <CppUTest/TestHarness.h>
  7. #include <stdint.h>
  8. extern "C" {
  9. #include <xorshiftrandom.h>
  10. }
  11. TEST_GROUP(XorShiftRandom)
  12. {
  13. };
  14. /* This test should always return 0 as the next random number (see XorShift algorithm) */
  15. TEST(XorShiftRandom, SeedZeroInitResult)
  16. {
  17. uint32_t nResult;
  18. nResult = 1;
  19. SetXorShiftSeed(0);
  20. nResult = NextXorShiftUint32();
  21. LONGS_EQUAL(0, nResult);
  22. }
  23. /*Characterization test*/
  24. TEST(XorShiftRandom, SeedOneCharacterization)
  25. {
  26. uint32_t nResult;
  27. SetXorShiftSeed(1);
  28. nResult = NextXorShiftUint32();
  29. LONGS_EQUAL(270369, nResult);
  30. nResult = NextXorShiftUint32();
  31. LONGS_EQUAL(67634689, nResult);
  32. nResult = NextXorShiftUint32();
  33. LONGS_EQUAL(2647435461, nResult);
  34. nResult = NextXorShiftUint32();
  35. LONGS_EQUAL(307599695, nResult);
  36. }