java-algorithms-implementation icon indicating copy to clipboard operation
java-algorithms-implementation copied to clipboard

Bug: MultiplyUsingLoopWithStringInput cant handle zero input

Open Snebie opened this issue 3 years ago • 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)

Snebie avatar Feb 25 '22 16:02 Snebie