calculatorCoreFunctionsTest.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 calculatorCoreFunctionsTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. import static org.junit.Assert.*;
  12. import org.junit.After;
  13. import org.junit.Before;
  14. import org.junit.Test;
  15. /**
  16. * The test class calculatorCoreFunctionsTest.
  17. *
  18. * @author (your name)
  19. * @version (a version number or a date)
  20. */
  21. public class calculatorCoreFunctionsTest
  22. {
  23. public calculatorCoreFunctions coreFunctions;
  24. @Before
  25. public void setUp()
  26. {
  27. coreFunctions = new calculatorCoreFunctions();
  28. }
  29. @After
  30. public void tearDown()
  31. {
  32. }
  33. @Test
  34. public void addTest()
  35. {
  36. double expected = 9.0;
  37. double actual = coreFunctions.add(8,1);
  38. assertEquals(expected, actual, 0.1);
  39. }
  40. @Test
  41. public void subtractTest()
  42. {
  43. double expected = 5.0;
  44. double actual = coreFunctions.subtract(7,2);
  45. assertEquals(expected, actual, 0.1);
  46. }
  47. @Test
  48. public void multiplyTest()
  49. {
  50. double expected = 12.0;
  51. double actual = coreFunctions.multiply(3,4);
  52. assertEquals(expected, actual, 0.1);
  53. }
  54. @Test
  55. public void divideTest()
  56. {
  57. double expected = 7.0;
  58. double actual = coreFunctions.divide(21,3);
  59. assertEquals(expected, actual, 0.1);
  60. }
  61. @Test
  62. public void expTest()
  63. {
  64. double expected = 4.0;
  65. double actual = coreFunctions.exponent(2,2);
  66. assertEquals(expected, actual, 0.1);
  67. }
  68. @Test
  69. public void sqrtTest()
  70. {
  71. double expected = 5.0;
  72. double actual = coreFunctions.sqrt(25.0);
  73. assertEquals(expected, actual, 0.1);
  74. }
  75. @Test
  76. public void invertTest()
  77. {
  78. double expected = 0.2;
  79. double actual = coreFunctions.inverse(5.0);
  80. assertEquals(expected, actual, 0.1);
  81. }
  82. }