Skip to content

[BUG] AbsoluteMin returns incorrect values for some inputs #7535

Description

@klerk1t

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.

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions