ShortCalculatorTest.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ShortCalculatorTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class ShortCalculatorTest
  12. {
  13. /**
  14. * Default constructor for test class ShortCalculatorTest
  15. */
  16. ShortCalculator shortCalculator;
  17. public ShortCalculatorTest()
  18. { shortCalculator = new ShortCalculator();
  19. }
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {shortCalculator = new ShortCalculator();
  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 add(){
  40. //:Given
  41. short expected = 4;
  42. //:When
  43. short actual = shortCalculator.add((short) 2,(short) 2);
  44. //:Then
  45. assertEquals( expected, actual);
  46. }
  47. @Test
  48. public void subtract(){
  49. //Given
  50. short expected = 4;
  51. //When
  52. short actual = shortCalculator.subtract((short) 10, (short) 6);
  53. //Then
  54. assertEquals( expected, actual);
  55. }
  56. @Test
  57. public void multiply(){
  58. //Given
  59. short expected = 40;
  60. //When
  61. short actual = shortCalculator.multiply((short) 10, (short) 4);
  62. //Then
  63. assertEquals( expected, actual);
  64. }
  65. @Test
  66. public void divide(){
  67. //Given
  68. short expected = 10;
  69. //When
  70. short actual = shortCalculator.divide((short) 40, (short) 4);
  71. //Then
  72. assertEquals( expected, actual);
  73. }
  74. }