Description
The current implementation of com.thealgorithms.maths.AbsoluteMin returns an incorrect result for some inputs.
Example:
org.opentest4j.AssertionFailedError:
Expected :2
Actual :-5
The implementation compares values by their absolute magnitude but updates the result using Math.min(), which can produce an incorrect result.
Steps to reproduce
Add the following test to AbsoluteMinTest:
assertEquals(2, AbsoluteMin.getMinValue(-5, 2));
Excepted behavior
The method should return the value with the smallest absolute magnitude.
For the input {-5, 2}, the expected result is 2.
Steps to reproduce
No response
Excepted behavior
The method AbsoluteMin.getMinValue(int a, int b) is expected to return the number whose absolute value is smallest, not the numerically smallest number.
It should compare values using Math.abs()
It should return the original number (preserving sign) that has the minimum absolute magnitude
Screenshots
No response
Additional context
No response
Description
The current implementation of com.thealgorithms.maths.AbsoluteMin returns an incorrect result for some inputs.
Example:
org.opentest4j.AssertionFailedError:
Expected :2
Actual :-5
The implementation compares values by their absolute magnitude but updates the result using Math.min(), which can produce an incorrect result.
Steps to reproduce
Add the following test to AbsoluteMinTest:
assertEquals(2, AbsoluteMin.getMinValue(-5, 2));
Excepted behavior
The method should return the value with the smallest absolute magnitude.
For the input {-5, 2}, the expected result is 2.
Steps to reproduce
No response
Excepted behavior
The method AbsoluteMin.getMinValue(int a, int b) is expected to return the number whose absolute value is smallest, not the numerically smallest number.
It should compare values using Math.abs()
It should return the original number (preserving sign) that has the minimum absolute magnitude
Screenshots
No response
Additional context
No response