diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-19 19:58:59 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-19 19:58:59 -0400 |
commit | 85be211f996c00b1304ed8b2d4c2cb602c1486d1 (patch) | |
tree | 50447e44e68adcdb740666484734c78b295bddc3 /test/unit/t_commodity.cc | |
parent | 5cc99a6972b3b50d70b69897325bc821c8c9ec19 (diff) | |
download | fork-ledger-85be211f996c00b1304ed8b2d4c2cb602c1486d1.tar.gz fork-ledger-85be211f996c00b1304ed8b2d4c2cb602c1486d1.tar.bz2 fork-ledger-85be211f996c00b1304ed8b2d4c2cb602c1486d1.zip |
Extended commodities unit test.
Diffstat (limited to 'test/unit/t_commodity.cc')
-rw-r--r-- | test/unit/t_commodity.cc | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/test/unit/t_commodity.cc b/test/unit/t_commodity.cc index 7a2a2dea..a3973915 100644 --- a/test/unit/t_commodity.cc +++ b/test/unit/t_commodity.cc @@ -11,6 +11,8 @@ void CommodityTestCase::tearDown() { void CommodityTestCase::testPriceHistory() { + datetime_t jan17_05 = parse_datetime("2005/01/17 00:00:00"); + datetime_t jan17_06 = parse_datetime("2006/01/17 00:00:00"); datetime_t jan17_07 = parse_datetime("2007/01/17 00:00:00"); datetime_t feb27_07 = parse_datetime("2007/02/27 18:00:00"); datetime_t feb28_07 = parse_datetime("2007/02/28 06:00:00"); @@ -18,46 +20,49 @@ void CommodityTestCase::testPriceHistory() datetime_t mar01_07 = parse_datetime("2007/03/01 00:00:00"); datetime_t apr15_07 = parse_datetime("2007/04/15 13:00:00"); - // jww (2007-04-17): tbd amount_t x0; amount_t x1("100.10 AAPL"); assertThrow(x0.value(), amount_error); assertFalse(x1.value()); - // Commodities cannot be constructed by themselves, since a great - // deal of their state depends on how they were seen to be used. + // Commodities cannot be constructed by themselves, since a great deal + // of their state depends on how they were seen to be used. commodity_t& aapl(x1.commodity()); - aapl.add_price(jan17_07, amount_t("$10.20")); - aapl.add_price(feb27_07, amount_t("$13.40")); - aapl.add_price(feb28_07, amount_t("$18.33")); + aapl.add_price(jan17_07, amount_t("$10.20")); + aapl.add_price(feb27_07, amount_t("$13.40")); + aapl.add_price(feb28_07, amount_t("$18.33")); aapl.add_price(feb28_07sbm, amount_t("$18.30")); - aapl.add_price(mar01_07, amount_t("$19.50")); - aapl.add_price(apr15_07, amount_t("$21.22")); - aapl.add_price(apr15_07, amount_t("EUR 23.00")); - - optional<amount_t> amt1 = x1.value(feb28_07sbm); - assertTrue(amt1); - assertEqual(amount_t("$1831.83"), *amt1); + aapl.add_price(mar01_07, amount_t("$19.50")); + aapl.add_price(apr15_07, amount_t("$21.22")); + aapl.add_price(apr15_07, amount_t("EUR 23.00")); + aapl.add_price(jan17_06, amount_t("CAD 25.00")); commodity_t& euro(amount_t("EUR 1.00").commodity()); - optional<amount_t> amt2 = x1.value(current_time, euro); - assertTrue(amt2); - assertEqual(amount_t("EUR 2302.30"), *amt2); + euro.add_price(feb27_07, amount_t("CAD 1.40")); + euro.add_price(jan17_05, amount_t("$0.78")); + + commodity_t& cad(amount_t("CAD 1.00").commodity()); - optional<amount_t> amt3 = x1.value(current_time); - assertTrue(amt3); - assertEqual(amount_t("$2124.12"), *amt3); + cad.add_price(jan17_06, amount_t("$1.11")); - euro.add_price(feb27_07, amount_t("CAD 40.00")); + optional<amount_t> amt = x1.value(feb28_07sbm); + assertTrue(amt); + assertEqual(amount_t("$1831.83"), *amt); - commodity_t& cad(amount_t("CAD 1.00").commodity()); + amt = x1.value(current_time); + assertTrue(amt); + assertEqual(amount_t("$2124.12"), *amt); + + amt = x1.value(current_time, euro); + assertTrue(amt); + assertEqual(amount_t("EUR 2302.30"), *amt); - optional<amount_t> amt4 = x1.value(current_time, cad); - assertTrue(amt4); - assertEqual(amount_t("CAD 92092.00"), *amt4); + amt = x1.value(current_time, cad); + assertTrue(amt); + assertEqual(amount_t("CAD 3223.22"), *amt); assertValid(x1); } |