diff --git a/pom.xml b/pom.xml index 682d6db..956fa2e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,5 +10,10 @@ + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/WuTangCurrency.java b/src/main/java/WuTangCurrency.java new file mode 100644 index 0000000..ef8e71a --- /dev/null +++ b/src/main/java/WuTangCurrency.java @@ -0,0 +1,31 @@ +import java.text.DecimalFormat; + +public class WuTangCurrency { + + + protected static final double US_DOLLAR = 1.00; + protected static final double EURO = 0.94; + protected static final double BRITISH = 0.82; + protected static final double INDIAN_RUPEE = 68.32; + protected static final double AUSTRALIAN_DOLLAR = 1.35; + protected static final double CANADIAN_DOLLAR = 1.32; + protected static final double SINGAPORE_DOLLAR = 1.43; + protected static final double SWISS_FRANC = 1.01; + protected static final double MALAYSIAN_RINGGIT = 4.47; + protected static final double JAPANESE_YEN = 115.84; + protected static final double CHINESE_YUAN_RENMINBI = 6.92; + + public static double currencyExchangeFormula(double amountFrom, double rateTo, double rateFrom) { + + double amountTo = amountFrom * (rateFrom / rateTo); + + // tried rounding to 2 decimal places but was unsuccessful + // double amountToRounded = (double)Math.round(amountTo * 100d) / 100d; + + System.out.println(amountTo); + return amountTo; + } + +} + + diff --git a/src/test/java/WuTangCurrencyTest.java b/src/test/java/WuTangCurrencyTest.java new file mode 100644 index 0000000..0760aeb --- /dev/null +++ b/src/test/java/WuTangCurrencyTest.java @@ -0,0 +1,89 @@ +import org.junit.Assert; +import org.junit.Test; + +public class WuTangCurrencyTest { + + WuTangCurrency exchangeRate = new WuTangCurrency(); //created to test currencyExchangeFormula() + + @Test + public void usDollarToEuroTest() { + double amountFrom = 1.00; + double expected = 0.94; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.US_DOLLAR, exchangeRate.EURO); + Assert.assertEquals(expected, actual, 0.01); //delta measures accuracy, within .01 + } + + @Test + public void EuroToUsDollarTest() { + double amountFrom = 0.94; + double expected = 1.00; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.US_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void EuroToBritishPoundTest() { + double amountFrom = 0.94; + double expected = 0.82; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.BRITISH); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void BritishPoundToINDIAN_RUPEETest() { + double amountFrom = 0.82; + double expected = 68.32; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.BRITISH, exchangeRate.INDIAN_RUPEE); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void IndianRupeeToCanadianDollarTest(){ + double amountFrom = 68.82; + double expected = 1.32; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.INDIAN_RUPEE, exchangeRate.CANADIAN_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void CanadianDollarToSingaporeDollarTest(){ + double amountFrom = 1.32; + double expected = 1.43; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.CANADIAN_DOLLAR, exchangeRate.SINGAPORE_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void SingaporeDollarToSwissFrancTest(){ + double amountFrom = 1.43; + double expected = 1.01; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SINGAPORE_DOLLAR, exchangeRate.SWISS_FRANC); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void SwissFrancToMalaysianRinggitTest(){ + double amountFrom = 1.01; + double expected = 4.47; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SWISS_FRANC, exchangeRate.MALAYSIAN_RINGGIT); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void MalaysianRinggitToJapaneseYenTest(){ + double amountFrom = 4.47; + double expected = 115.84; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.MALAYSIAN_RINGGIT, exchangeRate.JAPANESE_YEN); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void JapaneseYenToChineseYuanRenminbiTest(){ + double amountFrom = 115.84; + double expected = 6.92; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.JAPANESE_YEN, exchangeRate.CHINESE_YUAN_RENMINBI); + Assert.assertEquals(expected, actual, 0.01); + } + + +} \ No newline at end of file diff --git a/target/classes/WuTangCurrency.class b/target/classes/WuTangCurrency.class new file mode 100644 index 0000000..c3eed1c Binary files /dev/null and b/target/classes/WuTangCurrency.class differ diff --git a/target/test-classes/WuTangCurrencyTest.class b/target/test-classes/WuTangCurrencyTest.class new file mode 100644 index 0000000..93e4c4b Binary files /dev/null and b/target/test-classes/WuTangCurrencyTest.class differ