1
1
package com .thealgorithms .shufflealgorithm ;
2
2
3
- import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
4
- import static org .junit .jupiter .api .Assertions .assertTrue ;
5
-
6
3
import com .thealgorithms .shufflealogrithm .WeightedShuffle ;
7
4
import org .junit .jupiter .api .Test ;
8
5
6
+ import static org .junit .jupiter .api .Assertions .*;
7
+
9
8
public class WeightedShuffleTest {
10
9
11
10
// Test case for matching array and weights
@@ -15,14 +14,11 @@ void testWeightedShuffleBasic() {
15
14
int [] weights = {1 , 3 , 2 };
16
15
WeightedShuffle .weightedShuffle (array , weights );
17
16
18
- // After shuffling, higher weight elements should be more likely to appear
19
- // earlier The expected order can be difficult to determine precisely, but
20
- // we can check if the higher-weight elements (20, weight 3) appear before
21
- // lower-weight ones (10, weight 1).
22
- assertTrue (array [0 ] == 20 || array [1 ] == 20 ,
23
- "20 should be among the first two elements" );
24
- assertTrue (array [0 ] == 10 || array [1 ] == 10 ,
25
- "10 should not be the first element" );
17
+ // Check that higher weight element (20) appears among the first two elements
18
+ assertTrue (array [0 ] == 20 || array [1 ] == 20 , "20 should be among the first two elements" );
19
+
20
+ // Check that lower weight element (10) is not in the first position
21
+ assertFalse (array [0 ] == 10 , "10 should not be the first element" );
26
22
}
27
23
28
24
// Test case for empty array
0 commit comments