1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task4/solution02/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
1.3 @@ -0,0 +1,132 @@
1.4 +package org.apidesign.apifest08.test;
1.5 +
1.6 +import java.util.Date;
1.7 +import junit.framework.TestCase;
1.8 +import org.apidesign.apifest08.currency.Convertor;
1.9 +
1.10 +/** The exchange rates are not always the same. They are changing. However
1.11 + * as in order to predict the future, one needs to understand own past. That is
1.12 + * why it is important to know the exchange rate as it was at any time during
1.13 + * the past.
1.14 + * <p>
1.15 + * Today's quest is to enhance the convertor API to deal with dates.
1.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
1.17 + * be associated with a range between two Date objects. In order
1.18 + * to keep compatibility with old API that knew nothing about dates, the
1.19 + * rates associated then are applicable "for eternity". Any use of existing
1.20 + * convert methods that do not accept a Date argument, uses the current
1.21 + * System.currentTimeMillis() as default date.
1.22 + */
1.23 +public class Task4Test extends TestCase {
1.24 + public Task4Test(String testName) {
1.25 + super(testName);
1.26 + }
1.27 +
1.28 + @Override
1.29 + protected void setUp() throws Exception {
1.30 + }
1.31 +
1.32 + @Override
1.33 + protected void tearDown() throws Exception {
1.34 + }
1.35 +
1.36 + // Backward compatibly enhance your existing API to support following
1.37 + // usecases:
1.38 + //
1.39 +
1.40 + /** Takes a convertor with any rates associated and creates new convertor
1.41 + * that returns the same values as the old one for time between from to till.
1.42 + * Otherwise it returns no results. This is just a helper method that
1.43 + * shall call some real one in the API.
1.44 + *
1.45 + * @param old existing convertor
1.46 + * @param from initial date (inclusive)
1.47 + * @param till final date (exclusive)
1.48 + * @return new convertor
1.49 + */
1.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
1.51 + return null;
1.52 + }
1.53 +
1.54 +
1.55 + public void testCompositionOfLimitedConvertors() throws Exception {
1.56 + if (Boolean.getBoolean("ignore.failing")) {
1.57 + // implement me! then delete this if statement
1.58 + return;
1.59 + }
1.60 +
1.61 + Date d1 = null; // 2008-10-01 0:00 GMT
1.62 + Date d2 = null; // 2008-10-02 0:00 GMT
1.63 + Date d3 = null; // 2008-10-03 0:00 GMT
1.64 +
1.65 + Convertor c = Task2Test.merge(
1.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
1.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
1.68 + );
1.69 +
1.70 + // convert $5 to CZK using c:
1.71 + // cannot convert as no rate is applicable to current date
1.72 +
1.73 + // convert $8 to CZK using c:
1.74 + // cannot convert as no rate is applicable to current date
1.75 +
1.76 + // convert 1003CZK to USD using c:
1.77 + // cannot convert as no rate is applicable to current date
1.78 +
1.79 + // convert 16CZK using c:
1.80 + // cannot convert as no rate is applicable to current date
1.81 +
1.82 + // convert 500SKK to CZK using c:
1.83 + // cannot convert as no rate is applicable to current date
1.84 +
1.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
1.86 + // assertEquals("Result is 85 CZK");
1.87 +
1.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
1.89 + // assertEquals("Result is 136 CZK");
1.90 +
1.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
1.92 + // assertEquals("Result is 59 USD");
1.93 +
1.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
1.95 + // assertEquals("Result is 20 SKK");
1.96 +
1.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
1.98 + // assertEquals("Result is 400 CZK");
1.99 +
1.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
1.101 + // cannot convert as no rate is applicable to current date
1.102 + }
1.103 +
1.104 + /** Create convertor that understands two currencies, CZK and
1.105 + * SKK. Make 100 SKK == 90 CZK.
1.106 + *
1.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
1.108 + */
1.109 + public static Convertor createSKKtoCZK2() {
1.110 + return null;
1.111 + }
1.112 +
1.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
1.114 + if (Boolean.getBoolean("ignore.failing")) {
1.115 + // implement me! then delete this if statement
1.116 + return;
1.117 + }
1.118 +
1.119 + Date d1 = null; // 2008-10-01 0:00 GMT
1.120 + Date d2 = null; // 2008-10-02 0:00 GMT
1.121 + Date d3 = null; // 2008-10-03 0:00 GMT
1.122 +
1.123 + Convertor c = Task2Test.merge(
1.124 + limitTo(createSKKtoCZK2(), d1, d2),
1.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
1.126 + );
1.127 +
1.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
1.129 + // assertEquals("Result is 400 CZK");
1.130 +
1.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
1.132 + // assertEquals("Result is 450 CZK");
1.133 + }
1.134 +
1.135 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/task4/solution04/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
2.3 @@ -0,0 +1,132 @@
2.4 +package org.apidesign.apifest08.test;
2.5 +
2.6 +import java.util.Date;
2.7 +import junit.framework.TestCase;
2.8 +import org.apidesign.apifest08.currency.Convertor;
2.9 +
2.10 +/** The exchange rates are not always the same. They are changing. However
2.11 + * as in order to predict the future, one needs to understand own past. That is
2.12 + * why it is important to know the exchange rate as it was at any time during
2.13 + * the past.
2.14 + * <p>
2.15 + * Today's quest is to enhance the convertor API to deal with dates.
2.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
2.17 + * be associated with a range between two Date objects. In order
2.18 + * to keep compatibility with old API that knew nothing about dates, the
2.19 + * rates associated then are applicable "for eternity". Any use of existing
2.20 + * convert methods that do not accept a Date argument, uses the current
2.21 + * System.currentTimeMillis() as default date.
2.22 + */
2.23 +public class Task4Test extends TestCase {
2.24 + public Task4Test(String testName) {
2.25 + super(testName);
2.26 + }
2.27 +
2.28 + @Override
2.29 + protected void setUp() throws Exception {
2.30 + }
2.31 +
2.32 + @Override
2.33 + protected void tearDown() throws Exception {
2.34 + }
2.35 +
2.36 + // Backward compatibly enhance your existing API to support following
2.37 + // usecases:
2.38 + //
2.39 +
2.40 + /** Takes a convertor with any rates associated and creates new convertor
2.41 + * that returns the same values as the old one for time between from to till.
2.42 + * Otherwise it returns no results. This is just a helper method that
2.43 + * shall call some real one in the API.
2.44 + *
2.45 + * @param old existing convertor
2.46 + * @param from initial date (inclusive)
2.47 + * @param till final date (exclusive)
2.48 + * @return new convertor
2.49 + */
2.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
2.51 + return null;
2.52 + }
2.53 +
2.54 +
2.55 + public void testCompositionOfLimitedConvertors() throws Exception {
2.56 + if (Boolean.getBoolean("ignore.failing")) {
2.57 + // implement me! then delete this if statement
2.58 + return;
2.59 + }
2.60 +
2.61 + Date d1 = null; // 2008-10-01 0:00 GMT
2.62 + Date d2 = null; // 2008-10-02 0:00 GMT
2.63 + Date d3 = null; // 2008-10-03 0:00 GMT
2.64 +
2.65 + Convertor c = Task2Test.merge(
2.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
2.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
2.68 + );
2.69 +
2.70 + // convert $5 to CZK using c:
2.71 + // cannot convert as no rate is applicable to current date
2.72 +
2.73 + // convert $8 to CZK using c:
2.74 + // cannot convert as no rate is applicable to current date
2.75 +
2.76 + // convert 1003CZK to USD using c:
2.77 + // cannot convert as no rate is applicable to current date
2.78 +
2.79 + // convert 16CZK using c:
2.80 + // cannot convert as no rate is applicable to current date
2.81 +
2.82 + // convert 500SKK to CZK using c:
2.83 + // cannot convert as no rate is applicable to current date
2.84 +
2.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
2.86 + // assertEquals("Result is 85 CZK");
2.87 +
2.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
2.89 + // assertEquals("Result is 136 CZK");
2.90 +
2.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
2.92 + // assertEquals("Result is 59 USD");
2.93 +
2.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
2.95 + // assertEquals("Result is 20 SKK");
2.96 +
2.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
2.98 + // assertEquals("Result is 400 CZK");
2.99 +
2.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
2.101 + // cannot convert as no rate is applicable to current date
2.102 + }
2.103 +
2.104 + /** Create convertor that understands two currencies, CZK and
2.105 + * SKK. Make 100 SKK == 90 CZK.
2.106 + *
2.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
2.108 + */
2.109 + public static Convertor createSKKtoCZK2() {
2.110 + return null;
2.111 + }
2.112 +
2.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
2.114 + if (Boolean.getBoolean("ignore.failing")) {
2.115 + // implement me! then delete this if statement
2.116 + return;
2.117 + }
2.118 +
2.119 + Date d1 = null; // 2008-10-01 0:00 GMT
2.120 + Date d2 = null; // 2008-10-02 0:00 GMT
2.121 + Date d3 = null; // 2008-10-03 0:00 GMT
2.122 +
2.123 + Convertor c = Task2Test.merge(
2.124 + limitTo(createSKKtoCZK2(), d1, d2),
2.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
2.126 + );
2.127 +
2.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
2.129 + // assertEquals("Result is 400 CZK");
2.130 +
2.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
2.132 + // assertEquals("Result is 450 CZK");
2.133 + }
2.134 +
2.135 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/task4/solution06/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
3.3 @@ -0,0 +1,132 @@
3.4 +package org.apidesign.apifest08.test;
3.5 +
3.6 +import java.util.Date;
3.7 +import junit.framework.TestCase;
3.8 +import org.apidesign.apifest08.currency.Convertor;
3.9 +
3.10 +/** The exchange rates are not always the same. They are changing. However
3.11 + * as in order to predict the future, one needs to understand own past. That is
3.12 + * why it is important to know the exchange rate as it was at any time during
3.13 + * the past.
3.14 + * <p>
3.15 + * Today's quest is to enhance the convertor API to deal with dates.
3.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
3.17 + * be associated with a range between two Date objects. In order
3.18 + * to keep compatibility with old API that knew nothing about dates, the
3.19 + * rates associated then are applicable "for eternity". Any use of existing
3.20 + * convert methods that do not accept a Date argument, uses the current
3.21 + * System.currentTimeMillis() as default date.
3.22 + */
3.23 +public class Task4Test extends TestCase {
3.24 + public Task4Test(String testName) {
3.25 + super(testName);
3.26 + }
3.27 +
3.28 + @Override
3.29 + protected void setUp() throws Exception {
3.30 + }
3.31 +
3.32 + @Override
3.33 + protected void tearDown() throws Exception {
3.34 + }
3.35 +
3.36 + // Backward compatibly enhance your existing API to support following
3.37 + // usecases:
3.38 + //
3.39 +
3.40 + /** Takes a convertor with any rates associated and creates new convertor
3.41 + * that returns the same values as the old one for time between from to till.
3.42 + * Otherwise it returns no results. This is just a helper method that
3.43 + * shall call some real one in the API.
3.44 + *
3.45 + * @param old existing convertor
3.46 + * @param from initial date (inclusive)
3.47 + * @param till final date (exclusive)
3.48 + * @return new convertor
3.49 + */
3.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
3.51 + return null;
3.52 + }
3.53 +
3.54 +
3.55 + public void testCompositionOfLimitedConvertors() throws Exception {
3.56 + if (Boolean.getBoolean("ignore.failing")) {
3.57 + // implement me! then delete this if statement
3.58 + return;
3.59 + }
3.60 +
3.61 + Date d1 = null; // 2008-10-01 0:00 GMT
3.62 + Date d2 = null; // 2008-10-02 0:00 GMT
3.63 + Date d3 = null; // 2008-10-03 0:00 GMT
3.64 +
3.65 + Convertor c = Task2Test.merge(
3.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
3.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
3.68 + );
3.69 +
3.70 + // convert $5 to CZK using c:
3.71 + // cannot convert as no rate is applicable to current date
3.72 +
3.73 + // convert $8 to CZK using c:
3.74 + // cannot convert as no rate is applicable to current date
3.75 +
3.76 + // convert 1003CZK to USD using c:
3.77 + // cannot convert as no rate is applicable to current date
3.78 +
3.79 + // convert 16CZK using c:
3.80 + // cannot convert as no rate is applicable to current date
3.81 +
3.82 + // convert 500SKK to CZK using c:
3.83 + // cannot convert as no rate is applicable to current date
3.84 +
3.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
3.86 + // assertEquals("Result is 85 CZK");
3.87 +
3.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
3.89 + // assertEquals("Result is 136 CZK");
3.90 +
3.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
3.92 + // assertEquals("Result is 59 USD");
3.93 +
3.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
3.95 + // assertEquals("Result is 20 SKK");
3.96 +
3.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
3.98 + // assertEquals("Result is 400 CZK");
3.99 +
3.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
3.101 + // cannot convert as no rate is applicable to current date
3.102 + }
3.103 +
3.104 + /** Create convertor that understands two currencies, CZK and
3.105 + * SKK. Make 100 SKK == 90 CZK.
3.106 + *
3.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
3.108 + */
3.109 + public static Convertor createSKKtoCZK2() {
3.110 + return null;
3.111 + }
3.112 +
3.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
3.114 + if (Boolean.getBoolean("ignore.failing")) {
3.115 + // implement me! then delete this if statement
3.116 + return;
3.117 + }
3.118 +
3.119 + Date d1 = null; // 2008-10-01 0:00 GMT
3.120 + Date d2 = null; // 2008-10-02 0:00 GMT
3.121 + Date d3 = null; // 2008-10-03 0:00 GMT
3.122 +
3.123 + Convertor c = Task2Test.merge(
3.124 + limitTo(createSKKtoCZK2(), d1, d2),
3.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
3.126 + );
3.127 +
3.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
3.129 + // assertEquals("Result is 400 CZK");
3.130 +
3.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
3.132 + // assertEquals("Result is 450 CZK");
3.133 + }
3.134 +
3.135 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/task4/solution07/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
4.3 @@ -0,0 +1,132 @@
4.4 +package org.apidesign.apifest08.test;
4.5 +
4.6 +import java.util.Date;
4.7 +import junit.framework.TestCase;
4.8 +import org.apidesign.apifest08.currency.Convertor;
4.9 +
4.10 +/** The exchange rates are not always the same. They are changing. However
4.11 + * as in order to predict the future, one needs to understand own past. That is
4.12 + * why it is important to know the exchange rate as it was at any time during
4.13 + * the past.
4.14 + * <p>
4.15 + * Today's quest is to enhance the convertor API to deal with dates.
4.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
4.17 + * be associated with a range between two Date objects. In order
4.18 + * to keep compatibility with old API that knew nothing about dates, the
4.19 + * rates associated then are applicable "for eternity". Any use of existing
4.20 + * convert methods that do not accept a Date argument, uses the current
4.21 + * System.currentTimeMillis() as default date.
4.22 + */
4.23 +public class Task4Test extends TestCase {
4.24 + public Task4Test(String testName) {
4.25 + super(testName);
4.26 + }
4.27 +
4.28 + @Override
4.29 + protected void setUp() throws Exception {
4.30 + }
4.31 +
4.32 + @Override
4.33 + protected void tearDown() throws Exception {
4.34 + }
4.35 +
4.36 + // Backward compatibly enhance your existing API to support following
4.37 + // usecases:
4.38 + //
4.39 +
4.40 + /** Takes a convertor with any rates associated and creates new convertor
4.41 + * that returns the same values as the old one for time between from to till.
4.42 + * Otherwise it returns no results. This is just a helper method that
4.43 + * shall call some real one in the API.
4.44 + *
4.45 + * @param old existing convertor
4.46 + * @param from initial date (inclusive)
4.47 + * @param till final date (exclusive)
4.48 + * @return new convertor
4.49 + */
4.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
4.51 + return null;
4.52 + }
4.53 +
4.54 +
4.55 + public void testCompositionOfLimitedConvertors() throws Exception {
4.56 + if (Boolean.getBoolean("ignore.failing")) {
4.57 + // implement me! then delete this if statement
4.58 + return;
4.59 + }
4.60 +
4.61 + Date d1 = null; // 2008-10-01 0:00 GMT
4.62 + Date d2 = null; // 2008-10-02 0:00 GMT
4.63 + Date d3 = null; // 2008-10-03 0:00 GMT
4.64 +
4.65 + Convertor c = Task2Test.merge(
4.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
4.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
4.68 + );
4.69 +
4.70 + // convert $5 to CZK using c:
4.71 + // cannot convert as no rate is applicable to current date
4.72 +
4.73 + // convert $8 to CZK using c:
4.74 + // cannot convert as no rate is applicable to current date
4.75 +
4.76 + // convert 1003CZK to USD using c:
4.77 + // cannot convert as no rate is applicable to current date
4.78 +
4.79 + // convert 16CZK using c:
4.80 + // cannot convert as no rate is applicable to current date
4.81 +
4.82 + // convert 500SKK to CZK using c:
4.83 + // cannot convert as no rate is applicable to current date
4.84 +
4.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
4.86 + // assertEquals("Result is 85 CZK");
4.87 +
4.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
4.89 + // assertEquals("Result is 136 CZK");
4.90 +
4.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
4.92 + // assertEquals("Result is 59 USD");
4.93 +
4.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
4.95 + // assertEquals("Result is 20 SKK");
4.96 +
4.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
4.98 + // assertEquals("Result is 400 CZK");
4.99 +
4.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
4.101 + // cannot convert as no rate is applicable to current date
4.102 + }
4.103 +
4.104 + /** Create convertor that understands two currencies, CZK and
4.105 + * SKK. Make 100 SKK == 90 CZK.
4.106 + *
4.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
4.108 + */
4.109 + public static Convertor createSKKtoCZK2() {
4.110 + return null;
4.111 + }
4.112 +
4.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
4.114 + if (Boolean.getBoolean("ignore.failing")) {
4.115 + // implement me! then delete this if statement
4.116 + return;
4.117 + }
4.118 +
4.119 + Date d1 = null; // 2008-10-01 0:00 GMT
4.120 + Date d2 = null; // 2008-10-02 0:00 GMT
4.121 + Date d3 = null; // 2008-10-03 0:00 GMT
4.122 +
4.123 + Convertor c = Task2Test.merge(
4.124 + limitTo(createSKKtoCZK2(), d1, d2),
4.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
4.126 + );
4.127 +
4.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
4.129 + // assertEquals("Result is 400 CZK");
4.130 +
4.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
4.132 + // assertEquals("Result is 450 CZK");
4.133 + }
4.134 +
4.135 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/task4/solution11/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
5.3 @@ -0,0 +1,132 @@
5.4 +package org.apidesign.apifest08.test;
5.5 +
5.6 +import java.util.Date;
5.7 +import junit.framework.TestCase;
5.8 +import org.apidesign.apifest08.currency.Convertor;
5.9 +
5.10 +/** The exchange rates are not always the same. They are changing. However
5.11 + * as in order to predict the future, one needs to understand own past. That is
5.12 + * why it is important to know the exchange rate as it was at any time during
5.13 + * the past.
5.14 + * <p>
5.15 + * Today's quest is to enhance the convertor API to deal with dates.
5.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
5.17 + * be associated with a range between two Date objects. In order
5.18 + * to keep compatibility with old API that knew nothing about dates, the
5.19 + * rates associated then are applicable "for eternity". Any use of existing
5.20 + * convert methods that do not accept a Date argument, uses the current
5.21 + * System.currentTimeMillis() as default date.
5.22 + */
5.23 +public class Task4Test extends TestCase {
5.24 + public Task4Test(String testName) {
5.25 + super(testName);
5.26 + }
5.27 +
5.28 + @Override
5.29 + protected void setUp() throws Exception {
5.30 + }
5.31 +
5.32 + @Override
5.33 + protected void tearDown() throws Exception {
5.34 + }
5.35 +
5.36 + // Backward compatibly enhance your existing API to support following
5.37 + // usecases:
5.38 + //
5.39 +
5.40 + /** Takes a convertor with any rates associated and creates new convertor
5.41 + * that returns the same values as the old one for time between from to till.
5.42 + * Otherwise it returns no results. This is just a helper method that
5.43 + * shall call some real one in the API.
5.44 + *
5.45 + * @param old existing convertor
5.46 + * @param from initial date (inclusive)
5.47 + * @param till final date (exclusive)
5.48 + * @return new convertor
5.49 + */
5.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
5.51 + return null;
5.52 + }
5.53 +
5.54 +
5.55 + public void testCompositionOfLimitedConvertors() throws Exception {
5.56 + if (Boolean.getBoolean("ignore.failing")) {
5.57 + // implement me! then delete this if statement
5.58 + return;
5.59 + }
5.60 +
5.61 + Date d1 = null; // 2008-10-01 0:00 GMT
5.62 + Date d2 = null; // 2008-10-02 0:00 GMT
5.63 + Date d3 = null; // 2008-10-03 0:00 GMT
5.64 +
5.65 + Convertor c = Task2Test.merge(
5.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
5.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
5.68 + );
5.69 +
5.70 + // convert $5 to CZK using c:
5.71 + // cannot convert as no rate is applicable to current date
5.72 +
5.73 + // convert $8 to CZK using c:
5.74 + // cannot convert as no rate is applicable to current date
5.75 +
5.76 + // convert 1003CZK to USD using c:
5.77 + // cannot convert as no rate is applicable to current date
5.78 +
5.79 + // convert 16CZK using c:
5.80 + // cannot convert as no rate is applicable to current date
5.81 +
5.82 + // convert 500SKK to CZK using c:
5.83 + // cannot convert as no rate is applicable to current date
5.84 +
5.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
5.86 + // assertEquals("Result is 85 CZK");
5.87 +
5.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
5.89 + // assertEquals("Result is 136 CZK");
5.90 +
5.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
5.92 + // assertEquals("Result is 59 USD");
5.93 +
5.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
5.95 + // assertEquals("Result is 20 SKK");
5.96 +
5.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
5.98 + // assertEquals("Result is 400 CZK");
5.99 +
5.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
5.101 + // cannot convert as no rate is applicable to current date
5.102 + }
5.103 +
5.104 + /** Create convertor that understands two currencies, CZK and
5.105 + * SKK. Make 100 SKK == 90 CZK.
5.106 + *
5.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
5.108 + */
5.109 + public static Convertor createSKKtoCZK2() {
5.110 + return null;
5.111 + }
5.112 +
5.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
5.114 + if (Boolean.getBoolean("ignore.failing")) {
5.115 + // implement me! then delete this if statement
5.116 + return;
5.117 + }
5.118 +
5.119 + Date d1 = null; // 2008-10-01 0:00 GMT
5.120 + Date d2 = null; // 2008-10-02 0:00 GMT
5.121 + Date d3 = null; // 2008-10-03 0:00 GMT
5.122 +
5.123 + Convertor c = Task2Test.merge(
5.124 + limitTo(createSKKtoCZK2(), d1, d2),
5.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
5.126 + );
5.127 +
5.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
5.129 + // assertEquals("Result is 400 CZK");
5.130 +
5.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
5.132 + // assertEquals("Result is 450 CZK");
5.133 + }
5.134 +
5.135 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/task4/solution12/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
6.3 @@ -0,0 +1,132 @@
6.4 +package org.apidesign.apifest08.test;
6.5 +
6.6 +import java.util.Date;
6.7 +import junit.framework.TestCase;
6.8 +import org.apidesign.apifest08.currency.Convertor;
6.9 +
6.10 +/** The exchange rates are not always the same. They are changing. However
6.11 + * as in order to predict the future, one needs to understand own past. That is
6.12 + * why it is important to know the exchange rate as it was at any time during
6.13 + * the past.
6.14 + * <p>
6.15 + * Today's quest is to enhance the convertor API to deal with dates.
6.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
6.17 + * be associated with a range between two Date objects. In order
6.18 + * to keep compatibility with old API that knew nothing about dates, the
6.19 + * rates associated then are applicable "for eternity". Any use of existing
6.20 + * convert methods that do not accept a Date argument, uses the current
6.21 + * System.currentTimeMillis() as default date.
6.22 + */
6.23 +public class Task4Test extends TestCase {
6.24 + public Task4Test(String testName) {
6.25 + super(testName);
6.26 + }
6.27 +
6.28 + @Override
6.29 + protected void setUp() throws Exception {
6.30 + }
6.31 +
6.32 + @Override
6.33 + protected void tearDown() throws Exception {
6.34 + }
6.35 +
6.36 + // Backward compatibly enhance your existing API to support following
6.37 + // usecases:
6.38 + //
6.39 +
6.40 + /** Takes a convertor with any rates associated and creates new convertor
6.41 + * that returns the same values as the old one for time between from to till.
6.42 + * Otherwise it returns no results. This is just a helper method that
6.43 + * shall call some real one in the API.
6.44 + *
6.45 + * @param old existing convertor
6.46 + * @param from initial date (inclusive)
6.47 + * @param till final date (exclusive)
6.48 + * @return new convertor
6.49 + */
6.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
6.51 + return null;
6.52 + }
6.53 +
6.54 +
6.55 + public void testCompositionOfLimitedConvertors() throws Exception {
6.56 + if (Boolean.getBoolean("ignore.failing")) {
6.57 + // implement me! then delete this if statement
6.58 + return;
6.59 + }
6.60 +
6.61 + Date d1 = null; // 2008-10-01 0:00 GMT
6.62 + Date d2 = null; // 2008-10-02 0:00 GMT
6.63 + Date d3 = null; // 2008-10-03 0:00 GMT
6.64 +
6.65 + Convertor c = Task2Test.merge(
6.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
6.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
6.68 + );
6.69 +
6.70 + // convert $5 to CZK using c:
6.71 + // cannot convert as no rate is applicable to current date
6.72 +
6.73 + // convert $8 to CZK using c:
6.74 + // cannot convert as no rate is applicable to current date
6.75 +
6.76 + // convert 1003CZK to USD using c:
6.77 + // cannot convert as no rate is applicable to current date
6.78 +
6.79 + // convert 16CZK using c:
6.80 + // cannot convert as no rate is applicable to current date
6.81 +
6.82 + // convert 500SKK to CZK using c:
6.83 + // cannot convert as no rate is applicable to current date
6.84 +
6.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
6.86 + // assertEquals("Result is 85 CZK");
6.87 +
6.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
6.89 + // assertEquals("Result is 136 CZK");
6.90 +
6.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
6.92 + // assertEquals("Result is 59 USD");
6.93 +
6.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
6.95 + // assertEquals("Result is 20 SKK");
6.96 +
6.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
6.98 + // assertEquals("Result is 400 CZK");
6.99 +
6.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
6.101 + // cannot convert as no rate is applicable to current date
6.102 + }
6.103 +
6.104 + /** Create convertor that understands two currencies, CZK and
6.105 + * SKK. Make 100 SKK == 90 CZK.
6.106 + *
6.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
6.108 + */
6.109 + public static Convertor createSKKtoCZK2() {
6.110 + return null;
6.111 + }
6.112 +
6.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
6.114 + if (Boolean.getBoolean("ignore.failing")) {
6.115 + // implement me! then delete this if statement
6.116 + return;
6.117 + }
6.118 +
6.119 + Date d1 = null; // 2008-10-01 0:00 GMT
6.120 + Date d2 = null; // 2008-10-02 0:00 GMT
6.121 + Date d3 = null; // 2008-10-03 0:00 GMT
6.122 +
6.123 + Convertor c = Task2Test.merge(
6.124 + limitTo(createSKKtoCZK2(), d1, d2),
6.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
6.126 + );
6.127 +
6.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
6.129 + // assertEquals("Result is 400 CZK");
6.130 +
6.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
6.132 + // assertEquals("Result is 450 CZK");
6.133 + }
6.134 +
6.135 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/task4/solution13/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
7.3 @@ -0,0 +1,132 @@
7.4 +package org.apidesign.apifest08.test;
7.5 +
7.6 +import java.util.Date;
7.7 +import junit.framework.TestCase;
7.8 +import org.apidesign.apifest08.currency.Convertor;
7.9 +
7.10 +/** The exchange rates are not always the same. They are changing. However
7.11 + * as in order to predict the future, one needs to understand own past. That is
7.12 + * why it is important to know the exchange rate as it was at any time during
7.13 + * the past.
7.14 + * <p>
7.15 + * Today's quest is to enhance the convertor API to deal with dates.
7.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
7.17 + * be associated with a range between two Date objects. In order
7.18 + * to keep compatibility with old API that knew nothing about dates, the
7.19 + * rates associated then are applicable "for eternity". Any use of existing
7.20 + * convert methods that do not accept a Date argument, uses the current
7.21 + * System.currentTimeMillis() as default date.
7.22 + */
7.23 +public class Task4Test extends TestCase {
7.24 + public Task4Test(String testName) {
7.25 + super(testName);
7.26 + }
7.27 +
7.28 + @Override
7.29 + protected void setUp() throws Exception {
7.30 + }
7.31 +
7.32 + @Override
7.33 + protected void tearDown() throws Exception {
7.34 + }
7.35 +
7.36 + // Backward compatibly enhance your existing API to support following
7.37 + // usecases:
7.38 + //
7.39 +
7.40 + /** Takes a convertor with any rates associated and creates new convertor
7.41 + * that returns the same values as the old one for time between from to till.
7.42 + * Otherwise it returns no results. This is just a helper method that
7.43 + * shall call some real one in the API.
7.44 + *
7.45 + * @param old existing convertor
7.46 + * @param from initial date (inclusive)
7.47 + * @param till final date (exclusive)
7.48 + * @return new convertor
7.49 + */
7.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
7.51 + return null;
7.52 + }
7.53 +
7.54 +
7.55 + public void testCompositionOfLimitedConvertors() throws Exception {
7.56 + if (Boolean.getBoolean("ignore.failing")) {
7.57 + // implement me! then delete this if statement
7.58 + return;
7.59 + }
7.60 +
7.61 + Date d1 = null; // 2008-10-01 0:00 GMT
7.62 + Date d2 = null; // 2008-10-02 0:00 GMT
7.63 + Date d3 = null; // 2008-10-03 0:00 GMT
7.64 +
7.65 + Convertor c = Task2Test.merge(
7.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
7.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
7.68 + );
7.69 +
7.70 + // convert $5 to CZK using c:
7.71 + // cannot convert as no rate is applicable to current date
7.72 +
7.73 + // convert $8 to CZK using c:
7.74 + // cannot convert as no rate is applicable to current date
7.75 +
7.76 + // convert 1003CZK to USD using c:
7.77 + // cannot convert as no rate is applicable to current date
7.78 +
7.79 + // convert 16CZK using c:
7.80 + // cannot convert as no rate is applicable to current date
7.81 +
7.82 + // convert 500SKK to CZK using c:
7.83 + // cannot convert as no rate is applicable to current date
7.84 +
7.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
7.86 + // assertEquals("Result is 85 CZK");
7.87 +
7.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
7.89 + // assertEquals("Result is 136 CZK");
7.90 +
7.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
7.92 + // assertEquals("Result is 59 USD");
7.93 +
7.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
7.95 + // assertEquals("Result is 20 SKK");
7.96 +
7.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
7.98 + // assertEquals("Result is 400 CZK");
7.99 +
7.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
7.101 + // cannot convert as no rate is applicable to current date
7.102 + }
7.103 +
7.104 + /** Create convertor that understands two currencies, CZK and
7.105 + * SKK. Make 100 SKK == 90 CZK.
7.106 + *
7.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
7.108 + */
7.109 + public static Convertor createSKKtoCZK2() {
7.110 + return null;
7.111 + }
7.112 +
7.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
7.114 + if (Boolean.getBoolean("ignore.failing")) {
7.115 + // implement me! then delete this if statement
7.116 + return;
7.117 + }
7.118 +
7.119 + Date d1 = null; // 2008-10-01 0:00 GMT
7.120 + Date d2 = null; // 2008-10-02 0:00 GMT
7.121 + Date d3 = null; // 2008-10-03 0:00 GMT
7.122 +
7.123 + Convertor c = Task2Test.merge(
7.124 + limitTo(createSKKtoCZK2(), d1, d2),
7.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
7.126 + );
7.127 +
7.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
7.129 + // assertEquals("Result is 400 CZK");
7.130 +
7.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
7.132 + // assertEquals("Result is 450 CZK");
7.133 + }
7.134 +
7.135 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/task4/solution14/test/org/apidesign/apifest08/test/Task4Test.java Sat Oct 11 23:46:05 2008 +0200
8.3 @@ -0,0 +1,132 @@
8.4 +package org.apidesign.apifest08.test;
8.5 +
8.6 +import java.util.Date;
8.7 +import junit.framework.TestCase;
8.8 +import org.apidesign.apifest08.currency.Convertor;
8.9 +
8.10 +/** The exchange rates are not always the same. They are changing. However
8.11 + * as in order to predict the future, one needs to understand own past. That is
8.12 + * why it is important to know the exchange rate as it was at any time during
8.13 + * the past.
8.14 + * <p>
8.15 + * Today's quest is to enhance the convertor API to deal with dates.
8.16 + * One shall be able to convert a currency at any date. Each currencies rate shall
8.17 + * be associated with a range between two Date objects. In order
8.18 + * to keep compatibility with old API that knew nothing about dates, the
8.19 + * rates associated then are applicable "for eternity". Any use of existing
8.20 + * convert methods that do not accept a Date argument, uses the current
8.21 + * System.currentTimeMillis() as default date.
8.22 + */
8.23 +public class Task4Test extends TestCase {
8.24 + public Task4Test(String testName) {
8.25 + super(testName);
8.26 + }
8.27 +
8.28 + @Override
8.29 + protected void setUp() throws Exception {
8.30 + }
8.31 +
8.32 + @Override
8.33 + protected void tearDown() throws Exception {
8.34 + }
8.35 +
8.36 + // Backward compatibly enhance your existing API to support following
8.37 + // usecases:
8.38 + //
8.39 +
8.40 + /** Takes a convertor with any rates associated and creates new convertor
8.41 + * that returns the same values as the old one for time between from to till.
8.42 + * Otherwise it returns no results. This is just a helper method that
8.43 + * shall call some real one in the API.
8.44 + *
8.45 + * @param old existing convertor
8.46 + * @param from initial date (inclusive)
8.47 + * @param till final date (exclusive)
8.48 + * @return new convertor
8.49 + */
8.50 + public static Convertor limitTo(Convertor old, Date from, Date till) {
8.51 + return null;
8.52 + }
8.53 +
8.54 +
8.55 + public void testCompositionOfLimitedConvertors() throws Exception {
8.56 + if (Boolean.getBoolean("ignore.failing")) {
8.57 + // implement me! then delete this if statement
8.58 + return;
8.59 + }
8.60 +
8.61 + Date d1 = null; // 2008-10-01 0:00 GMT
8.62 + Date d2 = null; // 2008-10-02 0:00 GMT
8.63 + Date d3 = null; // 2008-10-03 0:00 GMT
8.64 +
8.65 + Convertor c = Task2Test.merge(
8.66 + limitTo(Task1Test.createCZKtoUSD(), d1, d2),
8.67 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
8.68 + );
8.69 +
8.70 + // convert $5 to CZK using c:
8.71 + // cannot convert as no rate is applicable to current date
8.72 +
8.73 + // convert $8 to CZK using c:
8.74 + // cannot convert as no rate is applicable to current date
8.75 +
8.76 + // convert 1003CZK to USD using c:
8.77 + // cannot convert as no rate is applicable to current date
8.78 +
8.79 + // convert 16CZK using c:
8.80 + // cannot convert as no rate is applicable to current date
8.81 +
8.82 + // convert 500SKK to CZK using c:
8.83 + // cannot convert as no rate is applicable to current date
8.84 +
8.85 + // convert $5 to CZK using c at 2008-10-01 6:00 GMT:
8.86 + // assertEquals("Result is 85 CZK");
8.87 +
8.88 + // convert $8 to CZK using c at 2008-10-01 6:00 GMT:
8.89 + // assertEquals("Result is 136 CZK");
8.90 +
8.91 + // convert 1003CZK to USD using c at 2008-10-01 6:00 GMT:
8.92 + // assertEquals("Result is 59 USD");
8.93 +
8.94 + // convert 16CZK using c at 2008-10-02 9:00 GMT:
8.95 + // assertEquals("Result is 20 SKK");
8.96 +
8.97 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
8.98 + // assertEquals("Result is 400 CZK");
8.99 +
8.100 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
8.101 + // cannot convert as no rate is applicable to current date
8.102 + }
8.103 +
8.104 + /** Create convertor that understands two currencies, CZK and
8.105 + * SKK. Make 100 SKK == 90 CZK.
8.106 + *
8.107 + * @return prepared convertor ready for converting SKK to CZK and CZK to SKK
8.108 + */
8.109 + public static Convertor createSKKtoCZK2() {
8.110 + return null;
8.111 + }
8.112 +
8.113 + public void testDateConvetorWithTwoDifferentRates() throws Exception {
8.114 + if (Boolean.getBoolean("ignore.failing")) {
8.115 + // implement me! then delete this if statement
8.116 + return;
8.117 + }
8.118 +
8.119 + Date d1 = null; // 2008-10-01 0:00 GMT
8.120 + Date d2 = null; // 2008-10-02 0:00 GMT
8.121 + Date d3 = null; // 2008-10-03 0:00 GMT
8.122 +
8.123 + Convertor c = Task2Test.merge(
8.124 + limitTo(createSKKtoCZK2(), d1, d2),
8.125 + limitTo(Task1Test.createSKKtoCZK(), d2, d3)
8.126 + );
8.127 +
8.128 + // convert 500SKK to CZK using c at 2008-10-02 9:00 GMT:
8.129 + // assertEquals("Result is 400 CZK");
8.130 +
8.131 + // convert 500SKK to CZK using c at 2008-10-01 6:00 GMT:
8.132 + // assertEquals("Result is 450 CZK");
8.133 + }
8.134 +
8.135 +}