DivideUsingSubtraction { public float divideIterative(int dividend, int divider) { validateInput(divider); float result = 0; while (dividend > divider) { dividend -= divider; result++; } float decimalPart = (float) dividend / (float) divider; result += decimalPart; return result; }  float divideIterative(int dividend, int divider); float divideRecursive(int dividend, int divider);  }
@Test(expected = IllegalArgumentException.class) public void anyNumberDividedByZeroIsNotDefinedIterative() { int dividend = 100; int divider = 0; divideUsingSubtraction.divideIterative(dividend, divider); }
@Test public void fourDividedByTwoEqualsToTwoIterative() { int dividend = 4; int divider = 2; float result = divideUsingSubtraction.divideIterative(dividend, divider); assertEquals(2, result, DELTA); }
@Test public void fiveDividedByTwoEqualsToTwoPointFiveIterative() { int dividend = 5; int divider = 2; float result = divideUsingSubtraction.divideIterative(dividend, divider); assertEquals(2.5, result, DELTA); }
@Test public void sixtyDividedByTwelveEqualsToFiveIterative() { int dividend = 60; int divider = 12; float result = divideUsingSubtraction.divideIterative(dividend, divider); assertEquals(5, result, DELTA); }