21 #include <ripple/basics/tagged_integer.h>
22 #include <ripple/beast/unit_test.h>
47 "TagUInt1 should be constructible using a std::uint32_t");
51 "TagUInt1 should not be constructible using a std::uint64_t");
55 "TagUInt3 should be constructible using a std::uint32_t");
59 "TagUInt3 should be constructible using a std::uint64_t");
64 "TagUInt1 should not be assignable with a std::uint32_t");
68 "TagUInt1 should not be assignable with a std::uint64_t");
72 "TagUInt3 should not be assignable with a std::uint32_t");
76 "TagUInt3 should not be assignable with a std::uint64_t");
80 "TagUInt1 should be assignable with a TagUInt1");
84 "TagUInt1 should not be assignable with a TagUInt2");
88 "TagUInt3 should be assignable with a TagUInt1");
92 "TagUInt1 should not be assignable with a TagUInt3");
96 "TagUInt3 should not be assignable with a TagUInt1");
101 "std::uint32_t should not be convertible to a TagUInt1");
105 "std::uint32_t should not be convertible to a TagUInt3");
109 "std::uint64_t should not be convertible to a TagUInt3");
113 "std::uint64_t should not be convertible to a TagUInt2");
117 "TagUInt1 should not be convertible to TagUInt2");
121 "TagUInt1 should not be convertible to TagUInt3");
125 "TagUInt2 should not be convertible to a TagUInt3");
134 testcase(
"Comparison Operators");
136 TagInt
const zero(0);
140 BEAST_EXPECT(!(
one == zero));
142 BEAST_EXPECT(
one != zero);
143 BEAST_EXPECT(!(
one !=
one));
145 BEAST_EXPECT(zero <
one);
146 BEAST_EXPECT(!(
one < zero));
148 BEAST_EXPECT(
one > zero);
149 BEAST_EXPECT(!(zero >
one));
152 BEAST_EXPECT(
one >= zero);
153 BEAST_EXPECT(!(zero >=
one));
155 BEAST_EXPECT(zero <=
one);
156 BEAST_EXPECT(zero <= zero);
157 BEAST_EXPECT(!(
one <= zero));
161 testcase(
"Increment/Decrement Operators");
162 TagInt
const zero(0);
166 BEAST_EXPECT(a ==
one);
168 BEAST_EXPECT(a == zero);
170 BEAST_EXPECT(a ==
one);
172 BEAST_EXPECT(a == zero);
176 testcase(
"Arithmetic Operators");
178 BEAST_EXPECT(+a == TagInt{-2});
179 BEAST_EXPECT(-a == TagInt{2});
180 BEAST_EXPECT(TagInt{-3} + TagInt{4} == TagInt{1});
181 BEAST_EXPECT(TagInt{-3} - TagInt{4} == TagInt{-7});
182 BEAST_EXPECT(TagInt{-3} * TagInt{4} == TagInt{-12});
183 BEAST_EXPECT(TagInt{8} / TagInt{4} == TagInt{2});
184 BEAST_EXPECT(TagInt{7} % TagInt{4} == TagInt{3});
186 BEAST_EXPECT(~TagInt{8} == TagInt{~TagInt::value_type{8}});
187 BEAST_EXPECT((TagInt{6} & TagInt{3}) == TagInt{2});
188 BEAST_EXPECT((TagInt{6} | TagInt{3}) == TagInt{7});
189 BEAST_EXPECT((TagInt{6} ^ TagInt{3}) == TagInt{5});
191 BEAST_EXPECT((TagInt{4} << TagInt{2}) == TagInt{16});
192 BEAST_EXPECT((TagInt{16} >> TagInt{2}) == TagInt{4});
195 testcase(
"Assignment Operators");
199 BEAST_EXPECT(b == TagInt{-2});
204 BEAST_EXPECT(a == TagInt{1});
209 BEAST_EXPECT(a == TagInt{-7});
214 BEAST_EXPECT(a == TagInt{-12});
219 BEAST_EXPECT(a == TagInt{2});
224 BEAST_EXPECT(a == TagInt{3});
229 BEAST_EXPECT(a == TagInt{2});
234 BEAST_EXPECT(a == TagInt{7});
239 BEAST_EXPECT(a == TagInt{5});
244 BEAST_EXPECT(a == TagInt{16});
249 BEAST_EXPECT(a == TagInt{4});