MCPcopy Create free account
hub / github.com/boost-ext/ut / main

Function main

example/expect.cpp:17–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16struct dummy_struct {};
17int main() {
18 using namespace boost::ut;
19
20 "operators"_test = [] {
21 expect(0_i == sum());
22 expect(2_i != sum(1, 2));
23 expect(sum(1) >= 0_i);
24 expect(sum(1) <= 1_i);
25 };
26
27 "message"_test = [] { expect(3_i == sum(1, 2)) << "wrong sum"; };
28
29 "expressions"_test = [] {
30 expect(0_i == sum() and 42_i == sum(40, 2));
31 expect(1_i == sum() or 0_i == sum());
32 expect(1_i == sum() or (sum() != 0_i or sum(1) > 0_i)) << "compound";
33 };
34
35 "that"_test = [] {
36 expect(that % 0 == sum());
37 expect(that % 42 == sum(40, 2) and that % (1 + 2) == sum(1, 2));
38 expect(that % 1 != 2 or 2_i > 3);
39 };
40
41 "eq/neq/gt/ge/lt/le"_test = [] {
42 // type_traits::is_stream_insertable_v constraint check
43
44 static_assert(type_traits::is_stream_insertable_v<int>);
45 static_assert(!type_traits::is_stream_insertable_v<dummy_struct>);
46
47 // it seems it produces nice error information
48 // leaving this as easy way to check failing compilation in case of doubt
49 // expect(eq(dummy_struct{}, sum(40, 2)));
50 // gcc
51 // expect.cpp:46:14: error: no matching function for call to ‘eq(dummy_struct, int)’
52 // 46 | expect(eq(dummy_struct{}, sum(40, 2)));
53 // | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
54 // clang
55 // expect.cpp:51:12: error: no matching function for call to 'eq'
56 // 51 | expect(eq(dummy_struct{}, sum(40, 2)));
57 // | ^~
58
59 expect(eq(42, sum(40, 2)));
60 expect(neq(1, 2));
61 expect(eq(sum(1), 1) and neq(sum(1, 2), 2));
62 expect(eq(1, 1) and that % 1 == 1 and 1_i == 1);
63 };
64
65 "floating points"_test = [] {
66 expect(42.1_d == 42.101) << "epsilon=0.1";
67 expect(42.10_d == 42.101) << "epsilon=0.01";
68 expect(42.10000001 == 42.1_d) << "epsilon=0.1";
69 };
70
71 "strings"_test = [] {
72 using namespace std::literals::string_view_literals;
73 using namespace std::literals::string_literals;
74

Callers

nothing calls this directly

Calls 3

expectFunction · 0.85
eqFunction · 0.85
neqFunction · 0.85

Tested by

no test coverage detected