TestSubtraction.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import org.junit.Test;
  2. import static org.junit.Assert.assertEquals;
  3. /**
  4. * @author leon on 8/26/18.
  5. */
  6. public class TestSubtraction {
  7. private static volatile MathUtilities mathUtils = new MathUtilities();
  8. @Test
  9. public void testIntegerSubtraction(){
  10. // : Given
  11. int baseValue = 20;
  12. int difference = 7;
  13. int expectedInt = 13;
  14. // : When
  15. int actualInt = mathUtils.subtract(baseValue,difference);
  16. // : Then
  17. assertEquals(expectedInt,actualInt);
  18. }
  19. @Test
  20. public void testLongSubtraction() {
  21. // : Given
  22. long baseValue = 228437266;
  23. long difference = 228437265;
  24. long expectedLong = 1;
  25. // : When
  26. long actualLong = mathUtils.subtract(baseValue, difference);
  27. // : Then
  28. assertEquals(expectedLong,actualLong);
  29. }
  30. @Test
  31. public void testShortSubtraction() {
  32. // : Given
  33. short baseValue = 16384;
  34. short difference = 16383;
  35. short expectedShort = 1;
  36. // : When
  37. short actualShort = mathUtils.subtract(baseValue, difference);
  38. // : Then
  39. assertEquals(expectedShort,actualShort);
  40. }
  41. @Test
  42. public void testByteSubtraction() {
  43. // : Given
  44. byte baseValue = 63;
  45. byte difference = 64;
  46. byte expectedByte = -1;
  47. // : When
  48. byte actualByte = mathUtils.subtract(baseValue, difference);
  49. // : Then
  50. assertEquals(expectedByte,actualByte);
  51. }
  52. @Test
  53. public void testFloatSubtraction() {
  54. // : Given
  55. float baseValue = 750.585F;
  56. float difference = 795.0F;
  57. float expectedFloat = -44.415F;
  58. // : When
  59. float actualFloat = mathUtils.subtract(baseValue,difference);
  60. // : Then
  61. assertEquals(expectedFloat,actualFloat, 0.005);
  62. }
  63. @Test
  64. public void testDoubleSubtraction() {
  65. // : Given
  66. double baseValue = 225.25;
  67. double difference = 231;
  68. double expectedDouble = -5.75;
  69. // : When
  70. double actualDouble = mathUtils.subtract(baseValue, difference);
  71. // : Then
  72. assertEquals(expectedDouble,actualDouble, 0);
  73. }
  74. }