RandomNumberGeneration.tests.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Created by Martin on 06/10/2019.
  3. *
  4. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include "catch.hpp"
  8. #include "internal/catch_random_number_generator.h"
  9. TEST_CASE("Our PCG implementation provides expected results for known seeds", "[rng]") {
  10. Catch::SimplePcg32 rng;
  11. SECTION("Default seeded") {
  12. REQUIRE(rng() == 0xfcdb943b);
  13. REQUIRE(rng() == 0x6f55b921);
  14. REQUIRE(rng() == 0x4c17a916);
  15. REQUIRE(rng() == 0x71eae25f);
  16. REQUIRE(rng() == 0x6ce7909c);
  17. }
  18. SECTION("Specific seed") {
  19. rng.seed(0xabcd1234);
  20. REQUIRE(rng() == 0x57c08495);
  21. REQUIRE(rng() == 0x33c956ac);
  22. REQUIRE(rng() == 0x2206fd76);
  23. REQUIRE(rng() == 0x3501a35b);
  24. REQUIRE(rng() == 0xfdffb30f);
  25. // Also check repeated output after reseeding
  26. rng.seed(0xabcd1234);
  27. REQUIRE(rng() == 0x57c08495);
  28. REQUIRE(rng() == 0x33c956ac);
  29. REQUIRE(rng() == 0x2206fd76);
  30. REQUIRE(rng() == 0x3501a35b);
  31. REQUIRE(rng() == 0xfdffb30f);
  32. }
  33. }
  34. TEST_CASE("Comparison ops", "[rng]") {
  35. using Catch::SimplePcg32;
  36. REQUIRE(SimplePcg32{} == SimplePcg32{});
  37. REQUIRE(SimplePcg32{ 0 } != SimplePcg32{});
  38. REQUIRE_FALSE(SimplePcg32{ 1 } == SimplePcg32{ 2 });
  39. REQUIRE_FALSE(SimplePcg32{ 1 } != SimplePcg32{ 1 });
  40. }