Repository navigation
Expand file tree
/
Copy pathtest_helpers.h
More file actions
59 lines (48 loc) · 1.36 KB
/
Copy pathtest_helpers.h
File metadata and controls
59 lines (48 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* File: test_helpers.h
* Author: Daniel Hannon
*
* Copyright: 2023 Daniel Hannon
*/
#include <compare>
#include <random>
#ifndef TEST_HELPERS_H_583EA76E46D841E09555B7A66D76820F
#define TEST_HELPERS_H_583EA76E46D841E09555B7A66D76820F 1
#include <catch2/generators/catch_generators_all.hpp>
#include <utility>
template<typename T>
class RandomPairGenerator : public Catch::Generators::IGenerator<std::pair<T, T>> {
std::minstd_rand m_rand;
std::uniform_int_distribution<T> m_dist;
std::pair<T, T> current;
public:
RandomPairGenerator(T low, T high):
m_rand{std::random_device{}()},
m_dist(low, high)
{
static_cast<void>(next());
}
std::pair<T, T> const& get() const override {
return current;
}
bool next() override {
current = {m_dist(m_rand), m_dist(m_rand)};
return true;
}
};
template<typename T>
Catch::Generators::GeneratorWrapper<std::pair<T, T>> pair_random(T low, T high) {
return Catch::Generators::GeneratorWrapper<std::pair<T, T>>(
new RandomPairGenerator<T>(low,high)
);
}
inline constexpr std::string_view comparisonString(std::partial_ordering x) {
if (x == std::partial_ordering::less)
return "Less than";
if (x == std::partial_ordering::equivalent)
return "Equal to";
if (x == std::partial_ordering::greater)
return "Greater than";
return "Unknown";
}
#endif // TEST_HELPERS_H_583EA76E46D841E09555B7A66D76820F