rippled
Loading...
Searching...
No Matches
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 <xrpl/beast/utility/Zero.h>
21
22#include <xrpl/beast/unit_test.h>
23
24namespace beast {
25
27{
28};
29
30int
32{
33 return 0;
34}
35
36namespace inner_adl_test {
37
39{
40};
41
42int
44{
45 return 0;
46}
47
48} // namespace inner_adl_test
49
51{
52private:
54 {
55 int value;
56
58 {
59 }
60
61 int
62 signum() const
63 {
64 return value;
65 }
66 };
67
68public:
69 void
70 expect_same(bool result, bool correct, char const* message)
71 {
72 expect(result == correct, message);
73 }
74
75 void
77 {
78 expect_same(x >= zero, x.signum() >= 0, "lhs greater-than-or-equal-to");
79 expect_same(x > zero, x.signum() > 0, "lhs greater than");
80 expect_same(x == zero, x.signum() == 0, "lhs equal to");
81 expect_same(x != zero, x.signum() != 0, "lhs not equal to");
82 expect_same(x < zero, x.signum() < 0, "lhs less than");
83 expect_same(x <= zero, x.signum() <= 0, "lhs less-than-or-equal-to");
84 }
85
86 void
88 {
89 testcase("lhs zero");
90
91 test_lhs_zero(-7);
93 test_lhs_zero(32);
94 }
95
96 void
98 {
99 expect_same(zero >= x, 0 >= x.signum(), "rhs greater-than-or-equal-to");
100 expect_same(zero > x, 0 > x.signum(), "rhs greater than");
101 expect_same(zero == x, 0 == x.signum(), "rhs equal to");
102 expect_same(zero != x, 0 != x.signum(), "rhs not equal to");
103 expect_same(zero < x, 0 < x.signum(), "rhs less than");
104 expect_same(zero <= x, 0 <= x.signum(), "rhs less-than-or-equal-to");
105 }
106
107 void
109 {
110 testcase("rhs zero");
111
112 test_rhs_zero(-4);
113 test_rhs_zero(0);
114 test_rhs_zero(64);
115 }
116
117 void
119 {
120 expect(adl_tester{} == zero, "ADL failure!");
121 expect(inner_adl_test::adl_tester2{} == zero, "ADL failure!");
122 }
123
124 void
125 run() override
126 {
129 test_adl();
130 }
131};
132
133BEAST_DEFINE_TESTSUITE(Zero, types, beast);
134
135} // namespace beast
void expect_same(bool result, bool correct, char const *message)
void test_lhs_zero(IntegerWrapper x)
void run() override
Runs the suite.
void test_rhs_zero(IntegerWrapper x)
A testsuite class.
Definition: suite.h:53
testcase_t testcase
Memberspace for declaring test cases.
Definition: suite.h:153
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition: suite.h:227
int signum(adl_tester2)
auto signum(T const &t)
Default implementation of signum calls the method on the class.
Definition: Zero.h:54
Zero allows classes to offer efficient comparisons to zero.
Definition: Zero.h:43