20 #include <ripple/basics/IOUAmount.h>
21 #include <ripple/beast/unit_test.h>
37 BEAST_EXPECT(z.
signum () == 0);
38 BEAST_EXPECT(z == beast::zero);
40 BEAST_EXPECT((z + z) == z);
41 BEAST_EXPECT((z - z) == z);
42 BEAST_EXPECT(z == -z);
45 BEAST_EXPECT(z == zz);
53 BEAST_EXPECT(neg.
signum () < 0);
56 BEAST_EXPECT(zer.
signum () == 0);
59 BEAST_EXPECT(pos.
signum () > 0);
64 testcase (
"beast::Zero Comparisons");
70 BEAST_EXPECT(z == zero);
71 BEAST_EXPECT(z >= zero);
72 BEAST_EXPECT(z <= zero);
73 unexpected (z != zero);
74 unexpected (z > zero);
75 unexpected (z < zero);
80 BEAST_EXPECT(neg < zero);
81 BEAST_EXPECT(neg <= zero);
82 BEAST_EXPECT(neg != zero);
83 unexpected (neg == zero);
88 BEAST_EXPECT(pos > zero);
89 BEAST_EXPECT(pos >= zero);
90 BEAST_EXPECT(pos != zero);
91 unexpected (pos == zero);
97 testcase (
"IOU Comparisons");
103 BEAST_EXPECT(z == z);
104 BEAST_EXPECT(z >= z);
105 BEAST_EXPECT(z <= z);
106 BEAST_EXPECT(z == -z);
110 unexpected (z != -z);
113 BEAST_EXPECT(n <= z);
114 BEAST_EXPECT(n != z);
120 BEAST_EXPECT(p >= z);
121 BEAST_EXPECT(p != z);
127 BEAST_EXPECT(n <= p);
128 BEAST_EXPECT(n != p);
134 BEAST_EXPECT(p >= n);
135 BEAST_EXPECT(p != n);
140 BEAST_EXPECT(p > -p);
141 BEAST_EXPECT(p >= -p);
142 BEAST_EXPECT(p != -p);
144 BEAST_EXPECT(n < -n);
145 BEAST_EXPECT(n <= -n);
146 BEAST_EXPECT(n != -n);
151 testcase(
"IOU strings");
166 testcase (
"mulRatio");
181 BEAST_EXPECT(bigMan ==
mulRatio (bigMan, maxUInt, maxUInt,
true));
183 BEAST_EXPECT(bigMan ==
mulRatio (bigMan, maxUInt, maxUInt,
false));
188 BEAST_EXPECT(bigMan ==
mulRatio (bigMan, maxUInt, maxUInt,
true));
190 BEAST_EXPECT(bigMan ==
mulRatio (bigMan, maxUInt, maxUInt,
false));
197 BEAST_EXPECT(tiny ==
mulRatio (tiny, 1, maxUInt,
true));
198 BEAST_EXPECT(tiny ==
mulRatio (tiny, maxUInt - 1, maxUInt,
true));
200 BEAST_EXPECT(beast::zero ==
mulRatio (tiny, 1, maxUInt,
false));
201 BEAST_EXPECT(beast::zero ==
mulRatio (tiny, maxUInt - 1, maxUInt,
false));
206 BEAST_EXPECT(beast::zero ==
mulRatio (tinyNeg, 1, maxUInt,
true));
207 BEAST_EXPECT(beast::zero ==
mulRatio (tinyNeg, maxUInt - 1, maxUInt,
true));
209 BEAST_EXPECT(tinyNeg ==
mulRatio (tinyNeg, 1, maxUInt,
false));
210 BEAST_EXPECT(tinyNeg ==
mulRatio (tinyNeg, maxUInt - 1, maxUInt,
false));
217 auto const rup =
mulRatio (one, maxUInt - 1, maxUInt,
true);
218 auto const rdown =
mulRatio (one, maxUInt - 1, maxUInt,
false);
219 BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
223 auto const rup =
mulRatio (big, maxUInt - 1, maxUInt,
true);
224 auto const rdown =
mulRatio (big, maxUInt - 1, maxUInt,
false);
225 BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
230 auto const rup =
mulRatio (negOne, maxUInt - 1, maxUInt,
true);
231 auto const rdown =
mulRatio (negOne, maxUInt - 1, maxUInt,
false);
232 BEAST_EXPECT(rup.mantissa () - rdown.mantissa () == 1);
239 except ([&] {
mulRatio (one, 1, 0,
true);});
245 except ([&] {
mulRatio (big, 2, 0,
true);});