phishman3579/java-algorithms-implementation

Bug: MultiplyUsingLoopWithStringInput cant handle zero input

Snebie opened this issue · 0 comments

We added the following test (in MathematicsTests) which checks that the method Multiplication.multiplyUsingLoopWithStringInput works correctly when multiplying with zero. It fails with the error below

Test:
@test
public void testMultiplyUsingLoopsWithStringInputZero(){
long result = Integer.parseInt(Multiplication.multiplyUsingLoopWithStringInput("0", "0"));
long expected = 0;
//Requirement:
//When multiplying two values where one or both is zero the result should be zero
assertTrue(result ==expected);
}

Error:
Testcase: testMultiplyUsingLoopsWithStringInputZero(com.jwetherell.algorithms.mathematics.test.MathematicsTest): Caused an ERROR
[junit] For input string: ""
[junit] java.lang.NumberFormatException: For input string: ""
[junit] at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
[junit] at java.base/java.lang.Integer.parseInt(Integer.java:678)
[junit] at java.base/java.lang.Integer.parseInt(Integer.java:786)
[junit] at com.jwetherell.algorithms.mathematics.test.MathematicsTest.testMultiplyUsingLoopsWithStringInputZero(Unknown Source)