refactor: IntrospectiveSort (#5316)

This commit is contained in:
Alex Klymenko
2024-08-11 20:00:47 +02:00
committed by GitHub
parent 66bfaff807
commit 2837585705
2 changed files with 93 additions and 93 deletions

View File

@ -1,63 +1,8 @@
package com.thealgorithms.sorts;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
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);
public class IntrospectiveSortTest extends SortingAlgorithmTest {
@Override
SortAlgorithm getSortAlgorithm() {
return new IntrospectiveSort();
}
}