mock_device.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_APPLY_DEVICE(T) \
  18. T apply(Distribution<T> const & dist) final { \
  19. std::stringstream ss; \
  20. ss << dist; \
  21. return CONCAT(apply_, T)(ss.str()); \
  22. } \
  23. MOCK_METHOD1(CONCAT(apply_, T), T(std::string const &))
  24. namespace engine::random {
  25. class MockDevice : public Device {
  26. public:
  27. result_type operator()() final { return apply_uint32_t("?"); }
  28. MOCK_APPLY_DEVICE(size_t);
  29. MOCK_APPLY_DEVICE(double);
  30. MOCK_APPLY_DEVICE(int32_t);
  31. MOCK_APPLY_DEVICE(uint32_t);
  32. };
  33. }