|
1 | 1 | package com.thealgorithms.sorts;
|
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
3 | 7 | /**
|
4 | 8 | * @author Rebecca Velez (https://github.com/rebeccavelez)
|
5 | 9 | * @see SlowSort
|
6 | 10 | */
|
7 | 11 |
|
8 |
| -public class SlowSortTest extends SortingAlgorithmTest { |
9 |
| - protected int getGeneratedArraySize() { |
10 |
| - return 100; |
| 12 | +public class SlowSortTest { |
| 13 | + |
| 14 | + private SlowSort slowSort = new SlowSort(); |
| 15 | + |
| 16 | + @Test |
| 17 | + public void slowSortEmptyArray() { |
| 18 | + Integer[] inputArray = {}; |
| 19 | + Integer[] outputArray = slowSort.sort(inputArray); |
| 20 | + Integer[] expectedOutput = {}; |
| 21 | + assertArrayEquals(outputArray, expectedOutput); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void slowSortSingleIntegerElementArray() { |
| 26 | + Integer[] inputArray = {5}; |
| 27 | + Integer[] outputArray = slowSort.sort(inputArray); |
| 28 | + Integer[] expectedOutput = {5}; |
| 29 | + assertArrayEquals(outputArray, expectedOutput); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void slowSortSingleStringElementArray() { |
| 34 | + String[] inputArray = {"k"}; |
| 35 | + String[] outputArray = slowSort.sort(inputArray); |
| 36 | + String[] expectedOutput = {"k"}; |
| 37 | + assertArrayEquals(outputArray, expectedOutput); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void slowSortIntegerArray() { |
| 42 | + Integer[] inputArray = {8, 84, 53, -683, 953, 64, 2, 202, 98, -10}; |
| 43 | + Integer[] outputArray = slowSort.sort(inputArray); |
| 44 | + Integer[] expectedOutput = {-683, -10, 2, 8, 53, 64, 84, 98, 202, 953}; |
| 45 | + assertArrayEquals(outputArray, expectedOutput); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void slowSortDuplicateIntegerArray() { |
| 50 | + Integer[] inputArray = {8, 84, 8, -2, 953, 64, 2, 953, 98}; |
| 51 | + Integer[] outputArray = slowSort.sort(inputArray); |
| 52 | + Integer[] expectedOutput = {-2, 2, 8, 8, 64, 84, 98, 953, 953}; |
| 53 | + assertArrayEquals(outputArray, expectedOutput); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void slowSortStringArray() { |
| 58 | + String[] inputArray = {"g", "d", "a", "b", "f", "c", "e"}; |
| 59 | + String[] outputArray = slowSort.sort(inputArray); |
| 60 | + String[] expectedOutput = {"a", "b", "c", "d", "e", "f", "g"}; |
| 61 | + assertArrayEquals(outputArray, expectedOutput); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void slowSortDuplicateStringArray() { |
| 66 | + String[] inputArray = {"g", "d", "a", "g", "b", "f", "d", "c", "e"}; |
| 67 | + String[] outputArray = slowSort.sort(inputArray); |
| 68 | + String[] expectedOutput = {"a", "b", "c", "d", "d", "e", "f", "g", "g"}; |
| 69 | + assertArrayEquals(outputArray, expectedOutput); |
11 | 70 | }
|
12 | 71 |
|
13 |
| - @Override |
14 |
| - SortAlgorithm getSortAlgorithm() { |
15 |
| - return new SlowSort(); |
| 72 | + @Test |
| 73 | + public void slowSortStringSymbolArray() { |
| 74 | + String[] inputArray = {"cbf", "auk", "ó", "(b", "a", ")", "au", "á", "cba", "auk", "(a", "bhy", "cba"}; |
| 75 | + String[] outputArray = slowSort.sort(inputArray); |
| 76 | + String[] expectedOutput = {"(a", "(b", ")", "a", "au", "auk", "auk", "bhy", "cba", "cba", "cbf", "á", "ó"}; |
| 77 | + assertArrayEquals(outputArray, expectedOutput); |
16 | 78 | }
|
17 | 79 | }
|
0 commit comments