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/DELETEME b/src/main/java/DELETEME deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/Exchange.java b/src/main/java/Exchange.java new file mode 100644 index 0000000..26ffa1a --- /dev/null +++ b/src/main/java/Exchange.java @@ -0,0 +1,28 @@ +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Map; + + +public class Exchange { + + + + + + + + + + + + + + + public static void main(String[] args) { + + } + + + +} diff --git a/src/main/java/Rate.java b/src/main/java/Rate.java new file mode 100644 index 0000000..f38d847 --- /dev/null +++ b/src/main/java/Rate.java @@ -0,0 +1,58 @@ +import java.math.BigDecimal; +import java.util.TreeMap; + + +public class Rate { + + private String country; + private Double rate; + + TreeMap currenyCollection = new TreeMap() { + { + put("USD", 1.00); + put("EUR", 0.94); + put("GBP", 0.82); + put("INR", 68.32); + put("AUD", 1.35); + put("CAD", 1.32); + put("SGD", 1.43); + put("CHF", 1.01); + put("MYR", 4.47); + put("JPY", 115.84); + put("CNY", 6.92); + } + + }; + + public Rate(){ + + } + + public BigDecimal conversion ( String country1, String country2, double amount) { + double convertedAmount = (currenyCollection.get(country2) / currenyCollection.get(country1)) * amount; + BigDecimal currencyAmount = new BigDecimal(convertedAmount); + return currencyAmount.setScale(2, BigDecimal.ROUND_CEILING); + + } + + + + public static void main(String[] args) { + + + + } +} + + +// public final static double usDollar = 1.00; +// public final static double euro = 0.94; +// public final static double britishPound = 0.82; +// public final static double indianRupee = 68.32; +// public final static double austrialianDollar = 1.35; +// public final static double canadianDollar = 1.32; +// public final static double singaporeDollar = 1.43; +// public final static double swissFranc = 1.01; +// public final static double malaysianRiggit = 4.47; +// public final static double japaneseYen = 115.84; +// public final static double chineseYuan = 6.92; \ No newline at end of file diff --git a/src/test/java/RateTest.java b/src/test/java/RateTest.java new file mode 100644 index 0000000..a5b26af --- /dev/null +++ b/src/test/java/RateTest.java @@ -0,0 +1,164 @@ +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import java.math.BigDecimal; + +import org.junit.Test; + +public class RateTest { + + Rate testRate; + + @Before + public void setUp(){ + testRate = new Rate(); + } + + + @Test + public void testConvertDollarToEuro() { + String country1 = "USD"; + String country2 = "EUR"; + double amount = 100.1456; + BigDecimal expectedAmount = new BigDecimal("94.14"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + + } + @Test + public void convertEuroToDollar() { + String country1 = "EUR"; + String country2 = "USD"; + double amount = 250.50; + BigDecimal expectedAmount = new BigDecimal("266.49"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + } + + @Test + public void ConvertEuroToBritishPound() { + String country1 = "EUR"; + String country2 = "GBP"; + double amount = 656.354; + BigDecimal expectedAmount = new BigDecimal("572.57"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + } + @Test + public void ConvertBritishPoundToIndianRupee() { + String country1 = "GBP"; + String country2 = "INR"; + double amount = 345.00; + BigDecimal expectedAmount = new BigDecimal("28744.40"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + } + + @Test + public void ConvertRupeeToCanadianDollar() { + String country1 = "INR"; + String country2 = "CAD"; + double amount = 97.47; + BigDecimal expectedAmount = new BigDecimal("1.89"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + } + + @Test + + public void ConvertCanadianDollarToSingaporeDollar(){ + String country1 = "CAD"; + String country2 = "SGD"; + double amount = 1000.00; + BigDecimal expectedAmount = new BigDecimal("1083.34"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + } + + @Test + public void ConvertSingaporeDollarToSwissFranc(){ + String country1 = "SGD"; + String country2 = "CHF"; + double amount = 1526.35; + BigDecimal expectedAmount = new BigDecimal("1078.06"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + } + + @Test + public void ConvertSwissFranctoMalaysianRinggit(){ + String country1 = "CHF"; + String country2 = "MYR"; + double amount = 345.00; + BigDecimal expectedAmount = new BigDecimal("1526.89"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + } + + @Test + public void ConvertMalaysianRinggitToJapaneseYen(){ + String country1 = "MYR"; + String country2 = "JPY"; + double amount = 345.00; + BigDecimal expectedAmount = new BigDecimal("8940.68"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + } + + @Test + + public void ConvertJapaneseYenToChineseYuan(){ + String country1 = "JPY"; + String country2 = "CNY"; + double amount = 345.00; + BigDecimal expectedAmount = new BigDecimal("20.61"); + + //:When + BigDecimal actualAmount = testRate.conversion(country1, country2, amount); + + //:Then + Assert.assertEquals(expectedAmount, actualAmount); + + } +} diff --git a/target/classes/Exchange.class b/target/classes/Exchange.class new file mode 100644 index 0000000..bbf79db Binary files /dev/null and b/target/classes/Exchange.class differ diff --git a/target/classes/Rate$1.class b/target/classes/Rate$1.class new file mode 100644 index 0000000..5bf570c Binary files /dev/null and b/target/classes/Rate$1.class differ diff --git a/target/classes/Rate.class b/target/classes/Rate.class new file mode 100644 index 0000000..a8524dd Binary files /dev/null and b/target/classes/Rate.class differ diff --git a/target/test-classes/RateTest.class b/target/test-classes/RateTest.class new file mode 100644 index 0000000..bcbea59 Binary files /dev/null and b/target/test-classes/RateTest.class differ