From 009dd3969a5cf965a685702b71aee53bf957b206 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 19 Jan 2009 17:48:27 -0400 Subject: Added a recursive, date-based commodity price searching capability. This makes it possible to find all possible prices for a commodity by walking the map of pricing relationships to all other commodities, even if the relation is distant. --- test/unit/t_commodity.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'test/unit/t_commodity.cc') diff --git a/test/unit/t_commodity.cc b/test/unit/t_commodity.cc index a96bed72..7a2a2dea 100644 --- a/test/unit/t_commodity.cc +++ b/test/unit/t_commodity.cc @@ -35,14 +35,29 @@ void CommodityTestCase::testPriceHistory() 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 amt1 = x1.value(feb28_07sbm); assertTrue(amt1); assertEqual(amount_t("$1831.83"), *amt1); - optional amt2 = x1.value(current_time); + commodity_t& euro(amount_t("EUR 1.00").commodity()); + + optional amt2 = x1.value(current_time, euro); assertTrue(amt2); - assertEqual(amount_t("$2124.12"), *amt2); + assertEqual(amount_t("EUR 2302.30"), *amt2); + + optional amt3 = x1.value(current_time); + assertTrue(amt3); + assertEqual(amount_t("$2124.12"), *amt3); + + euro.add_price(feb27_07, amount_t("CAD 40.00")); + + commodity_t& cad(amount_t("CAD 1.00").commodity()); + + optional amt4 = x1.value(current_time, cad); + assertTrue(amt4); + assertEqual(amount_t("CAD 92092.00"), *amt4); assertValid(x1); } -- cgit v1.2.3