mock_device.h 873 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // mock_device.h
  3. // shared_random_generator
  4. //
  5. // Created by Sam Jaffe on 3/25/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <sstream>
  10. #include <gmock/gmock.h>
  11. #include <random/device.h>
  12. #include <random/distribution.h>
  13. #ifndef CONCAT
  14. #define CONCAT2(A, B) A##B
  15. #define CONCAT(A, B) CONCAT2(A, B)
  16. #endif
  17. #define MOCK_DEVICE(T) \
  18. MOCK_METHOD1(CONCAT(apply_, T), T(std::string const &)); \
  19. T apply(Distribution<T> const & dist) final { \
  20. return CONCAT(apply_, T)(to_string(dist)); \
  21. }
  22. namespace engine::random {
  23. class MockDevice : public Device {
  24. public:
  25. result_type operator()() final { return apply_uint32_t("?"); }
  26. IMPLEMENT_DEVICE(MOCK_DEVICE)
  27. };
  28. }
  29. #undef MOCK_DEVICE