123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import org.junit.Test;
  2. import static org.junit.Assert.assertEquals;
  3. /**
  4. * @author leon on 8/26/18.
  5. */
  6. public class TestDivision {
  7. private static volatile MathUtilities mathUtils = new MathUtilities();
  8. @Test
  9. public void testIntegerDivision() {
  10. // : Given
  11. int dividend = 20;
  12. int divisor = 2;
  13. int expectedInt = 10;
  14. // : When
  15. int actualInt = mathUtils.divide(dividend, divisor);
  16. // : Then
  17. assertEquals(expectedInt, actualInt);
  18. }
  19. @Test
  20. public void testLongDivision() {
  21. // : Given
  22. long dividend = 20000000L;
  23. long divisor = 1000L;
  24. long expectedLong = 20000;
  25. // : When
  26. long actualLong = mathUtils.divide(dividend, divisor);
  27. // : Then
  28. assertEquals(expectedLong, actualLong);
  29. }
  30. @Test
  31. public void testShortDivision() {
  32. // : Given
  33. short dividend = 2;
  34. short divisor = 1;
  35. short expectedShort = 2;
  36. // : When
  37. short actualShort = mathUtils.divide(dividend, divisor);
  38. // : Then
  39. assertEquals(expectedShort, actualShort);
  40. }
  41. @Test
  42. public void testByteDivision() {
  43. // : Given
  44. byte dividend = 64;
  45. byte divisor = 32;
  46. byte expectedByte = 2;
  47. // : When
  48. byte actualByte = mathUtils.divide(dividend, divisor);
  49. // : Then
  50. assertEquals(expectedByte, actualByte);
  51. }
  52. @Test
  53. public void testFloatDivision() {
  54. // : Given
  55. float dividend = 7.5F;
  56. float divisor = 3;
  57. float expectedFloat = 2.50F;
  58. // : When
  59. float actualFloat = mathUtils.divide(dividend, divisor);
  60. // : Then
  61. assertEquals(expectedFloat, actualFloat, 0);
  62. }
  63. @Test
  64. public void testDoubleDivision() {
  65. // : Given
  66. double dividend = 5.0;
  67. double divisor = 4.0;
  68. double expectedDouble = 1.25;
  69. // : When
  70. double actualDouble = mathUtils.divide(dividend, divisor);
  71. // : Then
  72. assertEquals(expectedDouble, actualDouble, 0);
  73. }
  74. }