Skip to content

Commit d8a64f4

Browse files
authored
Update BucketSortHashBehaviorTest.java
1 parent e21a21f commit d8a64f4

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/test/java/com/thealgorithms/sorts/BucketSortHashBehaviorTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,35 @@
33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44

55
import java.util.Arrays;
6-
import java.util.List;
76
import org.junit.jupiter.api.Test;
87

98
public class BucketSortHashBehaviorTest {
109

1110
private static <T extends Comparable<T>> int pseudoHash(final T element, final T min, final T max, final int numberOfBuckets) {
12-
// Reproduces the production hash() logic
11+
//Reproduces the production hash() logic
1312
double range = max.compareTo(min);
1413
double normalizedValue = element.compareTo(min) / range; // -1/0/1 divided by -1/0/1
1514
return (int) (normalizedValue * (numberOfBuckets - 1));
1615
}
1716

18-
@Test // Test case when all numbers are equal
19-
void sort_stillCorrect_whenAllEqual() {
17+
@Test //Test case when all numbers are equal
18+
void sortStillCorrectWhenAllEqual() {
2019
Integer[] arr = {1, 1, 1, 1, 1};
2120
Integer[] expected = arr.clone();
2221

2322
new BucketSort().sort(arr);
2423
assertArrayEquals(expected, arr);
2524

26-
// Observe bucket mapping (all collapse to index 0)
25+
//Observe bucket mapping (all collapse to index 0)
2726
Integer min = 1, max = 1;
2827
int numberOfBuckets = Math.max(arr.length / 10, 1); // same as BUCKET_DIVISOR rule
2928
int idx = pseudoHash(1, min, max, numberOfBuckets);
3029
// idx will be 0 because NaN cast to int -> 0 in Java
3130
System.out.println("All-equal case -> bucket index: " + idx);
3231
}
3332

34-
@Test // Test case with non-equal integers
35-
void sort_stillCorrect_nonEqualIntegers() {
33+
@Test //Test case with non-equal integers
34+
void sortStillCorrectNonEqualIntegers() {
3635
Integer[] arr = {20, 40, 30, 10};
3736
Integer[] expected = {10, 20, 30, 40};
3837

@@ -48,11 +47,11 @@ void sort_stillCorrect_nonEqualIntegers() {
4847
int idx = pseudoHash(x, min, max, numberOfBuckets);
4948
System.out.println("Value " + x + " -> bucket " + idx);
5049
}
51-
// Expect only two distinct buckets because compareTo gives -1/0/1
50+
//Expect only two distinct buckets because compareTo gives -1/0/1
5251
}
5352

54-
@Test // Test case when the Array contains Strings
55-
void sort_stillCorrect_whenStrings() {
53+
@Test //Test case when the Array contains Strings
54+
void sortStillCorrectWhenStrings() {
5655
String[] arr = {"apple", "banana", "carrot"};
5756
String[] expected = arr.clone();
5857

0 commit comments

Comments
 (0)