summaryrefslogtreecommitdiff
path: root/tests/numerics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/numerics')
-rw-r--r--tests/numerics/BasicAmount.cc248
-rw-r--r--tests/numerics/BasicAmount.h28
2 files changed, 138 insertions, 138 deletions
diff --git a/tests/numerics/BasicAmount.cc b/tests/numerics/BasicAmount.cc
index 6ce39d1d..c1a1f0fa 100644
--- a/tests/numerics/BasicAmount.cc
+++ b/tests/numerics/BasicAmount.cc
@@ -48,40 +48,6 @@ void BasicAmountTestCase::testConstructors()
CPPUNIT_ASSERT(x11.valid());
}
-void BasicAmountTestCase::testNegation()
-{
- amount_t x0;
- amount_t x1(-123456L);
- amount_t x3(-123.456);
- amount_t x5("-123456");
- amount_t x6("-123.456");
- amount_t x7(std::string("-123456"));
- amount_t x8(std::string("-123.456"));
- amount_t x9(- x3);
-
- assertEqual(amount_t(0L), x0);
- assertEqual(x5, x1);
- assertEqual(x7, x1);
- assertEqual(x6, x3);
- assertEqual(x8, x3);
- assertEqual(- x6, x9);
- assertEqual(x3.negate(), x9);
-
- amount_t x10(x9.negate());
-
- assertEqual(x3, x10);
-
- CPPUNIT_ASSERT(x0.valid());
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(x3.valid());
- CPPUNIT_ASSERT(x5.valid());
- CPPUNIT_ASSERT(x6.valid());
- CPPUNIT_ASSERT(x7.valid());
- CPPUNIT_ASSERT(x8.valid());
- CPPUNIT_ASSERT(x9.valid());
- CPPUNIT_ASSERT(x10.valid());
-}
-
void BasicAmountTestCase::testAssignment()
{
amount_t x0;
@@ -160,6 +126,38 @@ void BasicAmountTestCase::testEquality()
CPPUNIT_ASSERT(x6.valid());
}
+void BasicAmountTestCase::testComparisons()
+{
+ amount_t x0;
+ amount_t x1(-123L);
+ amount_t x2(123L);
+ amount_t x3(-123.45);
+ amount_t x4(123.45);
+ amount_t x5("-123.45");
+ amount_t x6("123.45");
+
+ CPPUNIT_ASSERT(x0 > x1);
+ CPPUNIT_ASSERT(x0 < x2);
+ CPPUNIT_ASSERT(x0 > x3);
+ CPPUNIT_ASSERT(x0 < x4);
+ CPPUNIT_ASSERT(x0 > x5);
+ CPPUNIT_ASSERT(x0 < x6);
+
+ CPPUNIT_ASSERT(x1 > x3);
+ CPPUNIT_ASSERT(x3 <= x5);
+ CPPUNIT_ASSERT(x3 >= x5);
+ CPPUNIT_ASSERT(x3 < x1);
+ CPPUNIT_ASSERT(x3 < x4);
+
+ CPPUNIT_ASSERT(x0.valid());
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(x2.valid());
+ CPPUNIT_ASSERT(x3.valid());
+ CPPUNIT_ASSERT(x4.valid());
+ CPPUNIT_ASSERT(x5.valid());
+ CPPUNIT_ASSERT(x6.valid());
+}
+
void BasicAmountTestCase::testIntegerAddition()
{
amount_t x1(123L);
@@ -410,30 +408,53 @@ void BasicAmountTestCase::testFractionalDivision()
CPPUNIT_ASSERT(y4.valid());
}
-void BasicAmountTestCase::testIntegerConversion()
+void BasicAmountTestCase::testNegation()
{
- amount_t x1(123456L);
+ amount_t x0;
+ amount_t x1(-123456L);
+ amount_t x3(-123.456);
+ amount_t x5("-123456");
+ amount_t x6("-123.456");
+ amount_t x7(std::string("-123456"));
+ amount_t x8(std::string("-123.456"));
+ amount_t x9(- x3);
- assertEqual(true, bool(x1));
- assertEqual(123456L, x1.to_long());
- assertEqual(123456.0, x1.to_double());
- assertEqual(string("123456"), x1.to_string());
- assertEqual(string("123456"), x1.quantity_string());
+ assertEqual(amount_t(0L), x0);
+ assertEqual(x5, x1);
+ assertEqual(x7, x1);
+ assertEqual(x6, x3);
+ assertEqual(x8, x3);
+ assertEqual(- x6, x9);
+ assertEqual(x3.negate(), x9);
+
+ amount_t x10(x9.negate());
+
+ assertEqual(x3, x10);
+ CPPUNIT_ASSERT(x0.valid());
CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(x3.valid());
+ CPPUNIT_ASSERT(x5.valid());
+ CPPUNIT_ASSERT(x6.valid());
+ CPPUNIT_ASSERT(x7.valid());
+ CPPUNIT_ASSERT(x8.valid());
+ CPPUNIT_ASSERT(x9.valid());
+ CPPUNIT_ASSERT(x10.valid());
}
-void BasicAmountTestCase::testFractionalConversion()
+void BasicAmountTestCase::testAbs()
{
- amount_t x1(1234.56);
+ amount_t x0;
+ amount_t x1(-1234L);
+ amount_t x2(1234L);
- assertEqual(true, bool(x1));
- assertEqual(1234L, x1.to_long());
- assertEqual(1234.56, x1.to_double());
- assertEqual(string("1234.56"), x1.to_string());
- assertEqual(string("1234.56"), x1.quantity_string());
+ assertEqual(amount_t(), x0.abs());
+ assertEqual(amount_t(1234L), x1.abs());
+ assertEqual(amount_t(1234L), x2.abs());
+ CPPUNIT_ASSERT(x0.valid());
CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(x2.valid());
}
void BasicAmountTestCase::testFractionalRound()
@@ -490,6 +511,47 @@ void BasicAmountTestCase::testFractionalRound()
CPPUNIT_ASSERT(x4.valid());
}
+void BasicAmountTestCase::testReduction()
+{
+ amount_t x1("60s");
+ amount_t x2("600s");
+ amount_t x3("6000s");
+ amount_t x4("360000s");
+ amount_t x5("10m"); // 600s
+ amount_t x6("100m"); // 6000s
+ amount_t x7("1000m"); // 60000s
+ amount_t x8("10000m"); // 600000s
+ amount_t x9("10h"); // 36000s
+ amount_t x10("100h"); // 360000s
+ amount_t x11("1000h"); // 3600000s
+ amount_t x12("10000h"); // 36000000s
+
+ assertEqual(x2, x5);
+ assertEqual(x3, x6);
+ assertEqual(x4, x10);
+}
+
+void BasicAmountTestCase::testSign()
+{
+ amount_t x0;
+ amount_t x1("0.0000000000000000000000000000000000001");
+ amount_t x2("-0.0000000000000000000000000000000000001");
+ amount_t x3("1");
+ amount_t x4("-1");
+
+ CPPUNIT_ASSERT(! x0.sign());
+ CPPUNIT_ASSERT(x1.sign() > 0);
+ CPPUNIT_ASSERT(x2.sign() < 0);
+ CPPUNIT_ASSERT(x3.sign() > 0);
+ CPPUNIT_ASSERT(x4.sign() < 0);
+
+ CPPUNIT_ASSERT(x0.valid());
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(x2.valid());
+ CPPUNIT_ASSERT(x3.valid());
+ CPPUNIT_ASSERT(x4.valid());
+}
+
void BasicAmountTestCase::testTruth()
{
amount_t x0;
@@ -532,92 +594,30 @@ void BasicAmountTestCase::testForZero()
CPPUNIT_ASSERT(x1.valid());
}
-void BasicAmountTestCase::testComparisons()
-{
- amount_t x0;
- amount_t x1(-123L);
- amount_t x2(123L);
- amount_t x3(-123.45);
- amount_t x4(123.45);
- amount_t x5("-123.45");
- amount_t x6("123.45");
-
- CPPUNIT_ASSERT(x0 > x1);
- CPPUNIT_ASSERT(x0 < x2);
- CPPUNIT_ASSERT(x0 > x3);
- CPPUNIT_ASSERT(x0 < x4);
- CPPUNIT_ASSERT(x0 > x5);
- CPPUNIT_ASSERT(x0 < x6);
-
- CPPUNIT_ASSERT(x1 > x3);
- CPPUNIT_ASSERT(x3 <= x5);
- CPPUNIT_ASSERT(x3 >= x5);
- CPPUNIT_ASSERT(x3 < x1);
- CPPUNIT_ASSERT(x3 < x4);
-
- CPPUNIT_ASSERT(x0.valid());
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(x2.valid());
- CPPUNIT_ASSERT(x3.valid());
- CPPUNIT_ASSERT(x4.valid());
- CPPUNIT_ASSERT(x5.valid());
- CPPUNIT_ASSERT(x6.valid());
-}
-
-void BasicAmountTestCase::testSign()
+void BasicAmountTestCase::testIntegerConversion()
{
- amount_t x0;
- amount_t x1("0.0000000000000000000000000000000000001");
- amount_t x2("-0.0000000000000000000000000000000000001");
- amount_t x3("1");
- amount_t x4("-1");
+ amount_t x1(123456L);
- CPPUNIT_ASSERT(! x0.sign());
- CPPUNIT_ASSERT(x1.sign() > 0);
- CPPUNIT_ASSERT(x2.sign() < 0);
- CPPUNIT_ASSERT(x3.sign() > 0);
- CPPUNIT_ASSERT(x4.sign() < 0);
+ assertEqual(true, bool(x1));
+ assertEqual(123456L, x1.to_long());
+ assertEqual(123456.0, x1.to_double());
+ assertEqual(string("123456"), x1.to_string());
+ assertEqual(string("123456"), x1.quantity_string());
- CPPUNIT_ASSERT(x0.valid());
CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(x2.valid());
- CPPUNIT_ASSERT(x3.valid());
- CPPUNIT_ASSERT(x4.valid());
}
-void BasicAmountTestCase::testAbs()
+void BasicAmountTestCase::testFractionalConversion()
{
- amount_t x0;
- amount_t x1(-1234L);
- amount_t x2(1234L);
+ amount_t x1(1234.56);
- assertEqual(amount_t(), x0.abs());
- assertEqual(amount_t(1234L), x1.abs());
- assertEqual(amount_t(1234L), x2.abs());
+ assertEqual(true, bool(x1));
+ assertEqual(1234L, x1.to_long());
+ assertEqual(1234.56, x1.to_double());
+ assertEqual(string("1234.56"), x1.to_string());
+ assertEqual(string("1234.56"), x1.quantity_string());
- CPPUNIT_ASSERT(x0.valid());
CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(x2.valid());
-}
-
-void BasicAmountTestCase::testReduction()
-{
- amount_t x1("60s");
- amount_t x2("600s");
- amount_t x3("6000s");
- amount_t x4("360000s");
- amount_t x5("10m"); // 600s
- amount_t x6("100m"); // 6000s
- amount_t x7("1000m"); // 60000s
- amount_t x8("10000m"); // 600000s
- amount_t x9("10h"); // 36000s
- amount_t x10("100h"); // 360000s
- amount_t x11("1000h"); // 3600000s
- amount_t x12("10000h"); // 36000000s
-
- assertEqual(x2, x5);
- assertEqual(x3, x6);
- assertEqual(x4, x10);
}
void BasicAmountTestCase::testPrinting()
diff --git a/tests/numerics/BasicAmount.h b/tests/numerics/BasicAmount.h
index a6c8aff7..12449e49 100644
--- a/tests/numerics/BasicAmount.h
+++ b/tests/numerics/BasicAmount.h
@@ -8,9 +8,9 @@ class BasicAmountTestCase : public CPPUNIT_NS::TestCase
CPPUNIT_TEST_SUITE(BasicAmountTestCase);
CPPUNIT_TEST(testConstructors);
- CPPUNIT_TEST(testNegation);
CPPUNIT_TEST(testAssignment);
CPPUNIT_TEST(testEquality);
+ CPPUNIT_TEST(testComparisons);
CPPUNIT_TEST(testIntegerAddition);
CPPUNIT_TEST(testFractionalAddition);
CPPUNIT_TEST(testIntegerSubtraction);
@@ -19,15 +19,15 @@ class BasicAmountTestCase : public CPPUNIT_NS::TestCase
CPPUNIT_TEST(testFractionalMultiplication);
CPPUNIT_TEST(testIntegerDivision);
CPPUNIT_TEST(testFractionalDivision);
- CPPUNIT_TEST(testIntegerConversion);
- CPPUNIT_TEST(testFractionalConversion);
+ CPPUNIT_TEST(testNegation);
+ CPPUNIT_TEST(testAbs);
CPPUNIT_TEST(testFractionalRound);
+ CPPUNIT_TEST(testReduction);
+ CPPUNIT_TEST(testSign);
CPPUNIT_TEST(testTruth);
CPPUNIT_TEST(testForZero);
- CPPUNIT_TEST(testComparisons);
- CPPUNIT_TEST(testSign);
- CPPUNIT_TEST(testAbs);
- CPPUNIT_TEST(testReduction);
+ CPPUNIT_TEST(testIntegerConversion);
+ CPPUNIT_TEST(testFractionalConversion);
CPPUNIT_TEST(testPrinting);
CPPUNIT_TEST_SUITE_END();
@@ -40,9 +40,9 @@ public:
virtual void tearDown();
void testConstructors();
- void testNegation();
void testAssignment();
void testEquality();
+ void testComparisons();
void testIntegerAddition();
void testFractionalAddition();
void testIntegerSubtraction();
@@ -51,15 +51,15 @@ public:
void testFractionalMultiplication();
void testIntegerDivision();
void testFractionalDivision();
- void testIntegerConversion();
- void testFractionalConversion();
+ void testNegation();
+ void testAbs();
void testFractionalRound();
+ void testReduction();
+ void testSign();
void testTruth();
void testForZero();
- void testComparisons();
- void testSign();
- void testAbs();
- void testReduction();
+ void testIntegerConversion();
+ void testFractionalConversion();
void testPrinting();
private: