12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import org.junit.Test;
  2. import static org.junit.Assert.assertEquals;
  3. /**
  4. * @author leon on 8/26/18.
  5. */
  6. public class TestAddition {
  7. private static volatile MathUtilities mathUtils = new MathUtilities();
  8. @Test
  9. public void testIntegerAddition() {
  10. // : Given
  11. int baseValue = 20;
  12. int addedValue = 7;
  13. int expected = 27;
  14. // : When
  15. int actual = mathUtils.add(baseValue, addedValue);
  16. // : Then
  17. assertEquals(expected, actual);
  18. }
  19. @Test
  20. public void testLongAddition() {
  21. // : Given
  22. long baseValue = 228437266;
  23. long difference = 228437265;
  24. long expected = 456874531;
  25. // : When
  26. long actual = mathUtils.add(baseValue, difference);
  27. // : Then
  28. assertEquals(expected, actual);
  29. }
  30. @Test
  31. public void testShortAddition() {
  32. // : Given
  33. short baseValue = 16384;
  34. short addedValue = 7;
  35. short expected = 16391;
  36. // : When
  37. short actual = mathUtils.add(baseValue, addedValue);
  38. // : Then
  39. assertEquals(expected, actual);
  40. }
  41. @Test
  42. public void testByteAddition() {
  43. // : Given
  44. byte baseValue = 63;
  45. byte addedValue = 64;
  46. byte expected = 127;
  47. // : When
  48. byte actual = mathUtils.add(baseValue, addedValue);
  49. // : Then
  50. assertEquals(expected, actual);
  51. }
  52. @Test
  53. public void testFloatAddition() {
  54. // : Given
  55. float baseValue = 750.585F;
  56. float addedValue = 795.000F;
  57. float expected = 1545.585F;
  58. // : When
  59. float actual = mathUtils.add(baseValue, addedValue);
  60. // : Then
  61. assertEquals(expected, actual, 0);
  62. }
  63. @Test
  64. public void testDoubleAddition() {
  65. // : Given
  66. double baseValue = 225.25;
  67. double addedValue = 231;
  68. double expected = 456.25;
  69. // : When
  70. double actual = mathUtils.add(baseValue, addedValue);
  71. // : Then
  72. assertEquals(expected, actual, 0);
  73. }
  74. }