CoreFeaturesTest.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 CoreFeaturesTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class CoreFeaturesTest
  12. {
  13. private Console console = new Console();
  14. private CoreFeatures core = new CoreFeatures(console);
  15. @Test
  16. public void addTest()
  17. {
  18. console.changeCurrentValue(2);
  19. double testAdd = core.add(2);
  20. assertEquals(4, testAdd, 0);
  21. }
  22. @Test
  23. public void minusTest()
  24. {
  25. console.changeCurrentValue(2);
  26. double testMinus = core.subtract(2);
  27. assertEquals(0, testMinus, 0);
  28. }
  29. @Test
  30. public void timesTest()
  31. {
  32. console.changeCurrentValue(2);
  33. double testTimes = core.multiply(2);
  34. assertEquals(4, testTimes, 0);
  35. }
  36. @Test
  37. public void divideTest()
  38. {
  39. console.changeCurrentValue(2);
  40. double testDivide = core.divide(2);
  41. assertEquals(1, testDivide, 0);
  42. }
  43. @Test
  44. public void squareTest()
  45. {
  46. console.changeCurrentValue(2);
  47. double testSquare = core.square();
  48. assertEquals(4, testSquare, 0);
  49. }
  50. @Test
  51. public void sqrtTest()
  52. {
  53. console.changeCurrentValue(4);
  54. double testSqrt = core.squareRoot();
  55. assertEquals(2, testSqrt, 0);
  56. }
  57. @Test
  58. public void inverseTest()
  59. {
  60. console.changeCurrentValue(2);
  61. double testInverse = core.inverse();
  62. assertEquals(.5, testInverse, 0);
  63. }
  64. @Test
  65. public void changeSignTest()
  66. {
  67. console.changeCurrentValue(2);
  68. double testChangeSign = core.changeSign();
  69. assertEquals(-2, testChangeSign, 0);
  70. }
  71. @Test
  72. public void variableExponentiationTest()
  73. {
  74. console.changeCurrentValue(2);
  75. double testVariableExponentiation = core.variableExponentiation(2);
  76. assertEquals(4, testVariableExponentiation, 0);
  77. }
  78. @Test
  79. public void getValueTest()
  80. {
  81. console.changeCurrentValue(2);
  82. double testGetValue = console.getCurrentValue();
  83. assertEquals(2, testGetValue, 0);
  84. }
  85. @Test
  86. public void clearValueTest()
  87. {
  88. double testClearValue = console.clearCurrentValue();
  89. assertEquals(0, testClearValue, 0);
  90. }
  91. @Test
  92. public void changeValueTest()
  93. {
  94. double testChangeValue = console.changeCurrentValue(9);
  95. assertEquals(9, testChangeValue, 0);
  96. }
  97. }