1.1 --- a/task3/solution13/test/org/apidesign/apifest08/test/Task3Test.java Tue Oct 07 11:19:36 2008 +0200
1.2 +++ b/task3/solution13/test/org/apidesign/apifest08/test/Task3Test.java Fri Oct 10 22:24:52 2008 +0200
1.3 @@ -1,7 +1,11 @@
1.4 package org.apidesign.apifest08.test;
1.5
1.6 +import java.math.BigDecimal;
1.7 import junit.framework.TestCase;
1.8 import org.apidesign.apifest08.currency.Convertor;
1.9 +import org.apidesign.apifest08.currency.ConvertorCurrency;
1.10 +import org.apidesign.apifest08.currency.ExchangeRateProvider;
1.11 +import org.apidesign.apifest08.currency.IExchangeRateEngine;
1.12
1.13 /** The exchange rates are not always the same. They are changing. Day by day,
1.14 * hour by hour, minute by minute. For every bank it is important to always
1.15 @@ -16,6 +20,11 @@
1.16 * to be used.
1.17 */
1.18 public class Task3Test extends TestCase {
1.19 +
1.20 + private static ConvertorCurrency currencyCZK = ConvertorCurrency.getInstance("CZK");
1.21 + private static ConvertorCurrency currencySKK = ConvertorCurrency.getInstance("SKK");
1.22 + private static ConvertorCurrency currencyUSD = ConvertorCurrency.getInstance("USD");
1.23 +
1.24 public Task3Test(String testName) {
1.25 super(testName);
1.26 }
1.27 @@ -51,7 +60,14 @@
1.28 // then 1USD = 15.02CZK
1.29 // and so on and on up to 1USD = 16CZK
1.30 // and then another round to 15, etc.
1.31 - return null;
1.32 + IExchangeRateEngine engine = BouncingExchangeRateEngine.create(
1.33 + currencyUSD, new BigDecimal(1),
1.34 + currencyCZK,
1.35 + new BigDecimal(16),new BigDecimal(15),
1.36 + new BigDecimal("-0.01"));
1.37 + ExchangeRateProvider exRateProvider = ExchangeRateProvider.createExchangeRateProvider(engine);
1.38 + Convertor convertor = Convertor.createConvertor(exRateProvider);
1.39 + return convertor;
1.40 }
1.41
1.42 public void testFewQueriesForOnlineConvertor() {
1.43 @@ -66,18 +82,18 @@
1.44
1.45 static void doFewQueriesForOnlineConvertor(Convertor c) {
1.46 // convert $5 to CZK using c:
1.47 - //assertEquals("Result is 80 CZK");
1.48 + assertEquals("Result is 80 CZK", new BigDecimal("80.00"), c.convertWithReversibleRates(currencyUSD, currencyCZK, new BigDecimal(5)).getConverted());
1.49
1.50 // convert $8 to CZK using c:
1.51 - //assertEquals("Result is 127.92 CZK");
1.52 + assertEquals("Result is 127.92 CZK", new BigDecimal("127.92"), c.convertWithReversibleRates(currencyUSD, currencyCZK, new BigDecimal(8)).getConverted());
1.53
1.54 // convert $1 to CZK using c:
1.55 - //assertEquals("Result is 15.98 CZK");
1.56 + assertEquals("Result is 15.98 CZK", new BigDecimal("15.98"), c.convertWithReversibleRates(currencyUSD, currencyCZK, new BigDecimal(1)).getConverted());
1.57
1.58 // convert 15.97CZK to USD using c:
1.59 - //assertEquals("Result is 1$");
1.60 + assertEquals("Result is 15.98 CZK", new BigDecimal("1.00"), c.convertWithReversibleRates(currencyCZK, currencyUSD , new BigDecimal("15.97")).getConverted());
1.61
1.62 - fail("Implement me!");
1.63 + //fail("Implement me!");
1.64 }
1.65
1.66 /** Join the convertors and show they behave sane.
1.67 @@ -94,11 +110,25 @@
1.68 );
1.69
1.70 // convert 16CZK to SKK using c:
1.71 - // assertEquals("Result is 20 SKK");
1.72 + assertEquals("Result is 20 CZK", new BigDecimal("20.00"), c.convertWithReversibleRates(currencyCZK, currencySKK , new BigDecimal("16")).getConverted());
1.73
1.74 // convert 500SKK to CZK using c:
1.75 - // assertEquals("Result is 400 CZK");
1.76 + assertEquals("Result is 400 CZK", new BigDecimal("400.00"), c.convertWithReversibleRates(currencySKK, currencyCZK , new BigDecimal("500")).getConverted());
1.77
1.78 doFewQueriesForOnlineConvertor(c);
1.79 }
1.80 +
1.81 +// public void testBouncing() {
1.82 +// Convertor c=createOnlineCZKUSDConvertor();
1.83 +//
1.84 +// IExchangeRateEngine engine = BouncingExchangeRateEngine.create(
1.85 +// currencyUSD, new BigDecimal(1),
1.86 +// currencyCZK,
1.87 +// new BigDecimal("16.00"),new BigDecimal("15.00"),
1.88 +// new BigDecimal("-0.01"));
1.89 +//
1.90 +// for (int i=0;i<300;i++) {
1.91 +// System.out.println(engine.getExchangeRate(currencyUSD, currencyCZK).getToValue());
1.92 +// }
1.93 +// }
1.94 }