CurrencyConverterTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import org.junit.Assert;
  2. import org.junit.Before;
  3. import org.junit.Test;
  4. import java.util.Arrays;
  5. public class CurrencyConverterTest {
  6. Double USDOLLAREXR = 1.00;
  7. Double EUROEXR = 0.94;
  8. Double BRITPOUNDEXR = 0.82;
  9. Double INDIARUPEEEXR = 68.32;
  10. Double AUSTDOLLAREXR = 1.35;
  11. Double CANADADOLLAREXR = 1.32;
  12. Double SINGDOLLAREXR = 1.43;
  13. Double SWISSFRANCEXR = 1.01;
  14. Double MALAYSRINGGITEXR = 4.47;
  15. Double JAPANYENEXR = 115.84;
  16. Double CHINAYUANEXR = 6.92;
  17. @Test
  18. public void testDollarToEuro(){
  19. Double actual = CurrencyConverter.convertCurrency(50_000.00, USDOLLAREXR, EUROEXR);
  20. Double expected = 47_000.00;
  21. Assert.assertEquals(expected, actual);
  22. }
  23. @Test
  24. public void testEuroToDollar(){
  25. Double actual = CurrencyConverter.convertCurrency(50000.00, EUROEXR, USDOLLAREXR);
  26. Double expected = 53_191.49;
  27. Assert.assertEquals(expected, actual);
  28. }
  29. @Test
  30. public void testEuroToBritishPound(){
  31. Double actual = CurrencyConverter.convertCurrency(50000.00, EUROEXR, BRITPOUNDEXR);
  32. Double expected = 43_617.02;
  33. Assert.assertEquals(expected, actual);
  34. }
  35. @Test
  36. public void testBritishPoundToIndianRupee(){
  37. Double actual = CurrencyConverter.convertCurrency(50000.00, BRITPOUNDEXR, INDIARUPEEEXR);
  38. Double expected = 4_165_853.66;
  39. Assert.assertEquals(expected, actual);
  40. }
  41. @Test
  42. public void testRupeeToCanadianDollar(){
  43. Double actual = CurrencyConverter.convertCurrency(50000.00, INDIARUPEEEXR, CANADADOLLAREXR);
  44. Double expected = 966.04;
  45. Assert.assertEquals(expected, actual);
  46. }
  47. @Test
  48. public void testCanadianDollarToSingaporeDollar(){
  49. Double actual = CurrencyConverter.convertCurrency(50000.00, CANADADOLLAREXR, SINGDOLLAREXR);
  50. Double expected = 54_166.67;
  51. Assert.assertEquals(expected, actual);
  52. }
  53. @Test
  54. public void testSingaporeDollarToSwissFranc(){
  55. Double actual = CurrencyConverter.convertCurrency(50000.00, SINGDOLLAREXR, SWISSFRANCEXR);
  56. Double expected = 35_314.69;
  57. Assert.assertEquals(expected, actual);
  58. }
  59. @Test
  60. public void testSwissFrancToMalaysianRinggit(){
  61. Double actual = CurrencyConverter.convertCurrency(50000.00, SWISSFRANCEXR, MALAYSRINGGITEXR);
  62. Double expected = 221_287.13;
  63. Assert.assertEquals(expected, actual);
  64. }
  65. }