diff --git a/pom.xml b/pom.xml index 682d6db..754f707 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,26 @@ wu-tang-financial 1.0-SNAPSHOT - - + + + junit + junit + 4.12 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + \ No newline at end of file diff --git a/src/main/java/CurrencyConverter.java b/src/main/java/CurrencyConverter.java new file mode 100644 index 0000000..88ea18a --- /dev/null +++ b/src/main/java/CurrencyConverter.java @@ -0,0 +1,50 @@ +public class CurrencyConverter { + + 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 RUPEE = 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 FRANC = 1.01; + private static final double RINGGIT = 4.47; + private static final double YEN = 115.84; + private static final double YUAN = 6.92; + + + public double convert(double value, String starting, String ending) { + + return value * getExchangeRate(ending)/getExchangeRate(starting); + } + + private double getExchangeRate(String currency) { + switch (currency) { + case "USD": + return USD; + case "EUR": + return EUR; + case "GBP": + return GBP; + case "RUPEE": + return RUPEE; + case "AUD": + return AUD; + case "CAD": + return CAD; + case "SGD": + return SGD; + case "FRANC": + return FRANC; + case "RINGGIT": + return RINGGIT; + case "YEN": + return YEN; + case "YUAN": + return YUAN; + + } + + return 0; + } +} diff --git a/src/main/java/DELETEME b/src/main/java/DELETEME deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/CurrencyConverterTest.java b/src/test/java/CurrencyConverterTest.java new file mode 100644 index 0000000..96096f5 --- /dev/null +++ b/src/test/java/CurrencyConverterTest.java @@ -0,0 +1,166 @@ +import org.junit.Assert; +import org.junit.Test; + +public class CurrencyConverterTest { + + @Test + public void convert_DollarToEuro() { + // Arrange + double initialValue = 1; + double expectedValue = .94; + String startingCurrency = "USD"; + String endingCurrency = "EUR"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_EuroToDollar() { + // Arrange + double initialValue = .94; + double expectedValue = 1; + String startingCurrency = "EUR"; + String endingCurrency = "USD"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + @Test + public void convert_EuroToGBP() { + // Arrange + double initialValue = .94; + double expectedValue = .82; + String startingCurrency = "EUR"; + String endingCurrency = "GBP"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_GBPToRUPEE() { + // Arrange + double initialValue = .82; + double expectedValue = 68.32; + String startingCurrency = "GBP"; + String endingCurrency = "RUPEE"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_RUPEEToCAD() { + // Arrange + double initialValue = 68.32; + double expectedValue = 1.32; + String startingCurrency = "RUPEE"; + String endingCurrency = "CAD"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_CADToSGD() { + // Arrange + double initialValue = 1.32; + double expectedValue = 1.43; + String startingCurrency = "CAD"; + String endingCurrency = "SGD"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_SGDToFRANC() { + // Arrange + double initialValue = 1.43; + double expectedValue = 1.01; + String startingCurrency = "SGD"; + String endingCurrency = "FRANC"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_FRANCToRINGGIT() { + // Arrange + double initialValue = 1.01; + double expectedValue = 4.47; + String startingCurrency = "FRANC"; + String endingCurrency = "RINGGIT"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_RINGGIToYEN() { + // Arrange + double initialValue = 4.47; + double expectedValue = 115.84; + String startingCurrency = "RINGGIT"; + String endingCurrency = "YEN"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + @Test + public void convert_YENToYUAN() { + // Arrange + double initialValue = 115.84; + double expectedValue = 6.92; + String startingCurrency = "YEN"; + String endingCurrency = "YUAN"; + + // Act + CurrencyConverter currencyConverter = new CurrencyConverter(); + double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency); + + // Assert + Assert.assertEquals(expectedValue, actual, .000000001); + } + + +} diff --git a/src/test/java/DELETEME b/src/test/java/DELETEME deleted file mode 100644 index e69de29..0000000 diff --git a/target/classes/CurrencyConverter.class b/target/classes/CurrencyConverter.class new file mode 100644 index 0000000..64f4792 Binary files /dev/null and b/target/classes/CurrencyConverter.class differ diff --git a/target/test-classes/CurrencyConverterTest.class b/target/test-classes/CurrencyConverterTest.class new file mode 100644 index 0000000..4abe812 Binary files /dev/null and b/target/test-classes/CurrencyConverterTest.class differ