|
| 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 GnomeSortTest { |
| 9 | + |
| 10 | + private GnomeSort gnomeSort = new GnomeSort(); |
| 11 | + |
| 12 | + @Test |
| 13 | + @DisplayName("GnomeSort empty Array") |
| 14 | + public void gnomeSortEmptyArray() { |
| 15 | + Integer[] inputArray = {}; |
| 16 | + gnomeSort.sort(inputArray); |
| 17 | + assertThat(inputArray).isEmpty(); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + @DisplayName("GnomeSort single Integer Array") |
| 22 | + public void singleIntegerArray() { |
| 23 | + Integer[] inputArray = {4}; |
| 24 | + Integer[] expectedOutput = {4}; |
| 25 | + gnomeSort.sort(inputArray); |
| 26 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + @DisplayName("GnomeSort non duplicate Integer Array") |
| 31 | + public void gnomeSortNonDuplicateIntegerArray() { |
| 32 | + Integer[] inputArray = {6, 3, 87, 99, 27, 4}; |
| 33 | + Integer[] expectedOutput = {3, 4, 6, 27, 87, 99}; |
| 34 | + gnomeSort.sort(inputArray); |
| 35 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + @DisplayName("GnomeSort Integer Array with duplicates") |
| 40 | + public void gnomeSortDuplicateIntegerArray() { |
| 41 | + Integer[] inputArray = {6, 3, 87, 3, 99, 27, 4, 27}; |
| 42 | + Integer[] expectedOutput = {3, 3, 4, 6, 27, 27, 87, 99}; |
| 43 | + gnomeSort.sort(inputArray); |
| 44 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + @DisplayName("GnomeSort negative Integer Array with duplicates") |
| 49 | + public void gnomeSortNegativeDuplicateIntegerArray() { |
| 50 | + Integer[] inputArray = {6, 3, -87, 3, 99, -27, 4, -27}; |
| 51 | + Integer[] expectedOutput = {-87, -27, -27, 3, 3, 4, 6, 99}; |
| 52 | + gnomeSort.sort(inputArray); |
| 53 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + @DisplayName("GnomeSort single String Array") |
| 58 | + public void singleSringArray() { |
| 59 | + String[] inputArray = {"b"}; |
| 60 | + String[] expectedOutput = {"b"}; |
| 61 | + gnomeSort.sort(inputArray); |
| 62 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + @DisplayName("GnomeSort non duplicate String Array") |
| 67 | + public void gnomeSortNonDuplicateStringArray() { |
| 68 | + String[] inputArray = {"He", "A", "bc", "lo", "n", "bcp", "mhp", "d"}; |
| 69 | + String[] expectedOutput = {"A", "He", "bc", "bcp", "d", "lo", "mhp", "n"}; |
| 70 | + gnomeSort.sort(inputArray); |
| 71 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @DisplayName("GnomeSort String Array with duplicates") |
| 76 | + public void gnomeSortDuplicateStringArray() { |
| 77 | + String[] inputArray = {"He", "A", "bc", "lo", "n", "bcp", "mhp", "bcp"}; |
| 78 | + String[] expectedOutput = {"A", "He", "bc", "bcp", "bcp", "lo", "mhp", "n"}; |
| 79 | + gnomeSort.sort(inputArray); |
| 80 | + assertThat(inputArray).isEqualTo(expectedOutput); |
| 81 | + } |
| 82 | +} |
0 commit comments