-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cleanup: BeadSort and BeadSortTest, adding javadocs * checkstyle: fix formatting * checkstyle: fix import order * cleanup: improving code readability * cleanup: improving code readability using enum to represent beads * checkstyle: fix enum formatting * fix: enum should be compared using ==, according to maven bugs finder plugin --------- Co-authored-by: Alex Klymenko <[email protected]> Co-authored-by: Piotr Idzik <[email protected]>
- Loading branch information
1 parent
208e1e9
commit ac31fba
Showing
2 changed files
with
56 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
package com.thealgorithms.sorts; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class BeadSortTest { | ||
// BeadSort can't sort negative number, Character, String. It can sort positive number only | ||
private BeadSort beadSort = new BeadSort(); | ||
|
||
@Test | ||
public void beadSortEmptyArray() { | ||
int[] inputArray = {}; | ||
int[] outputArray = beadSort.sort(inputArray); | ||
int[] expectedOutput = {}; | ||
assertArrayEquals(outputArray, expectedOutput); | ||
} | ||
|
||
@Test | ||
public void beadSortSingleIntegerArray() { | ||
int[] inputArray = {4}; | ||
int[] outputArray = beadSort.sort(inputArray); | ||
int[] expectedOutput = {4}; | ||
assertArrayEquals(outputArray, expectedOutput); | ||
@ParameterizedTest | ||
@MethodSource("provideArraysForBeadSort") | ||
public void testBeadSort(int[] inputArray, int[] expectedArray) { | ||
BeadSort beadSort = new BeadSort(); | ||
assertArrayEquals(expectedArray, beadSort.sort(inputArray)); | ||
} | ||
|
||
@Test | ||
public void bogoSortNonDuplicateIntegerArray() { | ||
int[] inputArray = {6, 1, 99, 27, 15, 23, 36}; | ||
int[] outputArray = beadSort.sort(inputArray); | ||
int[] expectedOutput = {1, 6, 15, 23, 27, 36, 99}; | ||
assertArrayEquals(outputArray, expectedOutput); | ||
private static Stream<Arguments> provideArraysForBeadSort() { | ||
return Stream.of(Arguments.of(new int[] {}, new int[] {}), Arguments.of(new int[] {4}, new int[] {4}), Arguments.of(new int[] {6, 1, 99, 27, 15, 23, 36}, new int[] {1, 6, 15, 23, 27, 36, 99}), Arguments.of(new int[] {6, 1, 27, 15, 23, 27, 36, 23}, new int[] {1, 6, 15, 23, 23, 27, 27, 36}), | ||
Arguments.of(new int[] {5, 5, 5, 5, 5}, new int[] {5, 5, 5, 5, 5}), Arguments.of(new int[] {1, 2, 3, 4, 5}, new int[] {1, 2, 3, 4, 5}), Arguments.of(new int[] {5, 4, 3, 2, 1}, new int[] {1, 2, 3, 4, 5})); | ||
} | ||
|
||
@Test | ||
public void bogoSortDuplicateIntegerArray() { | ||
int[] inputArray = {6, 1, 27, 15, 23, 27, 36, 23}; | ||
int[] outputArray = beadSort.sort(inputArray); | ||
int[] expectedOutput = {1, 6, 15, 23, 23, 27, 27, 36}; | ||
assertArrayEquals(outputArray, expectedOutput); | ||
public void testWithNegativeNumbers() { | ||
assertThrows(IllegalArgumentException.class, () -> new BeadSort().sort(new int[] {3, 1, 4, 1, 5, -9})); | ||
} | ||
} |