CurrencyConverterTest.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import org.junit.jupiter.api.Test;
  2. import static org.junit.jupiter.api.Assertions.assertEquals;
  3. public class CurrencyConverterTest {
  4. CurrencyConverter cc = new CurrencyConverter();
  5. double delta = 0.01;
  6. @Test
  7. public void convertDollartoEuroTest(){
  8. double expected = 2.12;
  9. double actual = cc.convert(CurrencyEnum.US_DOLLAR.getRatio(), CurrencyEnum.EURO.getRatio(),2.00);
  10. assertEquals(expected,actual,delta);
  11. }
  12. @Test
  13. public void convertEurotoDollarTest(){
  14. double expected=4.70;
  15. double actual = cc.convert(CurrencyEnum.EURO.getRatio(),CurrencyEnum.US_DOLLAR.getRatio(),5);
  16. assertEquals(expected,actual,delta);
  17. }
  18. @Test
  19. public void convertEurotoBritishPoundTest(){
  20. double expected = 11.46;
  21. double actual = cc.convert(CurrencyEnum.EURO.getRatio(),CurrencyEnum.BRITISH_POUND.getRatio(),10);
  22. assertEquals(expected,actual,delta);
  23. }
  24. @Test
  25. public void convertBritishPoundtoIndianRupeeTest(){
  26. double expected = 12.00;
  27. double actual = cc.convert(CurrencyEnum.BRITISH_POUND.getRatio(),CurrencyEnum.INDIAN_RUPEE.getRatio(),1000);
  28. assertEquals(expected, actual, delta);
  29. }
  30. @Test
  31. public void convertRupeetoCanadianDollarTest(){
  32. double expected = 3157.21;
  33. double actual = cc.convert(CurrencyEnum.INDIAN_RUPEE.getRatio(),CurrencyEnum.CANADIAN_DOLLAR.getRatio(),61);
  34. assertEquals(expected,actual, delta);
  35. }
  36. @Test
  37. public void convertCanadianDollartoSingaporeDollarTest(){
  38. double expected = 72.00;
  39. double actual = cc.convert(CurrencyEnum.CANADIAN_DOLLAR.getRatio(), CurrencyEnum.SINGAPORE.getRatio(),78);
  40. assertEquals(expected,actual,delta);
  41. }
  42. @Test
  43. public void convertSingaporeDollartoSwissFrancTest(){
  44. double expected = 94.86;
  45. double actual = cc.convert(CurrencyEnum.SINGAPORE.getRatio(), CurrencyEnum.SWISS_FRANC.getRatio(),67);
  46. assertEquals(expected, actual, delta);
  47. }
  48. @Test
  49. public void convertSwissFranctoMalaysianRinggit(){
  50. double expected = 24.40;
  51. double actual = cc.convert(CurrencyEnum.SWISS_FRANC.getRatio(), CurrencyEnum.MALAYSIAN_RINGGIT.getRatio(),105);
  52. assertEquals(expected,actual,delta);
  53. }
  54. @Test
  55. public void convertMalaysianRinggittoJapaneseYenTest(){
  56. double expected = 192.93;
  57. double actual = cc.convert(CurrencyEnum.MALAYSIAN_RINGGIT.getRatio(),CurrencyEnum.JAPANESE_YEN.getRatio(),5000);
  58. assertEquals(expected, actual, delta);
  59. }
  60. @Test
  61. public void convertJapaneseYentoChineseYuanRenminbiTest(){
  62. double expected = 4184.97;
  63. double actual = cc.convert(CurrencyEnum.JAPANESE_YEN.getRatio(), CurrencyEnum.CHINESE_YUAN_RENMINBI.getRatio(), 250);
  64. assertEquals(expected, actual, delta);
  65. }
  66. }