diff --git a/pom.xml b/pom.xml index 682d6db..cb902f2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,8 +7,30 @@ io.zipcoder wu-tang-financial 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/Rate.java b/src/main/java/Rate.java new file mode 100644 index 0000000..9eafb0f --- /dev/null +++ b/src/main/java/Rate.java @@ -0,0 +1,62 @@ +public class Rate { + + //created finals because the rates do not change and no one else needs to change them + private static final double USD = 1.00; + private static final double EUR = 0.94; + private static final double GBP = 0.82; + private static final double INR = 68.32; + private static final double AUD = 1.35; + private static final double CAD = 1.32; + private static final double SGD = 1.43; + private static final double CHF = 1.01; + private static final double MYR = 4.47; + private static final double JPY = 115.84; + private static final double CNY = 6.92; + + + //created my action that will convert the rates and be used in RateTest + public double rateConverter(double value, String start, String end){ + + return value * getRateOfExchange(end)/getRateOfExchange(start); + + } + //used a switch statement to hold all the values and go through each one. + private double getRateOfExchange(String rateConverter){ + + switch (rateConverter){ + case "USD": + return USD; + + case "EUR": + return EUR; + + case "GBP": + return GBP; + + case "INR": + return INR; + + case "AUD": + return AUD; + + case "CAD": + return CAD; + + case "SGD": + return SGD; + + case "CHF": + return CHF; + + case "MYR": + return MYR; + + case "JPY": + return JPY; + + case "CNY": + return CNY; + } + return 0; + } +} diff --git a/src/test/java/RateTest.java b/src/test/java/RateTest.java new file mode 100644 index 0000000..993ff40 --- /dev/null +++ b/src/test/java/RateTest.java @@ -0,0 +1,150 @@ +import org.junit.Assert; +import org.junit.Test; + + +public class RateTest { + + @Test + public void convertDollarToEuro() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1; + double expectedValue = .94; + String startingCurrency = "USD"; + String endingCurrency = "EUR"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertEuroToDollar() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = .94; + double expectedValue = 1; + String startingCurrency = "EUR"; + String endingCurrency = "USD"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertEuroToGreatBritishPd() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = .94; + double expectedValue = .82; + String startingCurrency = "EUR"; + String endingCurrency = "GBP"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertIndianRToCanadianDollar() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 68.32; + double expectedValue = 1.32; + String startingCurrency = "INR"; + String endingCurrency = "CAD"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertCanadianDollarToSwissFranc() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1.32; + double expectedValue = 1.01; + String startingCurrency = "CAD"; + String endingCurrency = "CHF"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertSwissFrancToMalayR() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1.01; + double expectedValue = 4.47; + String startingCurrency = "CHF"; + String endingCurrency = "MYR"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertMalayRToJYen() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 4.47; + double expectedValue = 115.84; + String startingCurrency = "MYR"; + String endingCurrency = "JPY"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertJYenToChineseYR() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 115.84; + double expectedValue = 6.92; + String startingCurrency = "JPY"; + String endingCurrency = "CNY"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } +} diff --git a/target/classes/Rate.class b/target/classes/Rate.class new file mode 100644 index 0000000..02cefbb 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..33210ba Binary files /dev/null and b/target/test-classes/RateTest.class differ