TestMultiplication.java 2.2KB

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