CalculatorTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import org.junit.Assert;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class CalculatorTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class CalculatorTest
  12. {
  13. @Test
  14. public void additionTest(){
  15. //:Given
  16. Double expected = Double.valueOf(3);
  17. //:When
  18. Calculator c = new Calculator();
  19. Double actual = c.add(0,3);
  20. //:Then
  21. Assert.assertEquals(expected, actual);
  22. }
  23. @Test
  24. public void subtractionTest(){
  25. //:Given
  26. Double expected = Double.valueOf(2-1);
  27. //:When
  28. Calculator c = new Calculator();
  29. Double actual = c.subtract(2, 1);
  30. //Then
  31. Assert.assertEquals(expected, actual);
  32. }
  33. @Test
  34. public void mutliplicationTest(){
  35. //:Given
  36. Double expected = Double.valueOf(2*3);
  37. //:When
  38. Calculator c = new Calculator();
  39. Double actual = c.multiply(2, 3);
  40. //:Then
  41. Assert.assertEquals(expected, actual);
  42. }
  43. @Test
  44. public void divisionTest(){
  45. //:Given
  46. Double expected = Double.valueOf(4/3);
  47. //:When
  48. Calculator c = new Calculator();
  49. Double actual = c.divide(4,3);
  50. //:Then
  51. Assert.assertEquals(expected, actual);
  52. }
  53. @Test
  54. public void powTest(){
  55. //:Given
  56. Double expected = Double.valueOf(9);
  57. //:When
  58. Calculator c = new Calculator();
  59. Double actual = c.pow(3,2);
  60. //:Then
  61. Assert.assertEquals(expected, actual);
  62. }
  63. @Test
  64. public void squareTest(){
  65. //:Given
  66. Double expected = Double.valueOf(225);
  67. //:When
  68. Calculator c = new Calculator();
  69. Double actual = c.square(15);
  70. //:Then
  71. Assert.assertEquals(expected, actual);
  72. }
  73. @Test
  74. public void sqrtTest(){
  75. //:Given
  76. Double expected = Double.valueOf(Math.sqrt(4));
  77. //:When
  78. Calculator c = new Calculator();
  79. Double actual = c.squareRoot(4);
  80. //:Then
  81. Assert.assertEquals(expected, actual);
  82. }
  83. }