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/unit_test.h>
21#include <xrpl/beast/utility/Zero.h>
22
23namespace beast {
24
26{
27};
28
29int
31{
32 return 0;
33}
34
35namespace inner_adl_test {
36
38{
39};
40
41int
43{
44 return 0;
45}
46
47} // namespace inner_adl_test
48
50{
51private:
53 {
54 int value;
55
57 {
58 }
59
60 int
61 signum() const
62 {
63 return value;
64 }
65 };
66
67public:
68 void
69 expect_same(bool result, bool correct, char const* message)
70 {
71 expect(result == correct, message);
72 }
73
74 void
76 {
77 expect_same(x >= zero, x.signum() >= 0, "lhs greater-than-or-equal-to");
78 expect_same(x > zero, x.signum() > 0, "lhs greater than");
79 expect_same(x == zero, x.signum() == 0, "lhs equal to");
80 expect_same(x != zero, x.signum() != 0, "lhs not equal to");
81 expect_same(x < zero, x.signum() < 0, "lhs less than");
82 expect_same(x <= zero, x.signum() <= 0, "lhs less-than-or-equal-to");
83 }
84
85 void
87 {
88 testcase("lhs zero");
89
90 test_lhs_zero(-7);
92 test_lhs_zero(32);
93 }
94
95 void
97 {
98 expect_same(zero >= x, 0 >= x.signum(), "rhs greater-than-or-equal-to");
99 expect_same(zero > x, 0 > x.signum(), "rhs greater than");
100 expect_same(zero == x, 0 == x.signum(), "rhs equal to");
101 expect_same(zero != x, 0 != x.signum(), "rhs not equal to");
102 expect_same(zero < x, 0 < x.signum(), "rhs less than");
103 expect_same(zero <= x, 0 <= x.signum(), "rhs less-than-or-equal-to");
104 }
105
106 void
108 {
109 testcase("rhs zero");
110
111 test_rhs_zero(-4);
112 test_rhs_zero(0);
113 test_rhs_zero(64);
114 }
115
116 void
118 {
119 expect(adl_tester{} == zero, "ADL failure!");
120 expect(inner_adl_test::adl_tester2{} == zero, "ADL failure!");
121 }
122
123 void
124 run() override
125 {
128 test_adl();
129 }
130};
131
132BEAST_DEFINE_TESTSUITE(Zero, beast, beast);
133
134} // 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:55
testcase_t testcase
Memberspace for declaring test cases.
Definition suite.h:155
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:229
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