Skip to content
Open

Done #80

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
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@
<groupId>io.zipcoder</groupId>
<artifactId>wu-tang-financial</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
62 changes: 62 additions & 0 deletions src/main/java/Rate.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
150 changes: 150 additions & 0 deletions src/test/java/RateTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Binary file added target/classes/Rate.class
Binary file not shown.
Binary file added target/test-classes/RateTest.class
Binary file not shown.