ShortCalculatorTest.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 shortCalc;
  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. shortCalc = 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 shortSumTest(){
  41. //:Given
  42. short expected = 20;
  43. //:When
  44. short actual = shortCalc.sum((short)10,(short)10);
  45. //:Then
  46. assertEquals(expected, actual);
  47. }
  48. @Test
  49. public void shortDiffTest(){
  50. //given
  51. short expected = 15;
  52. //:When
  53. short actual = shortCalc.diff((short)25,(short)10);
  54. //:Then
  55. assertEquals(expected, actual);
  56. }
  57. @Test
  58. public void shortMultiplyTest(){
  59. //given
  60. short expected = 15;
  61. //:When
  62. short actual = shortCalc.multiply((short)5,(short)3);
  63. //:Then
  64. assertEquals(expected, actual);
  65. }
  66. @Test
  67. public void shortDivideTest(){
  68. //given
  69. short expected = 20;
  70. //:When
  71. short actual = shortCalc.divide((short)200,(short)10);
  72. //:Then
  73. assertEquals(expected, actual);
  74. }
  75. @Test
  76. public void shortModTest(){
  77. //given
  78. short expected = 1;
  79. //:When
  80. short actual = shortCalc.remainder((short)10,(short)9);
  81. //:Then
  82. assertEquals(expected, actual);
  83. }
  84. }