xrpld
Loading...
Searching...
No Matches
beast_Zero_test.cpp
1#include <xrpl/beast/unit_test/suite.h>
2#include <xrpl/beast/utility/Zero.h>
3
4namespace beast {
5
7{
8};
9
10int
12{
13 return 0;
14}
15
16namespace inner_adl_test {
17
19{
20};
21
22int
24{
25 return 0;
26}
27
28} // namespace inner_adl_test
29
31{
32private:
34 {
35 int value;
36
38 {
39 }
40
41 [[nodiscard]] int
42 signum() const
43 {
44 return value;
45 }
46 };
47
48public:
49 void
50 expectSame(bool result, bool correct, char const* message)
51 {
52 expect(result == correct, message);
53 }
54
55 void
57 {
58 expectSame(x >= kZero, x.signum() >= 0, "lhs greater-than-or-equal-to");
59 expectSame(x > kZero, x.signum() > 0, "lhs greater than");
60 expectSame(x == kZero, x.signum() == 0, "lhs equal to");
61 expectSame(x != kZero, x.signum() != 0, "lhs not equal to");
62 expectSame(x < kZero, x.signum() < 0, "lhs less than");
63 expectSame(x <= kZero, x.signum() <= 0, "lhs less-than-or-equal-to");
64 }
65
66 void
68 {
69 testcase("lhs zero");
70
71 testLhsZero(-7);
72 testLhsZero(0);
73 testLhsZero(32);
74 }
75
76 void
78 {
79 expectSame(kZero >= x, 0 >= x.signum(), "rhs greater-than-or-equal-to");
80 expectSame(kZero > x, 0 > x.signum(), "rhs greater than");
81 expectSame(kZero == x, 0 == x.signum(), "rhs equal to");
82 expectSame(kZero != x, 0 != x.signum(), "rhs not equal to");
83 expectSame(kZero < x, 0 < x.signum(), "rhs less than");
84 expectSame(kZero <= x, 0 <= x.signum(), "rhs less-than-or-equal-to");
85 }
86
87 void
89 {
90 testcase("rhs zero");
91
92 testRhsZero(-4);
93 testRhsZero(0);
94 testRhsZero(64);
95 }
96
97 void
99 {
100 expect(AdlTester{} == kZero, "ADL failure!");
101 expect(inner_adl_test::AdlTester2{} == kZero, "ADL failure!");
102 }
103
104 void
105 run() override
106 {
107 testLhsZero();
108 testRhsZero();
109 testAdl();
110 }
111};
112
114
115} // namespace beast
void expectSame(bool result, bool correct, char const *message)
void run() override
Runs the suite.
void testRhsZero(IntegerWrapper x)
void testLhsZero(IntegerWrapper x)
A testsuite class.
Definition suite.h:50
bool expect(Condition const &shouldBeTrue)
Evaluate a test condition.
Definition suite.h:223
TestcaseT testcase
Memberspace for declaring test cases.
Definition suite.h:149
auto signum(T const &t)
Default implementation of signum calls the method on the class.
Definition Zero.h:36
BEAST_DEFINE_TESTSUITE(aged_set, beast, beast)
Zero allows classes to offer efficient comparisons to zero.
Definition Zero.h:25