CurrencyConverterTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. CurrencyConverter curr;
  14. /**
  15. * Default constructor for test class CurrencyConverterTest
  16. */
  17. public CurrencyConverterTest()
  18. {
  19. }
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {curr = new CurrencyConverter();
  28. }
  29. /**
  30. * Tears down the test fixture.
  31. *
  32. * Called after every test case method.
  33. */
  34. @After
  35. public void tearDown()
  36. {
  37. }
  38. @Test
  39. public void convertTestUSDtoEURO(){
  40. float expected = (float)94.00;
  41. float actual = curr.convert((float)100,(float)(0.94),(float)1);
  42. assertEquals(expected,actual,0.1);
  43. }
  44. @Test
  45. public void convertTestEUROtoUSD(){
  46. float expected = (float)106.38;
  47. float actual = curr.convert((float)100,(float)1,(float)0.94);
  48. assertEquals(expected,actual,0.1);
  49. }
  50. @Test
  51. public void convertTestEUROtoGBP(){
  52. float expected = (float)114.63;
  53. float actual = curr.convert((float)100,(float)0.94,(float)0.82);
  54. assertEquals(expected,actual,0.1);
  55. }
  56. @Test
  57. public void convertTestGBPtoINR(){
  58. float expected = (float)8331.70;
  59. float actual = curr.convert((float)100,(float)68.32,(float)0.82);
  60. assertEquals(expected,actual,0.1);
  61. }
  62. @Test
  63. public void convertTestINRtoCAD(){
  64. float expected = (float)1.93;
  65. float actual = curr.convert((float)100,(float)1.32,(float)68.32);
  66. assertEquals(expected,actual,0.1);
  67. }
  68. @Test
  69. public void convertTestCADtoSWISS(){
  70. float expected = (float)76.51;
  71. float actual = curr.convert((float)100,(float)1.01,(float)1.32);
  72. assertEquals(expected,actual,0.1);
  73. }
  74. @Test
  75. public void convertTestSINGtoSWISS(){
  76. float expected = (float)141.58;
  77. float actual = curr.convert((float)100,(float)1.43,(float)1.01);
  78. assertEquals(expected,actual,0.1);
  79. }
  80. @Test
  81. public void convertTestSWIStoMALAY(){
  82. float expected = (float)442.57;
  83. float actual = curr.convert((float)100,(float)4.47,(float)1.01);
  84. assertEquals(expected,actual,0.1);
  85. }
  86. @Test
  87. public void convertTestMALAYtoJPY(){
  88. float expected = (float)2591.49;
  89. float actual = curr.convert((float)100,(float)115.84,(float)4.47);
  90. assertEquals(expected,actual,0.1);
  91. }
  92. @Test
  93. public void convertTestJPYtoCNY(){
  94. float expected = (float)5.97;
  95. float actual = curr.convert((float)100,(float)6.92,(float)115.84);
  96. assertEquals(expected,actual,0.1);
  97. }
  98. }