Skip to content

Commit 5864f32

Browse files
authored
Add BogoSort Tests (TheAlgorithms#3716)
1 parent 9e7456a commit 5864f32

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

DIRECTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@
569569
* [RabinKarpAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest.java)
570570
* sorts
571571
* [BinaryInsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java)
572+
* [BogoSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BogoSortTest.java)
572573
* [BubbleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java)
573574
* [DutchNationalFlagSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DutchNationalFlagSortTest.java)
574575
* [QuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/QuickSortTest.java)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 BogoSortTest {
8+
9+
private BogoSort bogoSort = new BogoSort();
10+
11+
@Test
12+
public void bogoSortEmptyArray() {
13+
Integer[] inputArray = {};
14+
Integer[] outputArray = bogoSort.sort(inputArray);
15+
Integer[] expectedOutput = {};
16+
assertArrayEquals(outputArray, expectedOutput);
17+
}
18+
19+
@Test
20+
public void bogoSortSingleIntegerArray() {
21+
Integer[] inputArray = { 4 };
22+
Integer[] outputArray = bogoSort.sort(inputArray);
23+
Integer[] expectedOutput = { 4 };
24+
assertArrayEquals(outputArray, expectedOutput);
25+
}
26+
27+
@Test
28+
public void bogoSortSingleStringArray() {
29+
String[] inputArray = { "s" };
30+
String[] outputArray = bogoSort.sort(inputArray);
31+
String[] expectedOutput = { "s" };
32+
assertArrayEquals(outputArray, expectedOutput);
33+
}
34+
35+
@Test
36+
public void bogoSortNonDuplicateIntegerArray() {
37+
Integer[] inputArray = { 6, -1, 99, 27, -15, 23, -36 };
38+
Integer[] outputArray = bogoSort.sort(inputArray);
39+
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 27, 99};
40+
assertArrayEquals(outputArray, expectedOutput);
41+
}
42+
43+
@Test
44+
public void bogoSortDuplicateIntegerArray() {
45+
Integer[] inputArray = { 6, -1, 27, -15, 23, 27, -36, 23 };
46+
Integer[] outputArray = bogoSort.sort(inputArray);
47+
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 23, 27, 27};
48+
assertArrayEquals(outputArray, expectedOutput);
49+
}
50+
51+
@Test
52+
public void bogoSortNonDuplicateStringArray() {
53+
String[] inputArray = { "s", "b", "k", "a", "d", "c", "h" };
54+
String[] outputArray = bogoSort.sort(inputArray);
55+
String[] expectedOutput = {"a", "b", "c", "d", "h", "k", "s" };
56+
assertArrayEquals(outputArray, expectedOutput);
57+
}
58+
59+
@Test
60+
public void bogoSortDuplicateStringArray() {
61+
String[] inputArray = { "s", "b", "d", "a", "d", "c", "h", "b" };
62+
String[] outputArray = bogoSort.sort(inputArray);
63+
String[] expectedOutput = {"a", "b", "b", "c", "d", "d", "h", "s" };
64+
assertArrayEquals(outputArray, expectedOutput);
65+
}
66+
}

0 commit comments

Comments
 (0)