CurrencyConverterTest.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. public class CurrencyConverterTest {
  6. CurrencyConverter cc;
  7. @Before
  8. public void setup() {
  9. cc = new CurrencyConverter();
  10. }
  11. @Test
  12. public void dollarToEuroTest() {
  13. double expected = 0.94;
  14. double actual = cc.convertCurrency(Currency.usdollar, Currency.euro, 1);
  15. Assert.assertEquals(expected, actual, 0);
  16. }
  17. @Test
  18. public void euroToDollarTest() {
  19. double expected = 1;
  20. double actual = cc.convertCurrency(Currency.euro, Currency.usdollar, 0.94);
  21. Assert.assertEquals(expected, actual, 0);
  22. }
  23. @Test
  24. public void euroToBritishPoundTest() {
  25. double expected = 0.87;
  26. double actual = cc.convertCurrency(Currency.euro, Currency.bpound, 1);
  27. Assert.assertEquals(expected, actual, 0);
  28. }
  29. @Test
  30. public void britishPoundToIndianRupeeTest() {
  31. double expected = 83.32;
  32. double actual = cc.convertCurrency(Currency.bpound, Currency.irupee, 1);
  33. Assert.assertEquals(expected, actual, 0);
  34. }
  35. @Test
  36. public void rupeeToCanadianDollarTest() {
  37. double expected = 0.02;
  38. double actual = cc.convertCurrency(Currency.irupee, Currency.candollar, 1);
  39. Assert.assertEquals(expected, actual, 0);
  40. }
  41. @Test
  42. public void canadianDollarToSingaporeDollarTest() {
  43. double expected = 1.08;
  44. double actual = cc.convertCurrency(Currency.candollar, Currency.singdollar, 1);
  45. Assert.assertEquals(expected, actual, 0);
  46. }
  47. @Test
  48. public void singaporeDollarToSwissFrancTest() {
  49. double expected = 0.71;
  50. double actual = cc.convertCurrency(Currency.singdollar, Currency.swissfranc, 1);
  51. Assert.assertEquals(expected, actual, 0);
  52. }
  53. @Test
  54. public void swissFrancToMalaysianRinggitTest() {
  55. double expected = 4.43;
  56. double actual = cc.convertCurrency(Currency.swissfranc, Currency.malringgit, 1);
  57. Assert.assertEquals(expected, actual, 0);
  58. }
  59. @Test
  60. public void malaysianRinggitToJapaneseYenTest() {
  61. double expected = 25.91;
  62. double actual = cc.convertCurrency(Currency.malringgit, Currency.japyen, 1);
  63. Assert.assertEquals(expected, actual, 0);
  64. }
  65. @Test
  66. public void JapaneseYenToChineseYuanRenminbiTest() {
  67. double expected = 5.97;
  68. double actual = cc.convertCurrency(Currency.japyen, Currency.yuanrenminbi, 100);
  69. Assert.assertEquals(expected, actual, 0);
  70. }
  71. }