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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions src/main/java/WuTangCurrency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.text.DecimalFormat;

public class WuTangCurrency {


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

public static double currencyExchangeFormula(double amountFrom, double rateTo, double rateFrom) {

double amountTo = amountFrom * (rateFrom / rateTo);

// tried rounding to 2 decimal places but was unsuccessful
// double amountToRounded = (double)Math.round(amountTo * 100d) / 100d;

System.out.println(amountTo);
return amountTo;
}

}


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

public class WuTangCurrencyTest {

WuTangCurrency exchangeRate = new WuTangCurrency(); //created to test currencyExchangeFormula()

@Test
public void usDollarToEuroTest() {
double amountFrom = 1.00;
double expected = 0.94;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.US_DOLLAR, exchangeRate.EURO);
Assert.assertEquals(expected, actual, 0.01); //delta measures accuracy, within .01
}

@Test
public void EuroToUsDollarTest() {
double amountFrom = 0.94;
double expected = 1.00;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.US_DOLLAR);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void EuroToBritishPoundTest() {
double amountFrom = 0.94;
double expected = 0.82;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.BRITISH);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void BritishPoundToINDIAN_RUPEETest() {
double amountFrom = 0.82;
double expected = 68.32;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.BRITISH, exchangeRate.INDIAN_RUPEE);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void IndianRupeeToCanadianDollarTest(){
double amountFrom = 68.82;
double expected = 1.32;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.INDIAN_RUPEE, exchangeRate.CANADIAN_DOLLAR);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void CanadianDollarToSingaporeDollarTest(){
double amountFrom = 1.32;
double expected = 1.43;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.CANADIAN_DOLLAR, exchangeRate.SINGAPORE_DOLLAR);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void SingaporeDollarToSwissFrancTest(){
double amountFrom = 1.43;
double expected = 1.01;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SINGAPORE_DOLLAR, exchangeRate.SWISS_FRANC);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void SwissFrancToMalaysianRinggitTest(){
double amountFrom = 1.01;
double expected = 4.47;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SWISS_FRANC, exchangeRate.MALAYSIAN_RINGGIT);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void MalaysianRinggitToJapaneseYenTest(){
double amountFrom = 4.47;
double expected = 115.84;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.MALAYSIAN_RINGGIT, exchangeRate.JAPANESE_YEN);
Assert.assertEquals(expected, actual, 0.01);
}

@Test
public void JapaneseYenToChineseYuanRenminbiTest(){
double amountFrom = 115.84;
double expected = 6.92;
double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.JAPANESE_YEN, exchangeRate.CHINESE_YUAN_RENMINBI);
Assert.assertEquals(expected, actual, 0.01);
}


}
Binary file added target/classes/WuTangCurrency.class
Binary file not shown.
Binary file added target/test-classes/WuTangCurrencyTest.class
Binary file not shown.