Skip to content

Commit 68fdec5

Browse files
authored
Add Tests for PancakeSort (TheAlgorithms#4318)
1 parent ac14411 commit 68fdec5

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void gnomeSortNegativeDuplicateIntegerArray() {
5555

5656
@Test
5757
@DisplayName("GnomeSort single String Array")
58-
public void singleSringArray() {
58+
public void singleStringArray() {
5959
String[] inputArray = {"b"};
6060
String[] expectedOutput = {"b"};
6161
gnomeSort.sort(inputArray);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.thealgorithms.sorts;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class PancakeSortTest {
9+
10+
private PancakeSort pancakeSort = new PancakeSort();
11+
12+
@Test
13+
@DisplayName("Empty Array pancakeSort")
14+
public void pancakeSortEmptyArray() {
15+
Integer[] inputArray = {};
16+
Integer[] outputArray = pancakeSort.sort(inputArray);
17+
assertThat(outputArray).isEmpty();
18+
}
19+
20+
@Test
21+
@DisplayName("PancakeSort single Integer Array")
22+
public void pancakeSort() {
23+
Integer[] inputArray = {2};
24+
Integer[] outputArray = pancakeSort.sort(inputArray);
25+
assertThat(outputArray).isEqualTo(inputArray);
26+
}
27+
28+
@Test
29+
@DisplayName("PancakeSort non duplicate Integer Array")
30+
public void pancakeSortNonDuplicateIntegerArray() {
31+
Integer[] inputArray = {2, 1, 77, 34, 14, 56, 8};
32+
Integer[] expectedOutput = {1, 2, 8, 14, 34, 56, 77};
33+
Integer[] outputArray = pancakeSort.sort(inputArray);
34+
assertThat(outputArray).isEqualTo(expectedOutput);
35+
}
36+
37+
@Test
38+
@DisplayName("PancakeSort Integer Array with duplicates")
39+
public void pancakeSortDuplicateIntegerArray() {
40+
Integer[] inputArray = {2, 1, 77, 34, 14, 77, 56, 14, 8};
41+
Integer[] expectedOutput = {1, 2, 8, 14, 14, 34, 56, 77, 77};
42+
Integer[] outputArray = pancakeSort.sort(inputArray);
43+
assertThat(outputArray).isEqualTo(expectedOutput);
44+
}
45+
46+
@Test
47+
@DisplayName("PancakeSort negative Integer Array with duplicates")
48+
public void pancakeSortNegativeDuplicateIntegerArray() {
49+
Integer[] inputArray = {2, 1, 77, -34, -14, 77, 56, -14, 8};
50+
Integer[] expectedOutput = {-34, -14, -14, 1, 2, 8, 56, 77, 77};
51+
Integer[] outputArray = pancakeSort.sort(inputArray);
52+
assertThat(outputArray).isEqualTo(expectedOutput);
53+
}
54+
55+
@Test
56+
@DisplayName("PancakeSort single String Array")
57+
public void pancakeSortSingleStringArray() {
58+
String[] inputArray = {"W"};
59+
String[] outputArray = pancakeSort.sort(inputArray);
60+
assertThat(outputArray).isEqualTo(inputArray);
61+
}
62+
63+
@Test
64+
@DisplayName("PancakeSort non duplicate String Array")
65+
public void pancakeSortNonDuplicateStringArray() {
66+
String[] inputArray = {"W", "A", "d", "be", "jk", "hb", "bgh"};
67+
String[] expectedOutput = {"A", "W", "be", "bgh", "d", "hb", "jk"};
68+
String[] outputArray = pancakeSort.sort(inputArray);
69+
assertThat(outputArray).isEqualTo(expectedOutput);
70+
}
71+
72+
@Test
73+
@DisplayName("PancakeSort String Array with duplicates")
74+
public void pancakeSortDuplicateStringArray() {
75+
String[] inputArray = {"W", "A", "d", "be", "jk", "hb", "bgh", "bgh", "W"};
76+
String[] expectedOutput = {"A", "W", "W", "be", "bgh", "bgh", "d", "hb", "jk"};
77+
String[] outputArray = pancakeSort.sort(inputArray);
78+
assertThat(outputArray).isEqualTo(expectedOutput);
79+
}
80+
}

0 commit comments

Comments
 (0)