diff --git a/pom.xml b/pom.xml index 682d6db..55d5fe7 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,12 @@ wu-tang-financial 1.0-SNAPSHOT - + + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/CurrencyExchange.java b/src/main/java/CurrencyExchange.java new file mode 100644 index 0000000..738439d --- /dev/null +++ b/src/main/java/CurrencyExchange.java @@ -0,0 +1,23 @@ +public class CurrencyExchange { + + public static final double US_DOLLAR = 1.00; + public static final double EURO = 0.94; + public static final double BRITISH_POUND = 0.82; + public static final double INDIAN_RUPEE = 68.32; + public static final double AUSTRALIAN_DOLLAR = 1.35; + public static final double CANADIAN_DOLLAR = 1.32; + public static final double SINGAPORE_DOLLAR = 1.43; + public static final double SWISS_FRANC = 1.01; + public static final double MALAYSIAN_RINGGIT = 4.47; + public static final double JAPANESE_YEN = 115.84; + public static final double CHINESE_YUAN_RENMINBI = 6.92; + + public static double convertFromTo(double fromAmount, double fromCurrencyRate, double toCurrencyRate) { + + double toAmount = toCurrencyRate * (fromAmount / fromCurrencyRate); + return toAmount; + } + + + +} diff --git a/src/test/java/CurrencyExchangeTest.java b/src/test/java/CurrencyExchangeTest.java new file mode 100644 index 0000000..ce892da --- /dev/null +++ b/src/test/java/CurrencyExchangeTest.java @@ -0,0 +1,102 @@ +import org.junit.Assert; +import org.junit.Test; +import org.junit.Before; + +/** + * Created by Luis J. Romero on 2/13/2018. + */ + +public class CurrencyExchangeTest { + + CurrencyExchange ce = new CurrencyExchange(); + + @Test + public void testConvertDollarToEuro() { + double fromAmount = 1.00; + double expected = 0.94; + double actual = ce.convertFromTo(fromAmount, ce.US_DOLLAR, ce.EURO); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertEuroToDollar() { + double fromAmount = 0.94; + double expected = 1.00; + double actual = ce.convertFromTo(fromAmount, ce.EURO, ce.US_DOLLAR); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertEuroToBritishPound() { + double fromAmount = 0.94; + double expected = 0.82; + double actual = ce.convertFromTo(fromAmount, ce.EURO, ce.BRITISH_POUND); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertBritishPoundToIndianRupee() { + double fromAmount = 0.82; + double expected = 68.32; + double actual = ce.convertFromTo(fromAmount, ce.BRITISH_POUND, ce.INDIAN_RUPEE); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertRupeeToCanadianDollar() { + double fromAmount = 68.32; + double expected = 1.32; + double actual = ce.convertFromTo(fromAmount, ce.INDIAN_RUPEE, ce.CANADIAN_DOLLAR); + Assert.assertEquals(expected, actual, 0.001); + } + + // Added Australian Dollar to Canadian Dollar, to include Australian Dollar in tests + @Test + public void testConvertAustralianDollarToCanadianDollar() { + double fromAmount = 1.35; + double expected = 1.32; + double actual = ce.convertFromTo(fromAmount, ce.AUSTRALIAN_DOLLAR, ce.CANADIAN_DOLLAR); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertCanadianDollarToSingaporeDollar() { + double fromAmount = 1.32; + double expected = 1.43; + double actual = ce.convertFromTo(fromAmount, ce.CANADIAN_DOLLAR, ce.SINGAPORE_DOLLAR); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertSingaporeDollarToSwissFranc() { + double fromAmount = 1.43; + double expected = 1.01; + double actual = ce.convertFromTo(fromAmount, ce.SINGAPORE_DOLLAR, ce.SWISS_FRANC); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertSwissFrancToMalaysianRinggit() { + double fromAmount = 1.01; + double expected = 4.47; + double actual = ce.convertFromTo(fromAmount, ce.SWISS_FRANC, ce.MALAYSIAN_RINGGIT); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertMalaysianRinggitToJapaneseYen() { + double fromAmount = 4.47; + double expected = 115.84; + double actual = ce.convertFromTo(fromAmount, ce.MALAYSIAN_RINGGIT, ce.JAPANESE_YEN); + Assert.assertEquals(expected, actual, 0.001); + } + + @Test + public void testConvertJapaneseYenToChineseYuanRenminbi() { + double fromAmount = 115.84; + double expected = 6.92; + double actual = ce.convertFromTo(fromAmount, ce.JAPANESE_YEN, ce.CHINESE_YUAN_RENMINBI); + Assert.assertEquals(expected, actual, 0.001); + } + +} diff --git a/target/classes/CurrencyExchange.class b/target/classes/CurrencyExchange.class new file mode 100644 index 0000000..a4ac89b Binary files /dev/null and b/target/classes/CurrencyExchange.class differ diff --git a/target/test-classes/CurrencyExchangeTest.class b/target/test-classes/CurrencyExchangeTest.class new file mode 100644 index 0000000..9c51cca Binary files /dev/null and b/target/test-classes/CurrencyExchangeTest.class differ