diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/numerics/t_amount.cc | 84 | ||||
-rw-r--r-- | tests/python/numerics/t_amount.py | 66 |
2 files changed, 43 insertions, 107 deletions
diff --git a/tests/numerics/t_amount.cc b/tests/numerics/t_amount.cc index a59ff2ea..002b70b0 100644 --- a/tests/numerics/t_amount.cc +++ b/tests/numerics/t_amount.cc @@ -34,10 +34,10 @@ void AmountTestCase::testConstructors() amount_t x10(x6); amount_t x11(x8); - assertEqual(amount_t(0L), x0); - assertEqual(amount_t(), x0); - assertEqual(amount_t("0"), x0); - assertEqual(amount_t("0.0"), x0); + assertThrow(amount_t(0L) == x0, amount_error); + assertThrow(amount_t() == x0, amount_error); + assertThrow(amount_t("0") == x0, amount_error); + assertThrow(amount_t("0.0") == x0, amount_error); assertEqual(x2, x1); assertEqual(x5, x1); assertEqual(x7, x1); @@ -108,7 +108,6 @@ void AmountTestCase::testCommodityConstructors() void AmountTestCase::testAssignment() { - amount_t x0; amount_t x1 = 123456L; amount_t x2 = 123456UL; amount_t x3 = 123.456; @@ -119,7 +118,6 @@ void AmountTestCase::testAssignment() amount_t x9 = x3; amount_t x10 = amount_t(x6); - assertEqual(amount_t(0L), x0); assertEqual(x2, x1); assertEqual(x5, x1); assertEqual(x7, x1); @@ -128,7 +126,6 @@ void AmountTestCase::testAssignment() assertEqual(x10, x3); assertEqual(x10, x9); - x0 = amount_t(); x1 = 123456L; x2 = 123456UL; x3 = 123.456; @@ -139,7 +136,6 @@ void AmountTestCase::testAssignment() x9 = x3; x10 = amount_t(x6); - assertEqual(amount_t(0L), x0); assertEqual(x2, x1); assertEqual(x5, x1); assertEqual(x7, x1); @@ -148,7 +144,6 @@ void AmountTestCase::testAssignment() assertEqual(x10, x3); assertEqual(x10, x9); - assertTrue(x0.valid()); assertTrue(x1.valid()); assertTrue(x2.valid()); assertTrue(x3.valid()); @@ -246,12 +241,12 @@ void AmountTestCase::testCommodityEquality() amount_t x10 = "-123.45€"; assertTrue(x0.is_null()); - assertTrue(x0.is_zero()); - assertTrue(x0.is_realzero()); - assertTrue(x0.sign() == 0); - assertTrue(x0.compare(x1) < 0); - assertTrue(x0.compare(x2) > 0); - assertTrue(x0.compare(x0) == 0); + assertThrow(x0.is_zero(), amount_error); + assertThrow(x0.is_realzero(), amount_error); + assertThrow(x0.sign() == 0, amount_error); + assertThrow(x0.compare(x1) < 0, amount_error); + assertThrow(x0.compare(x2) > 0, amount_error); + assertThrow(x0.compare(x0) == 0, amount_error); assertTrue(x1 != x2); assertTrue(x1 != x4); @@ -286,12 +281,12 @@ void AmountTestCase::testComparisons() amount_t x5("-123.45"); amount_t x6("123.45"); - assertTrue(x0 > x1); - assertTrue(x0 < x2); - assertTrue(x0 > x3); - assertTrue(x0 < x4); - assertTrue(x0 > x5); - assertTrue(x0 < x6); + assertThrow(x0 > x1, amount_error); + assertThrow(x0 < x2, amount_error); + assertThrow(x0 > x3, amount_error); + assertThrow(x0 < x4, amount_error); + assertThrow(x0 > x5, amount_error); + assertThrow(x0 < x6, amount_error); assertTrue(x1 > x3); assertTrue(x3 <= x5); @@ -317,7 +312,6 @@ void AmountTestCase::testComparisons() void AmountTestCase::testCommodityComparisons() { - amount_t x0; amount_t x1("$-123"); amount_t x2("$123.00"); amount_t x3(internalAmount("$-123.4544")); @@ -325,13 +319,6 @@ void AmountTestCase::testCommodityComparisons() amount_t x5("$-123.45"); amount_t x6("$123.45"); - assertTrue(x0 > x1); - assertTrue(x0 < x2); - assertTrue(x0 > x3); - assertTrue(x0 < x4); - assertTrue(x0 > x5); - assertTrue(x0 < x6); - assertTrue(x1 > x3); assertTrue(x3 <= x5); assertTrue(x3 < x5); @@ -340,7 +327,6 @@ void AmountTestCase::testCommodityComparisons() assertTrue(x3 < x1); assertTrue(x3 < x4); - assertValid(x0); assertValid(x1); assertValid(x2); assertValid(x3); @@ -847,7 +833,6 @@ void AmountTestCase::testCommodityDivision() void AmountTestCase::testNegation() { - amount_t x0; amount_t x1(-123456L); amount_t x3(-123.456); amount_t x5("-123456"); @@ -856,7 +841,6 @@ void AmountTestCase::testNegation() amount_t x8(string("-123.456")); amount_t x9(- x3); - assertEqual(amount_t(0L), x0); assertEqual(x5, x1); assertEqual(x7, x1); assertEqual(x6, x3); @@ -868,7 +852,6 @@ void AmountTestCase::testNegation() assertEqual(x3, x10); - assertTrue(x0.valid()); assertTrue(x1.valid()); assertTrue(x3.valid()); assertTrue(x5.valid()); @@ -940,7 +923,7 @@ void AmountTestCase::testAbs() amount_t x1(-1234L); amount_t x2(1234L); - assertEqual(amount_t(), x0.abs()); + assertThrow(x0.abs(), amount_error); assertEqual(amount_t(1234L), x1.abs()); assertEqual(amount_t(1234L), x2.abs()); @@ -951,15 +934,12 @@ void AmountTestCase::testAbs() void AmountTestCase::testCommodityAbs() { - amount_t x0; amount_t x1("$-1234.56"); amount_t x2("$1234.56"); - assertEqual(amount_t(), x0.abs()); assertEqual(amount_t("$1234.56"), x1.abs()); assertEqual(amount_t("$1234.56"), x2.abs()); - assertValid(x0); assertValid(x1); assertValid(x2); } @@ -1010,7 +990,7 @@ void AmountTestCase::testFractionalRound() assertEqual(amount_t("0.0000000000000000000000000000000000001"), x5.round(37)); - assertEqual(amount_t(), x5.round(36)); + assertEqual(amount_t(0L), x5.round(36)); assertTrue(x1.valid()); assertTrue(x2.valid()); @@ -1127,7 +1107,7 @@ void AmountTestCase::testSign() amount_t x3("1"); amount_t x4("-1"); - assertEqual(x0.sign(), 0); + assertThrow(x0.sign(), amount_error); assertTrue(x1.sign() > 0); assertTrue(x2.sign() < 0); assertTrue(x3.sign() > 0); @@ -1142,19 +1122,16 @@ void AmountTestCase::testSign() void AmountTestCase::testCommoditySign() { - amount_t x0; amount_t x1(internalAmount("$0.0000000000000000000000000000000000001")); amount_t x2(internalAmount("$-0.0000000000000000000000000000000000001")); amount_t x3("$1"); amount_t x4("$-1"); - assertFalse(x0.sign()); assertTrue(x1.sign() != 0); assertTrue(x2.sign() != 0); assertTrue(x3.sign() > 0); assertTrue(x4.sign() < 0); - assertValid(x0); assertValid(x1); assertValid(x2); assertValid(x3); @@ -1167,10 +1144,7 @@ void AmountTestCase::testTruth() amount_t x1("1234"); amount_t x2("1234.56"); - if (x0) - assertTrue(false); - else - assertTrue(true); + assertThrow(x0 ? 1 : 0, amount_error); assertTrue(x1); assertTrue(x2); @@ -1204,10 +1178,9 @@ void AmountTestCase::testForZero() amount_t x0; amount_t x1("0.000000000000000000001"); - assertFalse(x0); assertTrue(x1); - assertTrue(x0.is_zero()); - assertTrue(x0.is_realzero()); + assertThrow(x0.is_zero(), amount_error); + assertThrow(x0.is_realzero(), amount_error); assertFalse(x1.is_zero()); assertFalse(x1.is_realzero()); @@ -1271,9 +1244,7 @@ void AmountTestCase::testPrinting() { std::ostringstream bufstr; - bufstr << x0; - - assertEqual(std::string("0"), bufstr.str()); + assertThrow(bufstr << x0, amount_error); } { @@ -1290,19 +1261,11 @@ void AmountTestCase::testPrinting() void AmountTestCase::testCommodityPrinting() { - amount_t x0; amount_t x1(internalAmount("$982340823.386238098235098235098235098")); amount_t x2("$982340823.38"); { std::ostringstream bufstr; - bufstr << x0; - - assertEqual(std::string("0"), bufstr.str()); - } - - { - std::ostringstream bufstr; bufstr << x1; assertEqual(std::string("$982340823.386238098235098235098235098"), @@ -1324,7 +1287,6 @@ void AmountTestCase::testCommodityPrinting() assertEqual(std::string("$964993493285024293.18"), bufstr.str()); } - assertValid(x0); assertValid(x1); assertValid(x2); } diff --git a/tests/python/numerics/t_amount.py b/tests/python/numerics/t_amount.py index dd87b2cd..bde8eae1 100644 --- a/tests/python/numerics/t_amount.py +++ b/tests/python/numerics/t_amount.py @@ -33,10 +33,10 @@ class AmountTestCase(unittest.TestCase): x9 = amount(x3) x10 = amount(x6) - self.assertEqual(amount(0), x0) - self.assertEqual(amount(), x0) - self.assertEqual(amount("0"), x0) - self.assertEqual(amount("0.0"), x0) + self.assertRaises(exceptions.ArithmeticError, operator.eq, amount(0), x0) + self.assertRaises(exceptions.ArithmeticError, operator.eq, amount(), x0) + self.assertRaises(exceptions.ArithmeticError, operator.eq, amount("0"), x0) + self.assertRaises(exceptions.ArithmeticError, operator.eq, amount("0.0"), x0) self.assertEqual(x2, x1) self.assertEqual(x5, x1) self.assertEqual(x6, x3) @@ -98,7 +98,6 @@ class AmountTestCase(unittest.TestCase): self.assertValid(x10) def testAssignment(self): - x0 = amount() x1 = amount(123456) x2 = amount(123456L) x3 = amount(123.456) @@ -107,14 +106,12 @@ class AmountTestCase(unittest.TestCase): x9 = x3 x10 = amount(x6) - self.assertEqual(amount(0), x0) self.assertEqual(x2, x1) self.assertEqual(x5, x1) self.assertEqual(x6, x3) self.assertEqual(x10, x3) self.assertEqual(x10, x9) - x0 = amount() x1 = amount(123456) x2 = amount(123456L) x3 = amount(123.456) @@ -123,14 +120,12 @@ class AmountTestCase(unittest.TestCase): x9 = x3 x10 = amount(x6) - self.assertEqual(amount(0), x0) self.assertEqual(x2, x1) self.assertEqual(x5, x1) self.assertEqual(x6, x3) self.assertEqual(x10, x3) self.assertEqual(x10, x9) - self.assertValid(x0) self.assertValid(x1) self.assertValid(x2) self.assertValid(x3) @@ -217,12 +212,10 @@ class AmountTestCase(unittest.TestCase): x10 = amount("-123.45€") self.assertTrue(x0.is_null()) - self.assertTrue(x0.is_zero()) - self.assertTrue(x0.is_realzero()) - self.assertTrue(x0.sign() == 0) - self.assertTrue(x0.compare(x1) < 0) - self.assertTrue(x0.compare(x2) > 0) - self.assertTrue(x0.compare(x0) == 0) + self.assertRaises(exceptions.ArithmeticError, amount.is_zero, x0) + self.assertRaises(exceptions.ArithmeticError, amount.is_realzero, x0) + self.assertRaises(exceptions.ArithmeticError, amount.sign, x0) + self.assertRaises(exceptions.ArithmeticError, amount.compare, x0, 0) self.assertTrue(x1 != x2) self.assertTrue(x1 != x4) @@ -255,12 +248,12 @@ class AmountTestCase(unittest.TestCase): x5 = amount("-123.45") x6 = amount("123.45") - self.assertTrue(x0 > x1) - self.assertTrue(x0 < x2) - self.assertTrue(x0 > x3) - self.assertTrue(x0 < x4) - self.assertTrue(x0 > x5) - self.assertTrue(x0 < x6) + self.assertRaises(exceptions.ArithmeticError, operator.gt, x0, x1) + self.assertRaises(exceptions.ArithmeticError, operator.lt, x0, x2) + self.assertRaises(exceptions.ArithmeticError, operator.gt, x0, x3) + self.assertRaises(exceptions.ArithmeticError, operator.lt, x0, x4) + self.assertRaises(exceptions.ArithmeticError, operator.gt, x0, x5) + self.assertRaises(exceptions.ArithmeticError, operator.lt, x0, x6) self.assertTrue(x1 > x3) self.assertTrue(x3 <= x5) @@ -284,7 +277,6 @@ class AmountTestCase(unittest.TestCase): self.assertValid(x6) def testCommodityComparisons(self): - x0 = amount() x1 = amount("$-123") x2 = amount("$123.00") x3 = amount(internalAmount("$-123.4544")) @@ -292,13 +284,6 @@ class AmountTestCase(unittest.TestCase): x5 = amount("$-123.45") x6 = amount("$123.45") - self.assertTrue(x0 > x1) - self.assertTrue(x0 < x2) - self.assertTrue(x0 > x3) - self.assertTrue(x0 < x4) - self.assertTrue(x0 > x5) - self.assertTrue(x0 < x6) - self.assertTrue(x1 > x3) self.assertTrue(x3 <= x5) self.assertTrue(x3 < x5) @@ -307,7 +292,6 @@ class AmountTestCase(unittest.TestCase): self.assertTrue(x3 < x1) self.assertTrue(x3 < x4) - self.assertValid(x0) self.assertValid(x1) self.assertValid(x2) self.assertValid(x3) @@ -792,14 +776,12 @@ class AmountTestCase(unittest.TestCase): self.assertValid(x7) def testNegation(self): - x0 = amount() x1 = amount(-123456) x3 = amount(-123.456) x5 = amount("-123456") x6 = amount("-123.456") x9 = amount(- x3) - self.assertEqual(amount(0), x0) self.assertEqual(x5, x1) self.assertEqual(x6, x3) self.assertEqual(- x6, x9) @@ -809,7 +791,6 @@ class AmountTestCase(unittest.TestCase): self.assertEqual(x3, x10) - self.assertValid(x0) self.assertValid(x1) self.assertValid(x3) self.assertValid(x5) @@ -875,7 +856,7 @@ class AmountTestCase(unittest.TestCase): x1 = amount(-1234) x2 = amount(1234) - self.assertEqual(amount(), abs(x0)) + self.assertRaises(exceptions.ArithmeticError, amount.abs, x0) self.assertEqual(amount(1234), abs(x1)) self.assertEqual(amount(1234), abs(x2)) @@ -884,15 +865,12 @@ class AmountTestCase(unittest.TestCase): self.assertValid(x2) def testCommodityAbs(self): - x0 = amount() x1 = amount("$-1234.56") x2 = amount("$1234.56") - self.assertEqual(amount(), abs(x0)) self.assertEqual(amount("$1234.56"), abs(x1)) self.assertEqual(amount("$1234.56"), abs(x2)) - self.assertValid(x0) self.assertValid(x1) self.assertValid(x2) @@ -941,7 +919,7 @@ class AmountTestCase(unittest.TestCase): self.assertEqual(amount("0.0000000000000000000000000000000000001"), x5.round(37)) - self.assertEqual(amount(), x5.round(36)) + self.assertEqual(amount(0), x5.round(36)) self.assertValid(x1) self.assertValid(x2) @@ -1050,7 +1028,7 @@ class AmountTestCase(unittest.TestCase): x3 = amount("1") x4 = amount("-1") - self.assertEqual(x0.sign(), 0) + self.assertRaises(exceptions.ArithmeticError, amount.sign, x0) self.assertTrue(x1.sign() > 0) self.assertTrue(x2.sign() < 0) self.assertTrue(x3.sign() > 0) @@ -1063,19 +1041,16 @@ class AmountTestCase(unittest.TestCase): self.assertValid(x4) def testCommoditySign(self): - x0 = amount() x1 = amount(internalAmount("$0.0000000000000000000000000000000000001")) x2 = amount(internalAmount("$-0.0000000000000000000000000000000000001")) x3 = amount("$1") x4 = amount("$-1") - self.assertFalse(x0.sign()) self.assertTrue(x1.sign() != 0) self.assertTrue(x2.sign() != 0) self.assertTrue(x3.sign() > 0) self.assertTrue(x4.sign() < 0) - self.assertValid(x0) self.assertValid(x1) self.assertValid(x2) self.assertValid(x3) @@ -1086,7 +1061,7 @@ class AmountTestCase(unittest.TestCase): x1 = amount("1234") x2 = amount("1234.56") - self.assertFalse(x0) + self.assertRaises(exceptions.ArithmeticError, operator.truth, x0) self.assertTrue(x1) self.assertTrue(x2) @@ -1115,10 +1090,9 @@ class AmountTestCase(unittest.TestCase): x0 = amount() x1 = amount("0.000000000000000000001") - self.assertFalse(x0) self.assertTrue(x1) - self.assertTrue(x0.is_zero()) - self.assertTrue(x0.is_realzero()) + self.assertRaises(exceptions.ArithmeticError, amount.is_zero, x0) + self.assertRaises(exceptions.ArithmeticError, amount.is_realzero, x0) self.assertFalse(x1.is_zero()) self.assertFalse(x1.is_realzero()) |