123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class CurrencyConverterTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class CurrencyConverterTest
  12. {
  13. @Test
  14. public void testUSDtoEUR(){
  15. //Given
  16. CurrencyConverter converter = new CurrencyConverter(Currency.USD);
  17. //Actual
  18. double actual = converter.convert(1500.0, Currency.EUR);
  19. //Expected
  20. double expected = 1500.0 * (1.0/1.0) * 0.94;
  21. assertEquals(expected, actual, 1E-9);
  22. }
  23. @Test
  24. public void testEURtoUSD(){
  25. //Given
  26. CurrencyConverter converter = new CurrencyConverter(Currency.EUR);
  27. //Actual
  28. double actual = converter.convert(3200.0, Currency.USD);
  29. //Expected
  30. double expected = 3200.0 * (1.0/0.94) * 1.0;
  31. assertEquals(expected, actual, 1E-9);
  32. }
  33. @Test
  34. public void testEURtoGBP(){
  35. //Given
  36. CurrencyConverter converter = new CurrencyConverter(Currency.EUR);
  37. //Actual
  38. double actual = converter.convert(2700.50, Currency.GBP);
  39. //Expected
  40. double expected = 2700.50 * (1.0/0.94) * 0.82;
  41. assertEquals(expected, actual, 1E-9);
  42. }
  43. @Test
  44. public void testGBPtoINR(){
  45. //Given
  46. CurrencyConverter converter = new CurrencyConverter(Currency.GBP);
  47. //Actual
  48. double actual = converter.convert(326.75, Currency.INR);
  49. //Expected
  50. double expected = 326.75 * (1.0/0.82) * 68.32;
  51. assertEquals(expected, actual, 1E-9);
  52. }
  53. @Test
  54. public void testINRtoCAD(){
  55. //Given
  56. CurrencyConverter converter = new CurrencyConverter(Currency.INR);
  57. //Actual
  58. double actual = converter.convert(400.56, Currency.CAD);
  59. //Expected
  60. double expected = 400.56 * (1.0/68.32) * 1.32;
  61. assertEquals(expected, actual, 1E-9);
  62. }
  63. @Test
  64. public void testCADtoSGD(){
  65. //Given
  66. CurrencyConverter converter = new CurrencyConverter(Currency.CAD);
  67. //Actual
  68. double actual = converter.convert(1235.43, Currency.SGD);
  69. //Expected
  70. double expected = 1235.43 * (1.0/1.32) * 1.43;
  71. assertEquals(expected, actual, 1E-9);
  72. }
  73. @Test
  74. public void testSGDtoCHF(){
  75. //Given
  76. CurrencyConverter converter = new CurrencyConverter(Currency.SGD);
  77. //Actual
  78. double actual = converter.convert(1575.25, Currency.CHF);
  79. //Expected
  80. double expected = 1575.25 * (1.0/1.43) * 1.01;
  81. assertEquals(expected, actual, 1E-9);
  82. }
  83. @Test
  84. public void testCHFtoMYR(){
  85. //Given
  86. CurrencyConverter converter = new CurrencyConverter(Currency.CHF);
  87. //Actual
  88. double actual = converter.convert(1575.25, Currency.MYR);
  89. //Expected
  90. double expected = 1575.25 * (1.0/1.01) * 4.47;
  91. assertEquals(expected, actual, 1E-9);
  92. }
  93. @Test
  94. public void testMYRtoJPY(){
  95. //Given
  96. CurrencyConverter converter = new CurrencyConverter(Currency.MYR);
  97. //Actual
  98. double actual = converter.convert(1575.25, Currency.JPY);
  99. //Expected
  100. double expected = 1575.25 * (1.0/4.47) * 115.84;
  101. assertEquals(expected, actual, 1E-9);
  102. }
  103. @Test
  104. public void testJPYtoCNY(){
  105. //Given
  106. CurrencyConverter converter = new CurrencyConverter(Currency.JPY);
  107. //Actual
  108. double actual = converter.convert(1575.25, Currency.CNY);
  109. //Expected
  110. double expected = 1575.25 * (1.0/115.84) * 6.92;
  111. assertEquals(expected, actual, 1E-9);
  112. }
  113. }