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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<artifactId>wu-tang-financial</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
23 changes: 23 additions & 0 deletions src/main/java/CurrencyExchange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class CurrencyExchange {

public static final double US_DOLLAR = 1.00;
public static final double EURO = 0.94;
public static final double BRITISH_POUND = 0.82;
public static final double INDIAN_RUPEE = 68.32;
public static final double AUSTRALIAN_DOLLAR = 1.35;
public static final double CANADIAN_DOLLAR = 1.32;
public static final double SINGAPORE_DOLLAR = 1.43;
public static final double SWISS_FRANC = 1.01;
public static final double MALAYSIAN_RINGGIT = 4.47;
public static final double JAPANESE_YEN = 115.84;
public static final double CHINESE_YUAN_RENMINBI = 6.92;

public static double convertFromTo(double fromAmount, double fromCurrencyRate, double toCurrencyRate) {

double toAmount = toCurrencyRate * (fromAmount / fromCurrencyRate);
return toAmount;
}



}
102 changes: 102 additions & 0 deletions src/test/java/CurrencyExchangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.Before;

/**
* Created by Luis J. Romero on 2/13/2018.
*/

public class CurrencyExchangeTest {

CurrencyExchange ce = new CurrencyExchange();

@Test
public void testConvertDollarToEuro() {
double fromAmount = 1.00;
double expected = 0.94;
double actual = ce.convertFromTo(fromAmount, ce.US_DOLLAR, ce.EURO);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertEuroToDollar() {
double fromAmount = 0.94;
double expected = 1.00;
double actual = ce.convertFromTo(fromAmount, ce.EURO, ce.US_DOLLAR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertEuroToBritishPound() {
double fromAmount = 0.94;
double expected = 0.82;
double actual = ce.convertFromTo(fromAmount, ce.EURO, ce.BRITISH_POUND);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertBritishPoundToIndianRupee() {
double fromAmount = 0.82;
double expected = 68.32;
double actual = ce.convertFromTo(fromAmount, ce.BRITISH_POUND, ce.INDIAN_RUPEE);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertRupeeToCanadianDollar() {
double fromAmount = 68.32;
double expected = 1.32;
double actual = ce.convertFromTo(fromAmount, ce.INDIAN_RUPEE, ce.CANADIAN_DOLLAR);
Assert.assertEquals(expected, actual, 0.001);
}

// Added Australian Dollar to Canadian Dollar, to include Australian Dollar in tests
@Test
public void testConvertAustralianDollarToCanadianDollar() {
double fromAmount = 1.35;
double expected = 1.32;
double actual = ce.convertFromTo(fromAmount, ce.AUSTRALIAN_DOLLAR, ce.CANADIAN_DOLLAR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertCanadianDollarToSingaporeDollar() {
double fromAmount = 1.32;
double expected = 1.43;
double actual = ce.convertFromTo(fromAmount, ce.CANADIAN_DOLLAR, ce.SINGAPORE_DOLLAR);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertSingaporeDollarToSwissFranc() {
double fromAmount = 1.43;
double expected = 1.01;
double actual = ce.convertFromTo(fromAmount, ce.SINGAPORE_DOLLAR, ce.SWISS_FRANC);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertSwissFrancToMalaysianRinggit() {
double fromAmount = 1.01;
double expected = 4.47;
double actual = ce.convertFromTo(fromAmount, ce.SWISS_FRANC, ce.MALAYSIAN_RINGGIT);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertMalaysianRinggitToJapaneseYen() {
double fromAmount = 4.47;
double expected = 115.84;
double actual = ce.convertFromTo(fromAmount, ce.MALAYSIAN_RINGGIT, ce.JAPANESE_YEN);
Assert.assertEquals(expected, actual, 0.001);
}

@Test
public void testConvertJapaneseYenToChineseYuanRenminbi() {
double fromAmount = 115.84;
double expected = 6.92;
double actual = ce.convertFromTo(fromAmount, ce.JAPANESE_YEN, ce.CHINESE_YUAN_RENMINBI);
Assert.assertEquals(expected, actual, 0.001);
}

}
Binary file added target/classes/CurrencyExchange.class
Binary file not shown.
Binary file added target/test-classes/CurrencyExchangeTest.class
Binary file not shown.