summaryrefslogtreecommitdiff
path: root/tests/numerics
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-05-07 11:37:15 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:40 -0400
commit30978b7fe5ee93413b2e05b54942f6550832b222 (patch)
treecede95552b56e9f17b24b6daa1037e7b87f11aed /tests/numerics
parenta99695f69b395c9664447b5af82893fb755bd4c0 (diff)
downloadfork-ledger-30978b7fe5ee93413b2e05b54942f6550832b222.tar.gz
fork-ledger-30978b7fe5ee93413b2e05b54942f6550832b222.tar.bz2
fork-ledger-30978b7fe5ee93413b2e05b54942f6550832b222.zip
Added new test files.
Diffstat (limited to 'tests/numerics')
-rw-r--r--tests/numerics/t_amount.cc5
-rw-r--r--tests/numerics/t_balance.cc25
-rw-r--r--tests/numerics/t_balance.h30
-rw-r--r--tests/numerics/t_times.cc79
-rw-r--r--tests/numerics/t_times.h28
5 files changed, 57 insertions, 110 deletions
diff --git a/tests/numerics/t_amount.cc b/tests/numerics/t_amount.cc
index 67ea1781..a59ff2ea 100644
--- a/tests/numerics/t_amount.cc
+++ b/tests/numerics/t_amount.cc
@@ -1,7 +1,5 @@
#include "t_amount.h"
-#define internalAmount(x) amount_t::exact(x)
-
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AmountTestCase, "numerics");
void AmountTestCase::setUp()
@@ -11,7 +9,8 @@ void AmountTestCase::setUp()
// Cause the display precision for dollars to be initialized to 2.
amount_t x1("$1.00");
assertTrue(x1);
- amount_t::stream_fullstrings = true; // makes error reports from UnitTests accurate
+
+ amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
}
void AmountTestCase::tearDown()
diff --git a/tests/numerics/t_balance.cc b/tests/numerics/t_balance.cc
new file mode 100644
index 00000000..ca759836
--- /dev/null
+++ b/tests/numerics/t_balance.cc
@@ -0,0 +1,25 @@
+#include "t_balance.h"
+
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BalanceTestCase, "numerics");
+
+void BalanceTestCase::setUp()
+{
+ ledger::set_session_context(&session);
+
+ // Cause the display precision for dollars to be initialized to 2.
+ amount_t x1("$1.00");
+ assertTrue(x1);
+
+ amount_t::stream_fullstrings = true; // make reports from UnitTests accurate
+}
+
+void BalanceTestCase::tearDown()
+{
+ amount_t::stream_fullstrings = false;
+
+ ledger::set_session_context();
+}
+
+void BalanceTestCase::testConstructors()
+{
+}
diff --git a/tests/numerics/t_balance.h b/tests/numerics/t_balance.h
new file mode 100644
index 00000000..7c27f7e8
--- /dev/null
+++ b/tests/numerics/t_balance.h
@@ -0,0 +1,30 @@
+#ifndef _T_BALANCE_H
+#define _T_BALANCE_H
+
+#include "UnitTests.h"
+
+class BalanceTestCase : public CPPUNIT_NS::TestCase
+{
+ CPPUNIT_TEST_SUITE(BalanceTestCase);
+
+ CPPUNIT_TEST(testConstructors);
+
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ ledger::session_t session;
+
+ BalanceTestCase() {}
+ virtual ~BalanceTestCase() {}
+
+ virtual void setUp();
+ virtual void tearDown();
+
+ void testConstructors();
+
+private:
+ BalanceTestCase(const BalanceTestCase &copy);
+ void operator=(const BalanceTestCase &copy);
+};
+
+#endif // _T_BALANCE_H
diff --git a/tests/numerics/t_times.cc b/tests/numerics/t_times.cc
deleted file mode 100644
index 0d89d03f..00000000
--- a/tests/numerics/t_times.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "t_times.h"
-
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DateTimeTestCase, "numerics");
-
-void DateTimeTestCase::setUp() {}
-void DateTimeTestCase::tearDown() {}
-
-void DateTimeTestCase::testConstructors()
-{
- std::time_t time_t_now = std::time(NULL);
- struct tm * moment = std::localtime(&time_t_now);
-
- std::time_t localMoment = std::mktime(moment);
-
- ptime d0;
- ptime d1(parse_datetime("1990/01/01"));
- ptime d3(boost::posix_time::from_time_t(localMoment));
- ptime d4(parse_datetime("2006/12/25"));
- //ptime d5(parse_datetime("12/25"));
- ptime d6(parse_datetime("2006.12.25"));
- //ptime d7(parse_datetime("12.25"));
- ptime d8(parse_datetime("2006-12-25"));
- //ptime d9(parse_datetime("12-25"));
-#if 0
- ptime d10(parse_datetime("tue"));
- ptime d11(parse_datetime("tuesday"));
- ptime d12(parse_datetime("feb"));
- ptime d13(parse_datetime("february"));
- ptime d14(parse_datetime("2006"));
-#endif
- ptime d15(d3);
-
- assertTrue(d0.is_not_a_date_time());
- assertFalse(d1.is_not_a_date_time());
- assertFalse(d4.is_not_a_date_time());
-
- assertTrue(now > d1);
- //assertTrue(now <= d3);
- assertTrue(now > d4);
-
- assertEqual(d3, d15);
- assertEqual(d4, d6);
- assertEqual(d4, d8);
- //assertEqual(d5, d7);
- //assertEqual(d5, d9);
-#if 0
- assertEqual(d10, d11);
- assertEqual(d12, d13);
-#endif
-
-#if 0
- assertThrow(parse_datetime("2007/02/29"), datetime_error *);
- assertThrow(parse_datetime("2007/13/01"), datetime_error *);
- assertThrow(parse_datetime("2007/00/01"), datetime_error *);
- assertThrow(parse_datetime("2007/01/00"), datetime_error *);
- assertThrow(parse_datetime("2007/00/00"), datetime_error *);
- assertThrow(parse_datetime("2007/05/32"), datetime_error *);
-
- assertThrow(parse_datetime("2006x/12/25"), datetime_error *);
- assertThrow(parse_datetime("2006/12x/25"), datetime_error *);
- //assertThrow(parse_datetime("2006/12/25x"), datetime_error *);
-
- assertThrow(parse_datetime("feb/12/25"), datetime_error *);
- assertThrow(parse_datetime("2006/mon/25"), datetime_error *);
- assertThrow(parse_datetime("2006/12/web"), datetime_error *);
-
- assertThrow(parse_datetime("12*25"), datetime_error *);
-
- assertThrow(parse_datetime("tuf"), datetime_error *);
- assertThrow(parse_datetime("tufsday"), datetime_error *);
- assertThrow(parse_datetime("fec"), datetime_error *);
- assertThrow(parse_datetime("fecruary"), datetime_error *);
- assertThrow(parse_datetime("207x"), datetime_error *);
- assertThrow(parse_datetime("hello"), datetime_error *);
-
- interval_t i1;
- interval_t i2;
-#endif
-}
diff --git a/tests/numerics/t_times.h b/tests/numerics/t_times.h
deleted file mode 100644
index 5bbadf21..00000000
--- a/tests/numerics/t_times.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef _T_TIMES_H
-#define _T_TIMES_H
-
-#include "UnitTests.h"
-
-class DateTimeTestCase : public CPPUNIT_NS::TestCase
-{
- CPPUNIT_TEST_SUITE(DateTimeTestCase);
-
- CPPUNIT_TEST(testConstructors);
-
- CPPUNIT_TEST_SUITE_END();
-
-public:
- DateTimeTestCase() {}
- virtual ~DateTimeTestCase() {}
-
- virtual void setUp();
- virtual void tearDown();
-
- void testConstructors();
-
-private:
- DateTimeTestCase(const DateTimeTestCase &copy);
- void operator=(const DateTimeTestCase &copy);
-};
-
-#endif /* _T_TIMES_H */