Skip to content

Commit 51246aa

Browse files
author
Alex Klymenko
committed
fix: adding flipped tests, removed messages from tests
1 parent 5946c2b commit 51246aa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/test/java/com/thealgorithms/sorts/SortUtilsTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.junit.jupiter.api.Assertions.assertThrows;
65
import static org.junit.jupiter.api.Assertions.assertTrue;
76

87
import java.util.List;
@@ -76,20 +75,21 @@ void isSortedListFalse() {
7675

7776
@ParameterizedTest
7877
@MethodSource("provideArraysForSwap")
79-
public <T> void testSwap(T[] array, int i, int j, T[] expected, String message) {
78+
public <T> void testSwap(T[] array, int i, int j, T[] expected) {
8079
SortUtils.swap(array, i, j);
81-
assertArrayEquals(expected, array, message);
80+
assertArrayEquals(expected, array);
8281
}
8382

84-
private static Stream<Arguments> provideArraysForSwap() {
85-
return Stream.of(Arguments.of(new Integer[] {1, 2, 3, 4}, 1, 2, new Integer[] {1, 3, 2, 4}, "Swapping adjacent elements should work correctly."), Arguments.of(new Integer[] {1, 2, 3, 4}, 0, 3, new Integer[] {4, 2, 3, 1}, "Swapping non-adjacent elements should work correctly."),
86-
Arguments.of(new Integer[] {1, 2, 3, 4}, 2, 2, new Integer[] {1, 2, 3, 4}, "Swapping the same index should not change the array."), Arguments.of(new String[] {"a", "b", "c", "d"}, 0, 3, new String[] {"d", "b", "c", "a"}, "Swapping first and last elements should work correctly."),
87-
Arguments.of(new String[] {null, "b", "c", null}, 0, 3, new String[] {null, "b", "c", null}, "Swapping null elements should work correctly."), Arguments.of(new Integer[] {}, 0, 0, new Integer[] {}, "Swapping in an empty array should not throw an error."));
83+
@ParameterizedTest
84+
@MethodSource("provideArraysForSwap")
85+
public <T> void testSwapFlippedIndices(T[] array, int i, int j, T[] expected) {
86+
SortUtils.swap(array, j, i);
87+
assertArrayEquals(expected, array);
8888
}
8989

90-
@Test
91-
public void testSwapOutOfBounds() {
92-
Integer[] array = {1, 2, 3, 4};
93-
assertThrows(ArrayIndexOutOfBoundsException.class, () -> SortUtils.swap(array, -1, 4), "Swapping out of bounds should throw an ArrayIndexOutOfBoundsException.");
90+
private static Stream<Arguments> provideArraysForSwap() {
91+
return Stream.of(Arguments.of(new Integer[] {1, 2, 3, 4}, 1, 2, new Integer[] {1, 3, 2, 4}), Arguments.of(new Integer[] {1, 2, 3, 4}, 0, 3, new Integer[] {4, 2, 3, 1}),
92+
Arguments.of(new Integer[] {1, 2, 3, 4}, 2, 2, new Integer[] {1, 2, 3, 4}), Arguments.of(new String[] {"a", "b", "c", "d"}, 0, 3, new String[] {"d", "b", "c", "a"}),
93+
Arguments.of(new String[] {null, "b", "c", null}, 0, 3, new String[] {null, "b", "c", null}), Arguments.of(new Integer[] {}, 0, 0, new Integer[] {}));
9494
}
9595
}

0 commit comments

Comments
 (0)