123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 simpleOpTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class simpleOpTest
  12. {
  13. /**
  14. * Default constructor for test class simpleOpTest
  15. */
  16. public simpleOpTest()
  17. {
  18. }
  19. /**
  20. * Sets up the test fixture.
  21. *
  22. * Called before every test case method.
  23. */
  24. @Before
  25. public void setUp()
  26. {
  27. }
  28. /**
  29. * Tears down the test fixture.
  30. *
  31. * Called after every test case method.
  32. */
  33. @After
  34. public void tearDown()
  35. {
  36. }
  37. @Test
  38. public void firstAddTest()
  39. {
  40. assertEquals(4.0, simpleOp.add(2, 2), 0.1);
  41. }
  42. @Test
  43. public void secondAddTestNegative()
  44. {
  45. assertEquals(-8.0, simpleOp.add(-100, 92), 0.1);
  46. }
  47. @Test
  48. public void firstSubtractTest()
  49. {
  50. assertEquals(13.0, simpleOp.sub(25, 12), 0.1);
  51. }
  52. @Test
  53. public void secondSubtractTestNegative()
  54. {
  55. assertEquals(-8.0, simpleOp.sub(-100, -92), 0.1);
  56. }
  57. @Test
  58. public void firstMultiplyTest()
  59. {
  60. assertEquals(0.0, simpleOp.mul(3, 0), 0.1);
  61. }
  62. @Test
  63. public void secondMultiplyTestNegative()
  64. {
  65. assertEquals(125.0, simpleOp.mul(-25, -5), 0.1);
  66. }
  67. @Test
  68. public void DivideTest2Negative()
  69. {
  70. assertEquals(20.0, simpleOp.div(100, 5), 0.1);
  71. }
  72. @Test
  73. public void firstSquareTest()
  74. {
  75. assertEquals(25.0, simpleOp.squ(5), 0.1);
  76. }
  77. @Test
  78. public void secondSquareTestNegative()
  79. {
  80. assertEquals(49.0, simpleOp.squ(-7), 0.1);
  81. }
  82. @Test
  83. public void firstExponentTest()
  84. {
  85. assertEquals(125.0, simpleOp.exp(5, 3), 0.1);
  86. }
  87. @Test
  88. public void SecondExponentTestNegative()
  89. {
  90. assertEquals(0.008, simpleOp.exp(5, -3), 0.1);
  91. }
  92. @Test
  93. public void firstInverseTest()
  94. {
  95. assertEquals(0.01, simpleOp.inv(100), 0.1);
  96. }
  97. @Test
  98. public void secondInverseTest()
  99. {
  100. assertEquals(0.0002, simpleOp.inv(5000), 0.1);
  101. }
  102. @Test
  103. public void divideByZero()
  104. {
  105. assertEquals(0.0, simpleOp.div(100, 0), 0.1);
  106. }
  107. @Test
  108. public void firstInvertTest()
  109. {
  110. assertEquals(-237.0, simpleOp.invert(237), 0.1);
  111. }
  112. @Test
  113. public void secondInvertTest()
  114. {
  115. assertEquals(253.0, simpleOp.invert(-253), 0.1);
  116. }
  117. }