Skip to content

Commit 1f324e6

Browse files
Luis RomeroLuis Romero
authored andcommitted
255pm all tests worked, on 0213
1 parent 4512638 commit 1f324e6

File tree

5 files changed

+131
-1
lines changed

5 files changed

+131
-1
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<artifactId>wu-tang-financial</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

11-
<dependencies>
1211

12+
<dependencies>
13+
<dependency>
14+
<groupId>junit</groupId>
15+
<artifactId>junit</artifactId>
16+
<version>RELEASE</version>
17+
</dependency>
1318
</dependencies>
1419
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class CurrencyExchange {
2+
3+
public static final double US_DOLLAR = 1.00;
4+
public static final double EURO = 0.94;
5+
public static final double BRITISH_POUND = 0.82;
6+
public static final double INDIAN_RUPEE = 68.32;
7+
public static final double AUSTRALIAN_DOLLAR = 1.35;
8+
public static final double CANADIAN_DOLLAR = 1.32;
9+
public static final double SINGAPORE_DOLLAR = 1.43;
10+
public static final double SWISS_FRANC = 1.01;
11+
public static final double MALAYSIAN_RINGGIT = 4.47;
12+
public static final double JAPANESE_YEN = 115.84;
13+
public static final double CHINESE_YUAN_RENMINBI = 6.92;
14+
15+
public static double convertFromTo(double fromAmount, double fromCurrencyRate, double toCurrencyRate) {
16+
17+
double toAmount = toCurrencyRate * (fromAmount / fromCurrencyRate);
18+
return toAmount;
19+
}
20+
21+
22+
23+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
import org.junit.Before;
4+
5+
/**
6+
* Created by Luis J. Romero on 2/13/2018.
7+
*/
8+
9+
public class CurrencyExchangeTest {
10+
11+
CurrencyExchange ce = new CurrencyExchange();
12+
13+
@Test
14+
public void testConvertDollarToEuro() {
15+
double fromAmount = 1.00;
16+
double expected = ce.convertFromTo(fromAmount, ce.US_DOLLAR, ce.EURO);
17+
double actual = 0.94;
18+
Assert.assertEquals(expected, actual, 0.001);
19+
}
20+
21+
@Test
22+
public void testConvertEuroToDollar() {
23+
double fromAmount = 0.94;
24+
double expected = ce.convertFromTo(fromAmount, ce.EURO, ce.US_DOLLAR);
25+
double actual = 1.00;
26+
Assert.assertEquals(expected, actual, 0.001);
27+
}
28+
29+
@Test
30+
public void testConvertEuroToBritishPound() {
31+
double fromAmount = 0.94;
32+
double expected = ce.convertFromTo(fromAmount, ce.EURO, ce.BRITISH_POUND);
33+
double actual = 0.82;
34+
Assert.assertEquals(expected, actual, 0.001);
35+
}
36+
37+
@Test
38+
public void testConvertBritishPoundToIndianRupee() {
39+
double fromAmount = 0.82;
40+
double expected = ce.convertFromTo(fromAmount, ce.BRITISH_POUND, ce.INDIAN_RUPEE);
41+
double actual = 68.32;
42+
Assert.assertEquals(expected, actual, 0.001);
43+
}
44+
45+
@Test
46+
public void testConvertRupeeToCanadianDollar() {
47+
double fromAmount = 68.32;
48+
double expected = ce.convertFromTo(fromAmount, ce.INDIAN_RUPEE, ce.CANADIAN_DOLLAR);
49+
double actual = 1.32;
50+
Assert.assertEquals(expected, actual, 0.001);
51+
}
52+
53+
// Added Australian Dollar to Canadian Dollar, to include Australian Dollar in tests
54+
@Test
55+
public void testConvertAustralianDollarToCanadianDollar() {
56+
double fromAmount = 1.35;
57+
double expected = ce.convertFromTo(fromAmount, ce.AUSTRALIAN_DOLLAR, ce.CANADIAN_DOLLAR);
58+
double actual = 1.32;
59+
Assert.assertEquals(expected, actual, 0.001);
60+
}
61+
62+
@Test
63+
public void testConvertCanadianDollarToSingaporeDollar() {
64+
double fromAmount = 1.32;
65+
double expected = ce.convertFromTo(fromAmount, ce.CANADIAN_DOLLAR, ce.SINGAPORE_DOLLAR);
66+
double actual = 1.43;
67+
Assert.assertEquals(expected, actual, 0.001);
68+
}
69+
70+
@Test
71+
public void testConvertSingaporeDollarToSwissFranc() {
72+
double fromAmount = 1.43;
73+
double expected = ce.convertFromTo(fromAmount, ce.SINGAPORE_DOLLAR, ce.SWISS_FRANC);
74+
double actual = 1.01;
75+
Assert.assertEquals(expected, actual, 0.001);
76+
}
77+
78+
@Test
79+
public void testConvertSwissFrancToMalaysianRinggit() {
80+
double fromAmount = 1.01;
81+
double expected = ce.convertFromTo(fromAmount, ce.SWISS_FRANC, ce.MALAYSIAN_RINGGIT);
82+
double actual = 4.47;
83+
Assert.assertEquals(expected, actual, 0.001);
84+
}
85+
86+
@Test
87+
public void testConvertMalaysianRinggitToJapaneseYen() {
88+
double fromAmount = 4.47;
89+
double expected = ce.convertFromTo(fromAmount, ce.MALAYSIAN_RINGGIT, ce.JAPANESE_YEN);
90+
double actual = 115.84;
91+
Assert.assertEquals(expected, actual, 0.001);
92+
}
93+
94+
@Test
95+
public void testConvertJapaneseYenToChineseYuanRenminbi() {
96+
double fromAmount = 115.84;
97+
double expected = ce.convertFromTo(fromAmount, ce.JAPANESE_YEN, ce.CHINESE_YUAN_RENMINBI);
98+
double actual = 6.92;
99+
Assert.assertEquals(expected, actual, 0.001);
100+
}
101+
102+
}
934 Bytes
Binary file not shown.
2.74 KB
Binary file not shown.

0 commit comments

Comments
 (0)