1#include <xrpl/basics/tagged_integer.h>
3#include <gtest/gtest.h>
26 "TagUInt1 should be constructible using a std::uint32_t");
30 "TagUInt1 should not be constructible using a std::uint64_t");
34 "TagUInt3 should be constructible using a std::uint32_t");
38 "TagUInt3 should be constructible using a std::uint64_t");
43 "TagUInt1 should not be assignable with a std::uint32_t");
47 "TagUInt1 should not be assignable with a std::uint64_t");
51 "TagUInt3 should not be assignable with a std::uint32_t");
55 "TagUInt3 should not be assignable with a std::uint64_t");
59 "TagUInt1 should be assignable with a TagUInt1");
63 "TagUInt1 should not be assignable with a TagUInt2");
67 "TagUInt3 should be assignable with a TagUInt1");
71 "TagUInt1 should not be assignable with a TagUInt3");
75 "TagUInt3 should not be assignable with a TagUInt1");
80 "std::uint32_t should not be convertible to a TagUInt1");
84 "std::uint32_t should not be convertible to a TagUInt3");
88 "std::uint64_t should not be convertible to a TagUInt3");
92 "std::uint64_t should not be convertible to a TagUInt2");
96 "TagUInt1 should not be convertible to TagUInt2");
100 "TagUInt1 should not be convertible to TagUInt3");
104 "TagUInt2 should not be convertible to a TagUInt3");
108TEST(tagged_integer, comparison_operators)
110 TagInt
const zero(0);
113 EXPECT_TRUE(one == one);
114 EXPECT_FALSE(one == zero);
116 EXPECT_TRUE(one != zero);
117 EXPECT_FALSE(one != one);
119 EXPECT_TRUE(zero < one);
120 EXPECT_FALSE(one < zero);
122 EXPECT_TRUE(one > zero);
123 EXPECT_FALSE(zero > one);
125 EXPECT_TRUE(one >= one);
126 EXPECT_TRUE(one >= zero);
127 EXPECT_FALSE(zero >= one);
129 EXPECT_TRUE(zero <= one);
130 EXPECT_TRUE(zero <= zero);
131 EXPECT_FALSE(one <= zero);
134TEST(tagged_integer, increment_decrement_operators)
136 TagInt
const zero(0);
149TEST(tagged_integer, arithmetic_operators)
152 EXPECT_EQ(+a, TagInt{-2});
153 EXPECT_EQ(-a, TagInt{2});
154 EXPECT_EQ(TagInt{-3} + TagInt{4}, TagInt{1});
155 EXPECT_EQ(TagInt{-3} - TagInt{4}, TagInt{-7});
156 EXPECT_EQ(TagInt{-3} * TagInt{4}, TagInt{-12});
157 EXPECT_EQ(TagInt{8} / TagInt{4}, TagInt{2});
158 EXPECT_EQ(TagInt{7} % TagInt{4}, TagInt{3});
160 EXPECT_EQ(~TagInt{8}, TagInt{~TagInt::value_type{8}});
161 EXPECT_EQ((TagInt{6} & TagInt{3}), TagInt{2});
162 EXPECT_EQ((TagInt{6} | TagInt{3}), TagInt{7});
163 EXPECT_EQ((TagInt{6} ^ TagInt{3}), TagInt{5});
165 EXPECT_EQ((TagInt{4} << TagInt{2}), TagInt{16});
166 EXPECT_EQ((TagInt{16} >> TagInt{2}), TagInt{4});
169TEST(tagged_integer, assignment_operators)
174 EXPECT_EQ(b, TagInt{-2});
179 EXPECT_EQ(a, TagInt{1});
184 EXPECT_EQ(a, TagInt{-7});
189 EXPECT_EQ(a, TagInt{-12});
194 EXPECT_EQ(a, TagInt{2});
199 EXPECT_EQ(a, TagInt{3});
204 EXPECT_EQ(a, TagInt{2});
209 EXPECT_EQ(a, TagInt{7});
214 EXPECT_EQ(a, TagInt{5});
219 EXPECT_EQ(a, TagInt{16});
224 EXPECT_EQ(a, TagInt{4});
A type-safe wrap around standard integral types.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.