Add BogoSort Tests (#3716)

This commit is contained in:
Hyun 2022-11-01 04:52:57 +09:00 committed by GitHub
parent 9e7456a2a8
commit 5864f3296f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View File

@ -569,6 +569,7 @@
* [RabinKarpAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest.java) * [RabinKarpAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/searches/RabinKarpAlgorithmTest.java)
* sorts * sorts
* [BinaryInsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java) * [BinaryInsertionSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BinaryInsertionSortTest.java)
* [BogoSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BogoSortTest.java)
* [BubbleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java) * [BubbleSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/BubbleSortTest.java)
* [DutchNationalFlagSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DutchNationalFlagSortTest.java) * [DutchNationalFlagSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/DutchNationalFlagSortTest.java)
* [QuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/QuickSortTest.java) * [QuickSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/QuickSortTest.java)

View File

@ -0,0 +1,66 @@
package com.thealgorithms.sorts;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.jupiter.api.Test;
public class BogoSortTest {
private BogoSort bogoSort = new BogoSort();
@Test
public void bogoSortEmptyArray() {
Integer[] inputArray = {};
Integer[] outputArray = bogoSort.sort(inputArray);
Integer[] expectedOutput = {};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortSingleIntegerArray() {
Integer[] inputArray = { 4 };
Integer[] outputArray = bogoSort.sort(inputArray);
Integer[] expectedOutput = { 4 };
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortSingleStringArray() {
String[] inputArray = { "s" };
String[] outputArray = bogoSort.sort(inputArray);
String[] expectedOutput = { "s" };
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortNonDuplicateIntegerArray() {
Integer[] inputArray = { 6, -1, 99, 27, -15, 23, -36 };
Integer[] outputArray = bogoSort.sort(inputArray);
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 27, 99};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortDuplicateIntegerArray() {
Integer[] inputArray = { 6, -1, 27, -15, 23, 27, -36, 23 };
Integer[] outputArray = bogoSort.sort(inputArray);
Integer[] expectedOutput = { -36, -15, -1, 6, 23, 23, 27, 27};
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortNonDuplicateStringArray() {
String[] inputArray = { "s", "b", "k", "a", "d", "c", "h" };
String[] outputArray = bogoSort.sort(inputArray);
String[] expectedOutput = {"a", "b", "c", "d", "h", "k", "s" };
assertArrayEquals(outputArray, expectedOutput);
}
@Test
public void bogoSortDuplicateStringArray() {
String[] inputArray = { "s", "b", "d", "a", "d", "c", "h", "b" };
String[] outputArray = bogoSort.sort(inputArray);
String[] expectedOutput = {"a", "b", "b", "c", "d", "d", "h", "s" };
assertArrayEquals(outputArray, expectedOutput);
}
}