@Test public void anyNumberMultipliedByOneShouldReturnTheSameNumber() { assertEquals(7, multiply.calculate(1, 7)); }
public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; }
MultiplicationWithoutMultiply { public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; } }
MultiplicationWithoutMultiply { public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; }  }
MultiplicationWithoutMultiply { public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; }  int calculate(int n1, int n2); }
MultiplicationWithoutMultiply { public int calculate(int n1, int n2) { int result = 0; boolean negative = (n1 < 0 && n2 >= 0) || (n2 < 0 && n1 >= 0); boolean positive = !negative; n1 = Math.abs(n1); for (int i = 0; i < n1; i++) { if (negative && n2 > 0 || positive && n2 < 0) result -= n2; else result += n2; } return result; }  int calculate(int n1, int n2);  }