File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
main/java/com/thealgorithms/maths
test/java/com/thealgorithms/maths Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public static int getMinValue(int... numbers) {
1919
2020 var absMinWrapper = new Object () { int value = numbers [0 ]; };
2121
22- Arrays .stream (numbers ).skip (1 ).filter (number -> Math .abs (number ) < Math .abs (absMinWrapper .value )).forEach (number -> absMinWrapper .value = number );
22+ Arrays .stream (numbers ).skip (1 ).filter (number -> Math .abs (number ) <= Math .abs (absMinWrapper .value )).forEach (number -> absMinWrapper .value = Math . min ( absMinWrapper . value , number ) );
2323
2424 return absMinWrapper .value ;
2525 }
Original file line number Diff line number Diff line change @@ -15,7 +15,13 @@ void testGetMinValue() {
1515
1616 @ Test
1717 void testGetMinValueWithNoArguments () {
18- Exception exception = assertThrows (IllegalArgumentException .class , () -> AbsoluteMin . getMinValue () );
18+ Exception exception = assertThrows (IllegalArgumentException .class , AbsoluteMin :: getMinValue );
1919 assertEquals ("Numbers array cannot be empty" , exception .getMessage ());
2020 }
21+
22+ @ Test
23+ void testGetMinValueWithSameAbsoluteValues () {
24+ assertEquals (-5 , AbsoluteMin .getMinValue (-5 , 5 ));
25+ assertEquals (-5 , AbsoluteMin .getMinValue (5 , -5 ));
26+ }
2127}
You can’t perform that action at this time.
0 commit comments