MathUtilitiesTest.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @Test
  50. public void testIsOdd_forOddNumber(){
  51. assertTrue(utilities.isOdd(7));
  52. }
  53. @Test
  54. public void testIsOdd_forEvenNumber(){
  55. assertFalse(utilities.isOdd(12));
  56. }
  57. }