|
1 | 1 | package com.thealgorithms.sorts;
|
2 | 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); |
| 3 | +public class PancakeSortTest extends SortingAlgorithmTest { |
| 4 | + @Override |
| 5 | + SortAlgorithm getSortAlgorithm() { |
| 6 | + return new PancakeSort(); |
79 | 7 | }
|
80 | 8 | }
|
0 commit comments