Copying Task3Test to individual solutions that advanced to the 3rd round
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 07 Oct 2008 11:19:36 +0200
changeset 4879a576394dd7
parent 47 176d66a9cbe6
child 49 de033c457bed
Copying Task3Test to individual solutions that advanced to the 3rd round
task3/solution02/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution04/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution06/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution07/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution11/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution12/test/org/apidesign/apifest08/test/Task3Test.java
task3/solution13/test/org/apidesign/apifest08/test/Task3Test.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task3/solution02/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     1.3 @@ -0,0 +1,104 @@
     1.4 +package org.apidesign.apifest08.test;
     1.5 +
     1.6 +import junit.framework.TestCase;
     1.7 +import org.apidesign.apifest08.currency.Convertor;
     1.8 +
     1.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    1.10 + * hour by hour, minute by minute. For every bank it is important to always
    1.11 + * have the actual exchange rate available in the system. That is why let's
    1.12 + * create a pluggable convertor that will always have up to date value of its
    1.13 + * exchange rate.
    1.14 + * <p>
    1.15 + * The quest for today is to allow 3rd party developer to write a convertor
    1.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    1.17 + * written by independent vendor, the vendor knows only your Convertor API,
    1.18 + * he does not know how the whole system looks and how the convertor is supposed
    1.19 + * to be used.
    1.20 + */
    1.21 +public class Task3Test extends TestCase {
    1.22 +    public Task3Test(String testName) {
    1.23 +        super(testName);
    1.24 +    }
    1.25 +
    1.26 +    @Override
    1.27 +    protected void setUp() throws Exception {
    1.28 +    }
    1.29 +
    1.30 +    @Override
    1.31 +    protected void tearDown() throws Exception {
    1.32 +    }
    1.33 +
    1.34 +    // Backward compatibly enhance your existing API to support following
    1.35 +    // usecases:
    1.36 +    //
    1.37 +
    1.38 +
    1.39 +    /** Without knowing anything about the surrounding system, write an
    1.40 +     * implementation of convertor that will return different rates everytime
    1.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    1.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    1.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    1.44 +     * until you reach 1USD = 16CZK
    1.45 +     *
    1.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    1.47 +     */
    1.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    1.49 +        // initial rate: 1USD = 16CZK
    1.50 +        // 2nd query 1USD = 15.99CZK
    1.51 +        // 3rd query 1USD = 15.98CZK
    1.52 +        // until 1USD = 15.00CZK
    1.53 +        // then 1USD = 15.01CZK
    1.54 +        // then 1USD = 15.02CZK
    1.55 +        // and so on and on up to 1USD = 16CZK
    1.56 +        // and then another round to 15, etc.
    1.57 +        return null;
    1.58 +    }
    1.59 +
    1.60 +    public void testFewQueriesForOnlineConvertor() {
    1.61 +        if (Boolean.getBoolean("ignore.failing")) {
    1.62 +            // implement me!
    1.63 +            return;
    1.64 +        }
    1.65 +
    1.66 +        Convertor c = createOnlineCZKUSDConvertor();
    1.67 +        doFewQueriesForOnlineConvertor(c);
    1.68 +    }
    1.69 +
    1.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    1.71 +        // convert $5 to CZK using c:
    1.72 +        //assertEquals("Result is 80 CZK");
    1.73 +
    1.74 +        // convert $8 to CZK using c:
    1.75 +        //assertEquals("Result is 127.92 CZK");
    1.76 +
    1.77 +        // convert $1 to CZK using c:
    1.78 +        //assertEquals("Result is 15.98 CZK");
    1.79 +
    1.80 +        // convert 15.97CZK to USD using c:
    1.81 +        //assertEquals("Result is 1$");
    1.82 +
    1.83 +        fail("Implement me!");
    1.84 +    }
    1.85 +
    1.86 +    /** Join the convertors and show they behave sane.
    1.87 +     */
    1.88 +    public void testOnlineConvertorComposition() throws Exception {
    1.89 +        if (Boolean.getBoolean("ignore.failing")) {
    1.90 +            // implement me!
    1.91 +            return;
    1.92 +        }
    1.93 +        
    1.94 +        Convertor c = Task2Test.merge(
    1.95 +            createOnlineCZKUSDConvertor(),
    1.96 +            Task1Test.createSKKtoCZK()
    1.97 +        );
    1.98 +
    1.99 +        // convert 16CZK to SKK using c:
   1.100 +        // assertEquals("Result is 20 SKK");
   1.101 +
   1.102 +        // convert 500SKK to CZK using c:
   1.103 +        // assertEquals("Result is 400 CZK");
   1.104 +
   1.105 +        doFewQueriesForOnlineConvertor(c);
   1.106 +    }
   1.107 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/task3/solution04/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     2.3 @@ -0,0 +1,104 @@
     2.4 +package org.apidesign.apifest08.test;
     2.5 +
     2.6 +import junit.framework.TestCase;
     2.7 +import org.apidesign.apifest08.currency.Convertor;
     2.8 +
     2.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    2.10 + * hour by hour, minute by minute. For every bank it is important to always
    2.11 + * have the actual exchange rate available in the system. That is why let's
    2.12 + * create a pluggable convertor that will always have up to date value of its
    2.13 + * exchange rate.
    2.14 + * <p>
    2.15 + * The quest for today is to allow 3rd party developer to write a convertor
    2.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    2.17 + * written by independent vendor, the vendor knows only your Convertor API,
    2.18 + * he does not know how the whole system looks and how the convertor is supposed
    2.19 + * to be used.
    2.20 + */
    2.21 +public class Task3Test extends TestCase {
    2.22 +    public Task3Test(String testName) {
    2.23 +        super(testName);
    2.24 +    }
    2.25 +
    2.26 +    @Override
    2.27 +    protected void setUp() throws Exception {
    2.28 +    }
    2.29 +
    2.30 +    @Override
    2.31 +    protected void tearDown() throws Exception {
    2.32 +    }
    2.33 +
    2.34 +    // Backward compatibly enhance your existing API to support following
    2.35 +    // usecases:
    2.36 +    //
    2.37 +
    2.38 +
    2.39 +    /** Without knowing anything about the surrounding system, write an
    2.40 +     * implementation of convertor that will return different rates everytime
    2.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    2.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    2.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    2.44 +     * until you reach 1USD = 16CZK
    2.45 +     *
    2.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    2.47 +     */
    2.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    2.49 +        // initial rate: 1USD = 16CZK
    2.50 +        // 2nd query 1USD = 15.99CZK
    2.51 +        // 3rd query 1USD = 15.98CZK
    2.52 +        // until 1USD = 15.00CZK
    2.53 +        // then 1USD = 15.01CZK
    2.54 +        // then 1USD = 15.02CZK
    2.55 +        // and so on and on up to 1USD = 16CZK
    2.56 +        // and then another round to 15, etc.
    2.57 +        return null;
    2.58 +    }
    2.59 +
    2.60 +    public void testFewQueriesForOnlineConvertor() {
    2.61 +        if (Boolean.getBoolean("ignore.failing")) {
    2.62 +            // implement me!
    2.63 +            return;
    2.64 +        }
    2.65 +
    2.66 +        Convertor c = createOnlineCZKUSDConvertor();
    2.67 +        doFewQueriesForOnlineConvertor(c);
    2.68 +    }
    2.69 +
    2.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    2.71 +        // convert $5 to CZK using c:
    2.72 +        //assertEquals("Result is 80 CZK");
    2.73 +
    2.74 +        // convert $8 to CZK using c:
    2.75 +        //assertEquals("Result is 127.92 CZK");
    2.76 +
    2.77 +        // convert $1 to CZK using c:
    2.78 +        //assertEquals("Result is 15.98 CZK");
    2.79 +
    2.80 +        // convert 15.97CZK to USD using c:
    2.81 +        //assertEquals("Result is 1$");
    2.82 +
    2.83 +        fail("Implement me!");
    2.84 +    }
    2.85 +
    2.86 +    /** Join the convertors and show they behave sane.
    2.87 +     */
    2.88 +    public void testOnlineConvertorComposition() throws Exception {
    2.89 +        if (Boolean.getBoolean("ignore.failing")) {
    2.90 +            // implement me!
    2.91 +            return;
    2.92 +        }
    2.93 +        
    2.94 +        Convertor c = Task2Test.merge(
    2.95 +            createOnlineCZKUSDConvertor(),
    2.96 +            Task1Test.createSKKtoCZK()
    2.97 +        );
    2.98 +
    2.99 +        // convert 16CZK to SKK using c:
   2.100 +        // assertEquals("Result is 20 SKK");
   2.101 +
   2.102 +        // convert 500SKK to CZK using c:
   2.103 +        // assertEquals("Result is 400 CZK");
   2.104 +
   2.105 +        doFewQueriesForOnlineConvertor(c);
   2.106 +    }
   2.107 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/task3/solution06/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     3.3 @@ -0,0 +1,104 @@
     3.4 +package org.apidesign.apifest08.test;
     3.5 +
     3.6 +import junit.framework.TestCase;
     3.7 +import org.apidesign.apifest08.currency.Convertor;
     3.8 +
     3.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    3.10 + * hour by hour, minute by minute. For every bank it is important to always
    3.11 + * have the actual exchange rate available in the system. That is why let's
    3.12 + * create a pluggable convertor that will always have up to date value of its
    3.13 + * exchange rate.
    3.14 + * <p>
    3.15 + * The quest for today is to allow 3rd party developer to write a convertor
    3.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    3.17 + * written by independent vendor, the vendor knows only your Convertor API,
    3.18 + * he does not know how the whole system looks and how the convertor is supposed
    3.19 + * to be used.
    3.20 + */
    3.21 +public class Task3Test extends TestCase {
    3.22 +    public Task3Test(String testName) {
    3.23 +        super(testName);
    3.24 +    }
    3.25 +
    3.26 +    @Override
    3.27 +    protected void setUp() throws Exception {
    3.28 +    }
    3.29 +
    3.30 +    @Override
    3.31 +    protected void tearDown() throws Exception {
    3.32 +    }
    3.33 +
    3.34 +    // Backward compatibly enhance your existing API to support following
    3.35 +    // usecases:
    3.36 +    //
    3.37 +
    3.38 +
    3.39 +    /** Without knowing anything about the surrounding system, write an
    3.40 +     * implementation of convertor that will return different rates everytime
    3.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    3.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    3.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    3.44 +     * until you reach 1USD = 16CZK
    3.45 +     *
    3.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    3.47 +     */
    3.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    3.49 +        // initial rate: 1USD = 16CZK
    3.50 +        // 2nd query 1USD = 15.99CZK
    3.51 +        // 3rd query 1USD = 15.98CZK
    3.52 +        // until 1USD = 15.00CZK
    3.53 +        // then 1USD = 15.01CZK
    3.54 +        // then 1USD = 15.02CZK
    3.55 +        // and so on and on up to 1USD = 16CZK
    3.56 +        // and then another round to 15, etc.
    3.57 +        return null;
    3.58 +    }
    3.59 +
    3.60 +    public void testFewQueriesForOnlineConvertor() {
    3.61 +        if (Boolean.getBoolean("ignore.failing")) {
    3.62 +            // implement me!
    3.63 +            return;
    3.64 +        }
    3.65 +
    3.66 +        Convertor c = createOnlineCZKUSDConvertor();
    3.67 +        doFewQueriesForOnlineConvertor(c);
    3.68 +    }
    3.69 +
    3.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    3.71 +        // convert $5 to CZK using c:
    3.72 +        //assertEquals("Result is 80 CZK");
    3.73 +
    3.74 +        // convert $8 to CZK using c:
    3.75 +        //assertEquals("Result is 127.92 CZK");
    3.76 +
    3.77 +        // convert $1 to CZK using c:
    3.78 +        //assertEquals("Result is 15.98 CZK");
    3.79 +
    3.80 +        // convert 15.97CZK to USD using c:
    3.81 +        //assertEquals("Result is 1$");
    3.82 +
    3.83 +        fail("Implement me!");
    3.84 +    }
    3.85 +
    3.86 +    /** Join the convertors and show they behave sane.
    3.87 +     */
    3.88 +    public void testOnlineConvertorComposition() throws Exception {
    3.89 +        if (Boolean.getBoolean("ignore.failing")) {
    3.90 +            // implement me!
    3.91 +            return;
    3.92 +        }
    3.93 +        
    3.94 +        Convertor c = Task2Test.merge(
    3.95 +            createOnlineCZKUSDConvertor(),
    3.96 +            Task1Test.createSKKtoCZK()
    3.97 +        );
    3.98 +
    3.99 +        // convert 16CZK to SKK using c:
   3.100 +        // assertEquals("Result is 20 SKK");
   3.101 +
   3.102 +        // convert 500SKK to CZK using c:
   3.103 +        // assertEquals("Result is 400 CZK");
   3.104 +
   3.105 +        doFewQueriesForOnlineConvertor(c);
   3.106 +    }
   3.107 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/task3/solution07/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     4.3 @@ -0,0 +1,104 @@
     4.4 +package org.apidesign.apifest08.test;
     4.5 +
     4.6 +import junit.framework.TestCase;
     4.7 +import org.apidesign.apifest08.currency.Convertor;
     4.8 +
     4.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    4.10 + * hour by hour, minute by minute. For every bank it is important to always
    4.11 + * have the actual exchange rate available in the system. That is why let's
    4.12 + * create a pluggable convertor that will always have up to date value of its
    4.13 + * exchange rate.
    4.14 + * <p>
    4.15 + * The quest for today is to allow 3rd party developer to write a convertor
    4.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    4.17 + * written by independent vendor, the vendor knows only your Convertor API,
    4.18 + * he does not know how the whole system looks and how the convertor is supposed
    4.19 + * to be used.
    4.20 + */
    4.21 +public class Task3Test extends TestCase {
    4.22 +    public Task3Test(String testName) {
    4.23 +        super(testName);
    4.24 +    }
    4.25 +
    4.26 +    @Override
    4.27 +    protected void setUp() throws Exception {
    4.28 +    }
    4.29 +
    4.30 +    @Override
    4.31 +    protected void tearDown() throws Exception {
    4.32 +    }
    4.33 +
    4.34 +    // Backward compatibly enhance your existing API to support following
    4.35 +    // usecases:
    4.36 +    //
    4.37 +
    4.38 +
    4.39 +    /** Without knowing anything about the surrounding system, write an
    4.40 +     * implementation of convertor that will return different rates everytime
    4.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    4.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    4.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    4.44 +     * until you reach 1USD = 16CZK
    4.45 +     *
    4.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    4.47 +     */
    4.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    4.49 +        // initial rate: 1USD = 16CZK
    4.50 +        // 2nd query 1USD = 15.99CZK
    4.51 +        // 3rd query 1USD = 15.98CZK
    4.52 +        // until 1USD = 15.00CZK
    4.53 +        // then 1USD = 15.01CZK
    4.54 +        // then 1USD = 15.02CZK
    4.55 +        // and so on and on up to 1USD = 16CZK
    4.56 +        // and then another round to 15, etc.
    4.57 +        return null;
    4.58 +    }
    4.59 +
    4.60 +    public void testFewQueriesForOnlineConvertor() {
    4.61 +        if (Boolean.getBoolean("ignore.failing")) {
    4.62 +            // implement me!
    4.63 +            return;
    4.64 +        }
    4.65 +
    4.66 +        Convertor c = createOnlineCZKUSDConvertor();
    4.67 +        doFewQueriesForOnlineConvertor(c);
    4.68 +    }
    4.69 +
    4.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    4.71 +        // convert $5 to CZK using c:
    4.72 +        //assertEquals("Result is 80 CZK");
    4.73 +
    4.74 +        // convert $8 to CZK using c:
    4.75 +        //assertEquals("Result is 127.92 CZK");
    4.76 +
    4.77 +        // convert $1 to CZK using c:
    4.78 +        //assertEquals("Result is 15.98 CZK");
    4.79 +
    4.80 +        // convert 15.97CZK to USD using c:
    4.81 +        //assertEquals("Result is 1$");
    4.82 +
    4.83 +        fail("Implement me!");
    4.84 +    }
    4.85 +
    4.86 +    /** Join the convertors and show they behave sane.
    4.87 +     */
    4.88 +    public void testOnlineConvertorComposition() throws Exception {
    4.89 +        if (Boolean.getBoolean("ignore.failing")) {
    4.90 +            // implement me!
    4.91 +            return;
    4.92 +        }
    4.93 +        
    4.94 +        Convertor c = Task2Test.merge(
    4.95 +            createOnlineCZKUSDConvertor(),
    4.96 +            Task1Test.createSKKtoCZK()
    4.97 +        );
    4.98 +
    4.99 +        // convert 16CZK to SKK using c:
   4.100 +        // assertEquals("Result is 20 SKK");
   4.101 +
   4.102 +        // convert 500SKK to CZK using c:
   4.103 +        // assertEquals("Result is 400 CZK");
   4.104 +
   4.105 +        doFewQueriesForOnlineConvertor(c);
   4.106 +    }
   4.107 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/task3/solution11/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     5.3 @@ -0,0 +1,104 @@
     5.4 +package org.apidesign.apifest08.test;
     5.5 +
     5.6 +import junit.framework.TestCase;
     5.7 +import org.apidesign.apifest08.currency.Convertor;
     5.8 +
     5.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    5.10 + * hour by hour, minute by minute. For every bank it is important to always
    5.11 + * have the actual exchange rate available in the system. That is why let's
    5.12 + * create a pluggable convertor that will always have up to date value of its
    5.13 + * exchange rate.
    5.14 + * <p>
    5.15 + * The quest for today is to allow 3rd party developer to write a convertor
    5.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    5.17 + * written by independent vendor, the vendor knows only your Convertor API,
    5.18 + * he does not know how the whole system looks and how the convertor is supposed
    5.19 + * to be used.
    5.20 + */
    5.21 +public class Task3Test extends TestCase {
    5.22 +    public Task3Test(String testName) {
    5.23 +        super(testName);
    5.24 +    }
    5.25 +
    5.26 +    @Override
    5.27 +    protected void setUp() throws Exception {
    5.28 +    }
    5.29 +
    5.30 +    @Override
    5.31 +    protected void tearDown() throws Exception {
    5.32 +    }
    5.33 +
    5.34 +    // Backward compatibly enhance your existing API to support following
    5.35 +    // usecases:
    5.36 +    //
    5.37 +
    5.38 +
    5.39 +    /** Without knowing anything about the surrounding system, write an
    5.40 +     * implementation of convertor that will return different rates everytime
    5.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    5.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    5.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    5.44 +     * until you reach 1USD = 16CZK
    5.45 +     *
    5.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    5.47 +     */
    5.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    5.49 +        // initial rate: 1USD = 16CZK
    5.50 +        // 2nd query 1USD = 15.99CZK
    5.51 +        // 3rd query 1USD = 15.98CZK
    5.52 +        // until 1USD = 15.00CZK
    5.53 +        // then 1USD = 15.01CZK
    5.54 +        // then 1USD = 15.02CZK
    5.55 +        // and so on and on up to 1USD = 16CZK
    5.56 +        // and then another round to 15, etc.
    5.57 +        return null;
    5.58 +    }
    5.59 +
    5.60 +    public void testFewQueriesForOnlineConvertor() {
    5.61 +        if (Boolean.getBoolean("ignore.failing")) {
    5.62 +            // implement me!
    5.63 +            return;
    5.64 +        }
    5.65 +
    5.66 +        Convertor c = createOnlineCZKUSDConvertor();
    5.67 +        doFewQueriesForOnlineConvertor(c);
    5.68 +    }
    5.69 +
    5.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    5.71 +        // convert $5 to CZK using c:
    5.72 +        //assertEquals("Result is 80 CZK");
    5.73 +
    5.74 +        // convert $8 to CZK using c:
    5.75 +        //assertEquals("Result is 127.92 CZK");
    5.76 +
    5.77 +        // convert $1 to CZK using c:
    5.78 +        //assertEquals("Result is 15.98 CZK");
    5.79 +
    5.80 +        // convert 15.97CZK to USD using c:
    5.81 +        //assertEquals("Result is 1$");
    5.82 +
    5.83 +        fail("Implement me!");
    5.84 +    }
    5.85 +
    5.86 +    /** Join the convertors and show they behave sane.
    5.87 +     */
    5.88 +    public void testOnlineConvertorComposition() throws Exception {
    5.89 +        if (Boolean.getBoolean("ignore.failing")) {
    5.90 +            // implement me!
    5.91 +            return;
    5.92 +        }
    5.93 +        
    5.94 +        Convertor c = Task2Test.merge(
    5.95 +            createOnlineCZKUSDConvertor(),
    5.96 +            Task1Test.createSKKtoCZK()
    5.97 +        );
    5.98 +
    5.99 +        // convert 16CZK to SKK using c:
   5.100 +        // assertEquals("Result is 20 SKK");
   5.101 +
   5.102 +        // convert 500SKK to CZK using c:
   5.103 +        // assertEquals("Result is 400 CZK");
   5.104 +
   5.105 +        doFewQueriesForOnlineConvertor(c);
   5.106 +    }
   5.107 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/task3/solution12/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     6.3 @@ -0,0 +1,104 @@
     6.4 +package org.apidesign.apifest08.test;
     6.5 +
     6.6 +import junit.framework.TestCase;
     6.7 +import org.apidesign.apifest08.currency.Convertor;
     6.8 +
     6.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    6.10 + * hour by hour, minute by minute. For every bank it is important to always
    6.11 + * have the actual exchange rate available in the system. That is why let's
    6.12 + * create a pluggable convertor that will always have up to date value of its
    6.13 + * exchange rate.
    6.14 + * <p>
    6.15 + * The quest for today is to allow 3rd party developer to write a convertor
    6.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    6.17 + * written by independent vendor, the vendor knows only your Convertor API,
    6.18 + * he does not know how the whole system looks and how the convertor is supposed
    6.19 + * to be used.
    6.20 + */
    6.21 +public class Task3Test extends TestCase {
    6.22 +    public Task3Test(String testName) {
    6.23 +        super(testName);
    6.24 +    }
    6.25 +
    6.26 +    @Override
    6.27 +    protected void setUp() throws Exception {
    6.28 +    }
    6.29 +
    6.30 +    @Override
    6.31 +    protected void tearDown() throws Exception {
    6.32 +    }
    6.33 +
    6.34 +    // Backward compatibly enhance your existing API to support following
    6.35 +    // usecases:
    6.36 +    //
    6.37 +
    6.38 +
    6.39 +    /** Without knowing anything about the surrounding system, write an
    6.40 +     * implementation of convertor that will return different rates everytime
    6.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    6.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    6.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    6.44 +     * until you reach 1USD = 16CZK
    6.45 +     *
    6.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    6.47 +     */
    6.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    6.49 +        // initial rate: 1USD = 16CZK
    6.50 +        // 2nd query 1USD = 15.99CZK
    6.51 +        // 3rd query 1USD = 15.98CZK
    6.52 +        // until 1USD = 15.00CZK
    6.53 +        // then 1USD = 15.01CZK
    6.54 +        // then 1USD = 15.02CZK
    6.55 +        // and so on and on up to 1USD = 16CZK
    6.56 +        // and then another round to 15, etc.
    6.57 +        return null;
    6.58 +    }
    6.59 +
    6.60 +    public void testFewQueriesForOnlineConvertor() {
    6.61 +        if (Boolean.getBoolean("ignore.failing")) {
    6.62 +            // implement me!
    6.63 +            return;
    6.64 +        }
    6.65 +
    6.66 +        Convertor c = createOnlineCZKUSDConvertor();
    6.67 +        doFewQueriesForOnlineConvertor(c);
    6.68 +    }
    6.69 +
    6.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    6.71 +        // convert $5 to CZK using c:
    6.72 +        //assertEquals("Result is 80 CZK");
    6.73 +
    6.74 +        // convert $8 to CZK using c:
    6.75 +        //assertEquals("Result is 127.92 CZK");
    6.76 +
    6.77 +        // convert $1 to CZK using c:
    6.78 +        //assertEquals("Result is 15.98 CZK");
    6.79 +
    6.80 +        // convert 15.97CZK to USD using c:
    6.81 +        //assertEquals("Result is 1$");
    6.82 +
    6.83 +        fail("Implement me!");
    6.84 +    }
    6.85 +
    6.86 +    /** Join the convertors and show they behave sane.
    6.87 +     */
    6.88 +    public void testOnlineConvertorComposition() throws Exception {
    6.89 +        if (Boolean.getBoolean("ignore.failing")) {
    6.90 +            // implement me!
    6.91 +            return;
    6.92 +        }
    6.93 +        
    6.94 +        Convertor c = Task2Test.merge(
    6.95 +            createOnlineCZKUSDConvertor(),
    6.96 +            Task1Test.createSKKtoCZK()
    6.97 +        );
    6.98 +
    6.99 +        // convert 16CZK to SKK using c:
   6.100 +        // assertEquals("Result is 20 SKK");
   6.101 +
   6.102 +        // convert 500SKK to CZK using c:
   6.103 +        // assertEquals("Result is 400 CZK");
   6.104 +
   6.105 +        doFewQueriesForOnlineConvertor(c);
   6.106 +    }
   6.107 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/task3/solution13/test/org/apidesign/apifest08/test/Task3Test.java	Tue Oct 07 11:19:36 2008 +0200
     7.3 @@ -0,0 +1,104 @@
     7.4 +package org.apidesign.apifest08.test;
     7.5 +
     7.6 +import junit.framework.TestCase;
     7.7 +import org.apidesign.apifest08.currency.Convertor;
     7.8 +
     7.9 +/** The exchange rates are not always the same. They are changing. Day by day,
    7.10 + * hour by hour, minute by minute. For every bank it is important to always
    7.11 + * have the actual exchange rate available in the system. That is why let's
    7.12 + * create a pluggable convertor that will always have up to date value of its
    7.13 + * exchange rate.
    7.14 + * <p>
    7.15 + * The quest for today is to allow 3rd party developer to write a convertor
    7.16 + * that adjusts its exchange rate everytime it is queried. This convertor is
    7.17 + * written by independent vendor, the vendor knows only your Convertor API,
    7.18 + * he does not know how the whole system looks and how the convertor is supposed
    7.19 + * to be used.
    7.20 + */
    7.21 +public class Task3Test extends TestCase {
    7.22 +    public Task3Test(String testName) {
    7.23 +        super(testName);
    7.24 +    }
    7.25 +
    7.26 +    @Override
    7.27 +    protected void setUp() throws Exception {
    7.28 +    }
    7.29 +
    7.30 +    @Override
    7.31 +    protected void tearDown() throws Exception {
    7.32 +    }
    7.33 +
    7.34 +    // Backward compatibly enhance your existing API to support following
    7.35 +    // usecases:
    7.36 +    //
    7.37 +
    7.38 +
    7.39 +    /** Without knowing anything about the surrounding system, write an
    7.40 +     * implementation of convertor that will return different rates everytime
    7.41 +     * it is queried. Convert USD to CZK and vice versa. Start with the rate of
    7.42 +     * 1USD = 16CZK and adjust it in favor of CZK by 0.01 CZK with every query.
    7.43 +     * As soon as you reach 1USD = 15CZK adjust it by 0.01 CZK in favor of USD
    7.44 +     * until you reach 1USD = 16CZK
    7.45 +     *
    7.46 +     * @return new instance of "online" USD and CZK convertor starting with rate 1USD = 16CZK
    7.47 +     */
    7.48 +    public static Convertor createOnlineCZKUSDConvertor() {
    7.49 +        // initial rate: 1USD = 16CZK
    7.50 +        // 2nd query 1USD = 15.99CZK
    7.51 +        // 3rd query 1USD = 15.98CZK
    7.52 +        // until 1USD = 15.00CZK
    7.53 +        // then 1USD = 15.01CZK
    7.54 +        // then 1USD = 15.02CZK
    7.55 +        // and so on and on up to 1USD = 16CZK
    7.56 +        // and then another round to 15, etc.
    7.57 +        return null;
    7.58 +    }
    7.59 +
    7.60 +    public void testFewQueriesForOnlineConvertor() {
    7.61 +        if (Boolean.getBoolean("ignore.failing")) {
    7.62 +            // implement me!
    7.63 +            return;
    7.64 +        }
    7.65 +
    7.66 +        Convertor c = createOnlineCZKUSDConvertor();
    7.67 +        doFewQueriesForOnlineConvertor(c);
    7.68 +    }
    7.69 +
    7.70 +    static void doFewQueriesForOnlineConvertor(Convertor c) {
    7.71 +        // convert $5 to CZK using c:
    7.72 +        //assertEquals("Result is 80 CZK");
    7.73 +
    7.74 +        // convert $8 to CZK using c:
    7.75 +        //assertEquals("Result is 127.92 CZK");
    7.76 +
    7.77 +        // convert $1 to CZK using c:
    7.78 +        //assertEquals("Result is 15.98 CZK");
    7.79 +
    7.80 +        // convert 15.97CZK to USD using c:
    7.81 +        //assertEquals("Result is 1$");
    7.82 +
    7.83 +        fail("Implement me!");
    7.84 +    }
    7.85 +
    7.86 +    /** Join the convertors and show they behave sane.
    7.87 +     */
    7.88 +    public void testOnlineConvertorComposition() throws Exception {
    7.89 +        if (Boolean.getBoolean("ignore.failing")) {
    7.90 +            // implement me!
    7.91 +            return;
    7.92 +        }
    7.93 +        
    7.94 +        Convertor c = Task2Test.merge(
    7.95 +            createOnlineCZKUSDConvertor(),
    7.96 +            Task1Test.createSKKtoCZK()
    7.97 +        );
    7.98 +
    7.99 +        // convert 16CZK to SKK using c:
   7.100 +        // assertEquals("Result is 20 SKK");
   7.101 +
   7.102 +        // convert 500SKK to CZK using c:
   7.103 +        // assertEquals("Result is 400 CZK");
   7.104 +
   7.105 +        doFewQueriesForOnlineConvertor(c);
   7.106 +    }
   7.107 +}