Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<version>1.0-SNAPSHOT</version>

<dependencies>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
38 changes: 38 additions & 0 deletions src/main/java/CurrencyExchange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.TreeMap;

import static javax.swing.UIManager.put;
//Currency converter
public class CurrencyExchange {

private HashMap<String, Double> currencyMap;

{
currencyMap = new HashMap<String, Double>() {
{
put("USD", 1.00); //US Dollar
put("EURO", 0.94); //Euro
put("POUND", 0.82); //British Pound
put("RUPEE", 68.32); //Indian Rupee
put("AUD", 1.35); //Australian Dollar
put("CAD", 1.32); //Canadian Dollar
put("SGD", 1.43); //Singapore Dollar
put("FRANC", 1.01); //Swiss Franc
put("RINGGIT", 4.47); //Malaysian Ringgit
put("YEN", 115.84); //Japanese Yen
put("RENMINBI", 6.92);//Chinese Yuan Renminbi

}
};
}

public double conversionFormula (String nation1, String nation2, double amount){

double convertedAmount = (currencyMap.get(nation2)) / (currencyMap.get(nation1)) * amount;

return convertedAmount;

}

}
Empty file removed src/main/java/DELETEME
Empty file.
Empty file removed src/test/java/DELETEME
Empty file.
91 changes: 91 additions & 0 deletions src/test/java/TestingRates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.math.BigDecimal;

import static com.sun.tools.doclint.Entity.delta;

public class TestingRates {

CurrencyExchange testRate;

@Before
public void setUp() {
testRate = new CurrencyExchange();
}

@Test
public void testUSDtoEuro() {
double expectedAmount = 0.94;
double actualAmount = testRate.conversionFormula("USD", "EURO", 1.00);
Assert.assertEquals("Convert Dollar to Euro",expectedAmount, actualAmount, 0.1);
}

@Test
public void testEUROtoUSD() {
double expectedAmount = 53.20;
double actualAmount = testRate.conversionFormula("EURO", "USD", 50.00);
Assert.assertEquals("Convert Euro to US Dollar", expectedAmount, actualAmount, 0.1);
}

@Test
public void testEUROtoPOUND () {
double expectedAmount = 21.80;
double actualAmount = testRate.conversionFormula("EURO", "POUND", 25.00);
Assert.assertEquals("Convert Rupee to Canadian Dollar", expectedAmount, actualAmount, 0.1);
}

@Test
public void testPOUNDtoRUPEE () {
double expectedAmount = 2916.10;
double actualAmount = testRate.conversionFormula("POUND", "RUPEE", 35.00);
Assert.assertEquals("Convert British Pound to Indian Rupee", expectedAmount, actualAmount, 0.1);
}

@Test
public void testRUPEEtoCAD () {
double expectedAmount = 1.55;
double actualAmount = testRate.conversionFormula("RUPEE", "CAD", 80.00);
Assert.assertEquals("Convert Rupee to Canadian Dollar", expectedAmount, actualAmount, 0.1);
}

@Test
public void testCADtoSGD () {
double expectedAmount = 107.25;
double actualAmount = testRate.conversionFormula("CAD", "SGD", 99.00);
Assert.assertEquals(
"Convert Canadian Dollar to Singapore Dollar", expectedAmount, actualAmount, 0.1);
}

@Test
public void testSGDtoFRANC () {
double expectedAmount = 47.09;
double actualAmount = testRate.conversionFormula("SGD", "FRANC", 66.66);
Assert.assertEquals(
"Convert Singapore Dollar to Swiss Franc",expectedAmount, actualAmount, 0.1);
}

@Test
public void testFRANCtoRINGGIT () {
double expectedAmount = 4425.75;
double actualAmount = testRate.conversionFormula("FRANC", "RINGGIT", 1000.00);
Assert.assertEquals(
"Convert Swiss Franc to Malaysian Ringgit",expectedAmount, actualAmount, 0.1);
}

@Test
public void testRINGGITtoYEN () {
double expectedAmount = 259.15;
double actualAmount = testRate.conversionFormula("RINGGIT", "YEN", 10.00);
Assert.assertEquals(
"Convert Malaysian Ringgit to Japanese Yen",expectedAmount, actualAmount, 0.1);
}

@Test
public void testYENtoRENMINBI () {
double expectedAmount = 2.99;
double actualAmount = testRate.conversionFormula("YEN", "RENMINBI", 50.00);
Assert.assertEquals(
"Convert Japanese Yen to Chinese Yuan Renminb", expectedAmount, actualAmount, 0.1);
}
}
Binary file added target/classes/CurrencyExchange$1.class
Binary file not shown.
Binary file added target/classes/CurrencyExchange.class
Binary file not shown.
Binary file added target/test-classes/TestingRates.class
Binary file not shown.