random_test.cxx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // random_test.cpp
  3. // shared_random_generator-test
  4. //
  5. // Created by Sam Jaffe on 8/14/20.
  6. // Copyright © 2020 Sam Jaffe. All rights reserved.
  7. //
  8. #include "random/random.h"
  9. #include "random/distribution.h"
  10. #include "random/mock/mock_device.h"
  11. #include "xcode_gtest_helper.h"
  12. using testing::_;
  13. using engine::random::Index;
  14. using engine::random::MockDevice;
  15. using engine::random::Uniform;
  16. TEST(RandomTest, UsesInt32Type) {
  17. auto mock = std::make_shared<MockDevice>();
  18. engine::random::Random generator{mock};
  19. EXPECT_CALL(*mock, apply_int32_t(_)).Times(1);
  20. generator(Uniform(-10, 10));
  21. }
  22. TEST(RandomTest, UsesUInt32Type) {
  23. auto mock = std::make_shared<MockDevice>();
  24. engine::random::Random generator{mock};
  25. EXPECT_CALL(*mock, apply_uint32_t(_)).Times(1);
  26. generator(Uniform(0u, 10u));
  27. }
  28. TEST(RandomTest, UsesSizeType) {
  29. auto mock = std::make_shared<MockDevice>();
  30. engine::random::Random generator{mock};
  31. EXPECT_CALL(*mock, apply_size_t(_)).Times(1);
  32. generator(Index(10));
  33. }
  34. TEST(RandomTest, UsesDoubleType) {
  35. auto mock = std::make_shared<MockDevice>();
  36. engine::random::Random generator{mock};
  37. EXPECT_CALL(*mock, apply_double(_)).Times(1);
  38. generator(Uniform(0.0, 10.0));
  39. }