MathUtilitiesTest.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. public class MathUtilitiesTest
  6. {
  7. private MathUtilities utilities;
  8. private static final double DELTA = 0.009;
  9. @Before
  10. public void setup(){
  11. utilities = new MathUtilities();
  12. }
  13. @Test
  14. public void testAddInteger(){
  15. //Given
  16. int expected = 15;
  17. //When
  18. int actual = utilities.add(7, 8);
  19. //Then
  20. assertEquals(expected, actual);
  21. }
  22. @Test
  23. public void testAddDouble(){
  24. //Given
  25. double expected = 11.22;
  26. //When
  27. double actual = utilities.add(10, 1.22);
  28. //Then
  29. assertEquals(expected, actual, DELTA);
  30. }
  31. @Test
  32. public void testHalfForEven(){
  33. //Given
  34. double expected = 2.0;
  35. //When
  36. double actual = utilities.half(4);
  37. //Then
  38. assertEquals(expected, actual, DELTA);
  39. }
  40. @Test
  41. public void testHalfForOdd(){
  42. //Given
  43. double expected = 12.5;
  44. //When
  45. double actual = utilities.half(25);
  46. //Then
  47. assertEquals(expected, actual, DELTA);
  48. }
  49. }