Skip to content

Commit 219ec7c

Browse files
hyeonmin2Debasish Biswas
andauthored
Create ShellSortTest (TheAlgorithms#3783)
Co-authored-by: Debasish Biswas <debasishbsws.abc@gmail.com>
1 parent 501aca3 commit 219ec7c

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.thealgorithms.sorts;
2+
3+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class ShellSortTest {
8+
9+
private ShellSort shellSort = new ShellSort();
10+
11+
@Test
12+
public void ShellSortEmptyArray() {
13+
Integer[] inputArray = {};
14+
Integer[] outputArray = shellSort.sort(inputArray);
15+
Integer[] expectedOutput = {};
16+
assertArrayEquals(outputArray, expectedOutput);
17+
}
18+
19+
@Test
20+
public void ShellSortSingleIntegerArray() {
21+
Integer[] inputArray = { 4 };
22+
Integer[] outputArray = shellSort.sort(inputArray);
23+
Integer[] expectedOutput = { 4 };
24+
assertArrayEquals(outputArray, expectedOutput);
25+
}
26+
27+
@Test
28+
public void ShellSortSingleStringArray() {
29+
String[] inputArray = { "s" };
30+
String[] outputArray = shellSort.sort(inputArray);
31+
String[] expectedOutput = { "s" };
32+
assertArrayEquals(outputArray, expectedOutput);
33+
}
34+
35+
@Test
36+
public void ShellSortNonDuplicateIntegerArray() {
37+
Integer[] inputArray = { 6, -1, 99, 27, -15, 23, -36 };
38+
Integer[] outputArray = shellSort.sort(inputArray);
39+
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 27, 99};
40+
assertArrayEquals(outputArray, expectedOutput);
41+
}
42+
43+
@Test
44+
public void ShellSortDuplicateIntegerArray() {
45+
Integer[] inputArray = { 6, -1, 27, -15, 23, 27, -36, 23 };
46+
Integer[] outputArray = shellSort.sort(inputArray);
47+
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 23, 27, 27};
48+
assertArrayEquals(outputArray, expectedOutput);
49+
}
50+
51+
@Test
52+
public void ShellSortNonDuplicateStringArray() {
53+
String[] inputArray = { "s", "b", "k", "a", "d", "c", "h" };
54+
String[] outputArray = shellSort.sort(inputArray);
55+
String[] expectedOutput = {"a", "b", "c", "d", "h", "k", "s" };
56+
assertArrayEquals(outputArray, expectedOutput);
57+
}
58+
59+
@Test
60+
public void ShellSortDuplicateStringArray() {
61+
String[] inputArray = { "s", "b", "d", "a", "d", "c", "h", "b" };
62+
String[] outputArray = shellSort.sort(inputArray);
63+
String[] expectedOutput = {"a", "b", "b", "c", "d", "d", "h", "s" };
64+
assertArrayEquals(outputArray, expectedOutput);
65+
}
66+
67+
}

0 commit comments

Comments
 (0)