-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_matcher_matches_equation.cpp
128 lines (113 loc) · 2.93 KB
/
test_matcher_matches_equation.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "../source/h2_unit.cpp"
#include <limits>
#include <atomic>
SUITE(equation matches)
{
Case(integer)
{
h2::h2_equation<int> a1(123);
OK(nullptr == a1.matches(123, {}));
h2::h2_equation<const int> a2(123);
OK(nullptr == a2.matches(123, {}));
h2::h2_equation<unsigned long long> a3(123);
OK(nullptr == a3.matches(123, {}));
}
Case(string)
{
// cannot convert argument 1 from 'const char [4]' to 'const char *'
// <ConformanceMode>false</ConformanceMode>; /permissive- ==> /permissive
h2::h2_equation<char*> a1((char*)"abc");
OK(nullptr == a1.matches((char*)"abc", {}));
h2::h2_equation<h2::h2_string> a2("abc");
OK(nullptr == a2.matches("abc", {}));
h2::h2_equation<std::string> a3("abc");
OK(nullptr == a3.matches("abc", {}));
}
Case(float)
{
h2::h2_equation<float> a1(65.0);
OK(nullptr == a1.matches(65, {}));
h2::h2_equation<double> a2(65.0);
OK(nullptr == a2.matches(65, {}));
}
}
SUITE(approximate float)
{
Case(base)
{
h2::h2_approximate a;
auto a0 = a * 0.1;
OK((a0 == 0.1 * h2::h2_approximate::A));
OK((a0 + h2::h2_approximate::B == 0.1 * h2::h2_approximate::A + h2::h2_approximate::B));
auto a1 = a * 1.0;
OK((a1 == 1.0 * h2::h2_approximate::A));
OK((a1 + h2::h2_approximate::B == 1.0 * h2::h2_approximate::A + h2::h2_approximate::B));
auto a2 = a * 2.2;
OK(Eq(2.2 * h2::h2_approximate::A, 1), a2);
OK(Eq(2.2 * h2::h2_approximate::A + h2::h2_approximate::B, 1), a2 + h2::h2_approximate::B);
}
Case(absolute default approximate)
{
OK(Eq(100.0), 100.0);
OK(Eq(3.14), 3.14);
OK(Eq(1.0 / 3.0), 2.0 / 6.0);
}
Case(absolute approximate)
{
OK(Eq(100.0, 0.1), 100.1);
OK(Eq(100.0, 0.1), 100.0999);
OK(Eq(100.0, 0.1), 100);
OK(Eq(100.0, 0.1), 99.9999);
OK(Eq(100.0, 0.1), 99.9);
}
Case(absolute approximate)
{
OK(Eq(1.0 / 3.0, std::numeric_limits<double>::epsilon()), 2.0 / 6.0);
}
Case(percentage 1% approximate)
{
OK(Eq(100.0, 1 %), 101);
OK(Eq(100.0, 1 %), 100.5);
OK(Eq(100.0, 1 %), 100);
OK(Eq(100.0, 1 %), 99.5);
OK(Eq(100.0, 1 %), 99);
}
Case(percentage 0.1% approximate)
{
OK(Eq(100.0, 0.1 %), 100.1);
OK(Eq(100.0, 0.1 %), 100.05);
OK(Eq(100.0, 0.1 %), 100);
OK(Eq(100.0, 0.1 %), 99.95);
OK(Eq(100.0, 0.1 %), 99.9);
}
Case(percentage 5% approximate)
{
OK(Eq(100.0, 5 %), 105);
OK(Eq(100.0, 5 %), 103);
OK(Eq(100.0, 5 %), 100);
OK(Eq(100.0, 5 %), 98);
OK(Eq(100.0, 5 %), 95);
}
}
SUITE(type eq)
{
Case(int)
{
int a = 1;
OK(TypeEq<int>(), a);
}
Case(std::string)
{
std::string a = "1";
OK(TypeEq<std::string>(), a);
}
}
CASE(atomic)
{
std::atomic<int> a1(0);
a1++;
--a1;
a1 += 1;
a1 -= 1;
OK(0, (int)a1);
}