ShortCalculatorTest.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. ShortCalculator shortCalculator;
  14. /**
  15. * Default constructor for test class ShortCalculatorTest
  16. */
  17. public ShortCalculatorTest()
  18. {
  19. }
  20. /**
  21. * Sets up the test fixture.
  22. *
  23. * Called before every test case method.
  24. */
  25. @Before
  26. public void setUp()
  27. {
  28. shortCalculator = new ShortCalculator();
  29. }
  30. /**
  31. * Tears down the test fixture.
  32. *
  33. * Called after every test case method.
  34. */
  35. @After
  36. public void tearDown()
  37. {
  38. }
  39. @Test
  40. public void sum(){//:Given
  41. short expected = 20;
  42. //:When
  43. short actual = shortCalculator.sum((short)10 , (short)10);
  44. //:Then
  45. assertEquals( expected, actual);
  46. }
  47. @Test
  48. public void subtract(){//:Given
  49. short expected = 20;
  50. //:When
  51. short actual = shortCalculator.subtract((short)35 , (short)15);
  52. //:Then
  53. assertEquals( expected, actual);
  54. }
  55. @Test
  56. public void divide(){//:Given
  57. short expected = 1;
  58. //:When
  59. short actual = shortCalculator.divide((short)10 , (short)10);
  60. //:Then
  61. assertEquals( expected, actual);
  62. }
  63. @Test
  64. public void multiply(){//
  65. short expected = 100;
  66. //:When
  67. short actual = shortCalculator.multiply((short)20 , (short)5);
  68. //:Then
  69. assertEquals(expected, actual);
  70. }
  71. @Test
  72. public void mod(){//:Given
  73. short expected = 0;
  74. //:When
  75. short actual = shortCalculator.mod((short)10 , (short)10);
  76. //:Then
  77. assertEquals( expected, actual);
  78. }
  79. }