Add Introspective Search (#3887)

This commit is contained in:
Specialist Steak
2023-02-20 01:20:59 +05:30
committed by GitHub
parent 541f490d1e
commit 3c0d94292c
2 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,65 @@
package com.thealgorithms.sorts;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class IntrospectiveSortTest {
@Test
// valid test case
public void StrandSortNonDuplicateTest() {
Integer[] expectedArray = {1, 2, 3, 4, 5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
@Test
// valid test case
public void StrandSortDuplicateTest() {
Integer[] expectedArray = {2, 2, 2, 5, 7};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
@Test
// valid test case
public void StrandSortEmptyTest() {
Integer[] expectedArray = {};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
@Test
// valid test case
public void StrandSortNullTest() {
Integer[] expectedArray = null;
assertThrows(NullPointerException.class, () -> {
new IntrospectiveSort().sort(expectedArray);
});
}
@Test
// valid test case
public void StrandSortNegativeTest() {
Integer[] expectedArray = {-1, -2, -3, -4, -5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
@Test
// valid test case
public void StrandSortNegativeAndPositiveTest() {
Integer[] expectedArray = {-1, -2, -3, 4, 5};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
@Test
// valid test case
public void allSameTest() {
Integer[] expectedArray = {1, 1, 1, 1, 1};
Integer[] actualList = new IntrospectiveSort().sort(expectedArray);
assertArrayEquals(expectedArray, actualList);
}
}