123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
-
-
- import static org.junit.Assert.*;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
-
- /**
- * The test class CurrencyConverterTest.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class CurrencyConverterTest
- {
- @Test
- public void testUSDtoEUR(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.USD);
-
- //Actual
- double actual = converter.convert(1500.0, Currency.EUR);
-
- //Expected
- double expected = 1500.0 * (1.0/1.0) * 0.94;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testEURtoUSD(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.EUR);
-
- //Actual
- double actual = converter.convert(3200.0, Currency.USD);
-
- //Expected
- double expected = 3200.0 * (1.0/0.94) * 1.0;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testEURtoGBP(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.EUR);
-
- //Actual
- double actual = converter.convert(2700.50, Currency.GBP);
-
- //Expected
- double expected = 2700.50 * (1.0/0.94) * 0.82;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testGBPtoINR(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.GBP);
-
- //Actual
- double actual = converter.convert(326.75, Currency.INR);
-
- //Expected
- double expected = 326.75 * (1.0/0.82) * 68.32;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testINRtoCAD(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.INR);
-
- //Actual
- double actual = converter.convert(400.56, Currency.CAD);
-
- //Expected
- double expected = 400.56 * (1.0/68.32) * 1.32;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testCADtoSGD(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.CAD);
-
- //Actual
- double actual = converter.convert(1235.43, Currency.SGD);
-
- //Expected
- double expected = 1235.43 * (1.0/1.32) * 1.43;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testSGDtoCHF(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.SGD);
-
- //Actual
- double actual = converter.convert(1575.25, Currency.CHF);
-
- //Expected
- double expected = 1575.25 * (1.0/1.43) * 1.01;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testCHFtoMYR(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.CHF);
-
- //Actual
- double actual = converter.convert(1575.25, Currency.MYR);
-
- //Expected
- double expected = 1575.25 * (1.0/1.01) * 4.47;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testMYRtoJPY(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.MYR);
-
- //Actual
- double actual = converter.convert(1575.25, Currency.JPY);
-
- //Expected
- double expected = 1575.25 * (1.0/4.47) * 115.84;
- assertEquals(expected, actual, 1E-9);
- }
-
- @Test
- public void testJPYtoCNY(){
- //Given
- CurrencyConverter converter = new CurrencyConverter(Currency.JPY);
-
- //Actual
- double actual = converter.convert(1575.25, Currency.CNY);
-
- //Expected
- double expected = 1575.25 * (1.0/115.84) * 6.92;
- assertEquals(expected, actual, 1E-9);
- }
- }
|