forked from boost-ext/ut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpect.cpp
102 lines (84 loc) · 2.55 KB
/
expect.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
//
// Copyright (c) 2019 Kris Jusiak (kris at jusiak dot net)
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/ut.hpp>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
constexpr auto sum = [](auto... args) { return (0 + ... + args); };
int main() {
using namespace boost::ut;
"operators"_test = [] {
expect(0_i == sum());
expect(2_i != sum(1, 2));
expect(sum(1) >= 0_i);
expect(sum(1) <= 1_i);
};
"message"_test = [] { expect(3_i == sum(1, 2)) << "wrong sum"; };
"expressions"_test = [] {
expect(0_i == sum() and 42_i == sum(40, 2));
expect(1_i == sum() or 0_i == sum());
expect(1_i == sum() or (sum() != 0_i or sum(1) > 0_i)) << "compound";
};
"that"_test = [] {
expect(that % 0 == sum());
expect(that % 42 == sum(40, 2) and that % (1 + 2) == sum(1, 2));
expect(that % 1 != 2 or 2_i > 3);
};
"eq/neq/gt/ge/lt/le"_test = [] {
expect(eq(42, sum(40, 2)));
expect(neq(1, 2));
expect(eq(sum(1), 1) and neq(sum(1, 2), 2));
expect(eq(1, 1) and that % 1 == 1 and 1_i == 1);
};
"floating points"_test = [] {
expect(42.1_d == 42.101) << "epsilon=0.1";
expect(42.10_d == 42.101) << "epsilon=0.01";
expect(42.10000001 == 42.1_d) << "epsilon=0.1";
};
"fatal"_test = [] {
std::vector v{1, 2, 3};
!expect(std::size(v) == 3_ul) << "fatal assertion";
expect(v[0] == 1_i);
expect(v[1] == 2_i);
expect(v[2] == 3_i);
};
"strings"_test = [] {
using namespace std::literals::string_view_literals;
using namespace std::literals::string_literals;
expect("str"s == "str"s);
expect("str1"s != "str2"s);
expect("str"sv == "str"sv);
expect("str1"sv != "str2"sv);
expect("str"sv == "str"s);
expect("str1"sv != "str2"s);
expect("str"s == "str"sv);
expect("str1"s != "str2"sv);
};
"types"_test = [] {
expect(type<int> == type<int>);
expect(type<float> != type<double>);
const auto i = 0;
expect(type<const int> == type<decltype(i)>);
expect(type<decltype(i)> != type<int>);
};
"containers"_test = [] {
std::vector v1{1, 2, 3};
std::vector v2{1, 2, 3};
expect(v1 == v2);
};
"constant"_test = [] {
constexpr auto compile_time_v = 42;
auto run_time_v = 99;
expect(constant<42_i == compile_time_v> and run_time_v == 99_i);
};
"convertible"_test = [] {
expect(bool(std::make_unique<int>()));
expect(not bool(std::unique_ptr<int>{}));
};
}