|
|
@@ -89,8 +89,19 @@ TEST(BigDecimalTest, SubtractionNormalizeScaleToHighest) {
|
|
|
|
|
|
struct ArithTuple { math::bigdecimal lhs, rhs; std::string expected; };
|
|
|
struct BigDecPair { math::bigdecimal lhs, rhs; };
|
|
|
+void PrintTo(math::bigdecimal const & dec, std::ostream * out) {
|
|
|
+ (*out) << dec.to_string() << "(" << dec.scale() << ")";
|
|
|
+}
|
|
|
+std::ostream & operator<<(std::ostream & out, math::bigdecimal const & dec) {
|
|
|
+ PrintTo(dec, &out);
|
|
|
+ return out;
|
|
|
+}
|
|
|
void PrintTo(BigDecPair const & tup, std::ostream * out) {
|
|
|
- (*out) << "{ lhs = " << tup.lhs.to_string() << "(" << tup.lhs.scale() << "), rhs = " << tup.rhs.to_string() << "(" << tup.rhs.scale() << ") }";
|
|
|
+ (*out) << "{ lhs = ";
|
|
|
+ PrintTo(tup.lhs, out);
|
|
|
+ (*out) << ", rhs = ";
|
|
|
+ PrintTo(tup.rhs, out);
|
|
|
+ (*out) << " }";
|
|
|
}
|
|
|
|
|
|
class MultiplicationScaleTest : public testing::TestWithParam<ArithTuple> {};
|
|
|
@@ -114,7 +125,15 @@ TEST_P(DivisionScaleTest, ScaleIsDifferenceOfNumAndDenomScales) {
|
|
|
class EqTest : public testing::TestWithParam<BigDecPair> {};
|
|
|
|
|
|
TEST_P(EqTest, DecimalsAreEqualEvenIfScalesAreNot) {
|
|
|
- EXPECT_THAT(GetParam().lhs, GetParam().rhs);
|
|
|
+ auto pair = GetParam();
|
|
|
+ EXPECT_THAT(pair.lhs, pair.rhs);
|
|
|
+}
|
|
|
+
|
|
|
+class DecimalLtTest : public testing::TestWithParam<BigDecPair> {};
|
|
|
+
|
|
|
+TEST_P(DecimalLtTest, IsLessThanEvenWithDifferentScales) {
|
|
|
+ auto pair = GetParam();
|
|
|
+ EXPECT_THAT(pair.lhs, testing::Lt(pair.rhs));
|
|
|
}
|
|
|
|
|
|
#pragma clang diagnostic push
|
|
|
@@ -151,4 +170,9 @@ INSTANTIATE_TEST_CASE_P(BigDecimal, EqTest,
|
|
|
BigDecPair{{1000000000, -4}, {1000000000, -9}},
|
|
|
BigDecPair{{"0.1", 1}, {"0.10", 2}}));
|
|
|
|
|
|
+INSTANTIATE_TEST_CASE_P(BigDecimal, DecimalLtTest,
|
|
|
+ testing::Values(BigDecPair{{ 0, 0}, { 1, 4}} ,
|
|
|
+ BigDecPair{{ 0, 4}, { 1, 0}},
|
|
|
+ BigDecPair{{ 0, 4}, { 1, 4}}));
|
|
|
+
|
|
|
#pragma clang diagnostic pop
|