99public class BucketSortHashBehaviorTest {
1010
1111 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
12+ // Reproduces the production hash() logic
1313 double range = max .compareTo (min );
1414 double normalizedValue = element .compareTo (min ) / range ; // -1/0/1 divided by -1/0/1
1515 return (int ) (normalizedValue * (numberOfBuckets - 1 ));
1616 }
1717
18- @ Test //Test case when all numbers are equal
18+ @ Test // Test case when all numbers are equal
1919 void sort_stillCorrect_whenAllEqual () {
2020 Integer [] arr = {1 , 1 , 1 , 1 , 1 };
2121 Integer [] expected = arr .clone ();
2222
2323 new BucketSort ().sort (arr );
2424 assertArrayEquals (expected , arr );
2525
26- //Observe bucket mapping (all collapse to index 0)
26+ // Observe bucket mapping (all collapse to index 0)
2727 Integer min = 1 , max = 1 ;
2828 int numberOfBuckets = Math .max (arr .length / 10 , 1 ); // same as BUCKET_DIVISOR rule
2929 int idx = pseudoHash (1 , min , max , numberOfBuckets );
30- //idx will be 0 because NaN cast to int -> 0 in Java
30+ // idx will be 0 because NaN cast to int -> 0 in Java
3131 System .out .println ("All-equal case -> bucket index: " + idx );
3232 }
3333
34- @ Test //Test case with non-equal integers
34+ @ Test // Test case with non-equal integers
3535 void sort_stillCorrect_nonEqualIntegers () {
3636 Integer [] arr = {20 , 40 , 30 , 10 };
3737 Integer [] expected = {10 , 20 , 30 , 40 };
@@ -51,7 +51,7 @@ void sort_stillCorrect_nonEqualIntegers() {
5151 // Expect only two distinct buckets because compareTo gives -1/0/1
5252 }
5353
54- @ Test //Test case when the Array contains Strings
54+ @ Test // Test case when the Array contains Strings
5555 void sort_stillCorrect_whenStrings () {
5656 String [] arr = {"apple" , "banana" , "carrot" };
5757 String [] expected = arr .clone ();
@@ -70,4 +70,3 @@ void sort_stillCorrect_whenStrings() {
7070 // Buckets reflect only lexicographic order, not a numeric spacing
7171 }
7272}
73-
0 commit comments