rippled
test
beast
beast_Zero_test.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of Beast: https://github.com/vinniefalco/Beast
4
Copyright 2014, Nikolaos D. Bougalis <nikb@bougalis.net>
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#include <ripple/beast/utility/Zero.h>
21
22
#include <ripple/beast/unit_test.h>
23
24
namespace
beast
{
25
26
struct
adl_tester
{};
27
28
int
signum
(
adl_tester
)
29
{
30
return
0;
31
}
32
33
34
namespace
inner_adl_test {
35
36
struct
adl_tester2
{};
37
38
int
signum
(
adl_tester2
)
39
{
40
return
0;
41
}
42
43
}
// detail
44
45
class
Zero_test
:
public
beast::unit_test::suite
46
{
47
private
:
48
struct
IntegerWrapper
49
{
50
int
value
;
51
52
IntegerWrapper
(
int
v)
53
:
value
(v)
54
{
55
}
56
57
int
signum
()
const
58
{
59
return
value
;
60
}
61
};
62
63
public
:
64
void
expect_same
(
bool
result,
bool
correct,
char
const
* message)
65
{
66
expect(result == correct, message);
67
}
68
69
void
70
test_lhs_zero
(
IntegerWrapper
x)
71
{
72
expect_same
(x >= zero, x.
signum
() >= 0,
73
"lhs greater-than-or-equal-to"
);
74
expect_same
(x > zero, x.
signum
() > 0,
75
"lhs greater than"
);
76
expect_same
(x == zero, x.
signum
() == 0,
77
"lhs equal to"
);
78
expect_same
(x != zero, x.
signum
() != 0,
79
"lhs not equal to"
);
80
expect_same
(x < zero, x.
signum
() < 0,
81
"lhs less than"
);
82
expect_same
(x <= zero, x.
signum
() <= 0,
83
"lhs less-than-or-equal-to"
);
84
}
85
86
void
87
test_lhs_zero
()
88
{
89
testcase (
"lhs zero"
);
90
91
test_lhs_zero
(-7);
92
test_lhs_zero
(0);
93
test_lhs_zero
(32);
94
}
95
96
void
97
test_rhs_zero
(
IntegerWrapper
x)
98
{
99
expect_same
(zero >= x, 0 >= x.
signum
(),
100
"rhs greater-than-or-equal-to"
);
101
expect_same
(zero > x, 0 > x.
signum
(),
102
"rhs greater than"
);
103
expect_same
(zero == x, 0 == x.
signum
(),
104
"rhs equal to"
);
105
expect_same
(zero != x, 0 != x.
signum
(),
106
"rhs not equal to"
);
107
expect_same
(zero < x, 0 < x.
signum
(),
108
"rhs less than"
);
109
expect_same
(zero <= x, 0 <= x.
signum
(),
110
"rhs less-than-or-equal-to"
);
111
}
112
113
void
114
test_rhs_zero
()
115
{
116
testcase (
"rhs zero"
);
117
118
test_rhs_zero
(-4);
119
test_rhs_zero
(0);
120
test_rhs_zero
(64);
121
}
122
123
void
124
test_adl
()
125
{
126
expect (
adl_tester
{} == zero,
"ADL failure!"
);
127
expect (
inner_adl_test::adl_tester2
{} == zero,
"ADL failure!"
);
128
}
129
130
void
131
run
()
override
132
{
133
test_lhs_zero
();
134
test_rhs_zero
();
135
test_adl
();
136
}
137
138
};
139
140
BEAST_DEFINE_TESTSUITE
(Zero, types,
beast
);
141
142
}
beast::Zero_test::test_lhs_zero
void test_lhs_zero()
Definition:
beast_Zero_test.cpp:87
beast::Zero_test::test_adl
void test_adl()
Definition:
beast_Zero_test.cpp:124
beast::signum
auto signum(T const &t)
Default implementation of signum calls the method on the class.
Definition:
Zero.h:53
beast::Zero_test::IntegerWrapper::signum
int signum() const
Definition:
beast_Zero_test.cpp:57
beast::Zero_test::test_lhs_zero
void test_lhs_zero(IntegerWrapper x)
Definition:
beast_Zero_test.cpp:70
beast::Zero_test::IntegerWrapper::IntegerWrapper
IntegerWrapper(int v)
Definition:
beast_Zero_test.cpp:52
beast::adl_tester
Definition:
beast_Zero_test.cpp:26
beast::inner_adl_test::signum
int signum(adl_tester2)
Definition:
beast_Zero_test.cpp:38
beast::Zero_test::IntegerWrapper
Definition:
beast_Zero_test.cpp:48
beast::Zero_test::test_rhs_zero
void test_rhs_zero()
Definition:
beast_Zero_test.cpp:114
beast::inner_adl_test::adl_tester2
Definition:
beast_Zero_test.cpp:36
beast::Zero_test::IntegerWrapper::value
int value
Definition:
beast_Zero_test.cpp:50
beast::Zero_test::test_rhs_zero
void test_rhs_zero(IntegerWrapper x)
Definition:
beast_Zero_test.cpp:97
beast::Zero_test::run
void run() override
Definition:
beast_Zero_test.cpp:131
beast::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(aged_set, container, beast)
beast::Zero_test::expect_same
void expect_same(bool result, bool correct, char const *message)
Definition:
beast_Zero_test.cpp:64
beast::Zero_test
Definition:
beast_Zero_test.cpp:45
beast
Definition:
base_uint.h:582
Generated by
1.8.17