Skip to content

Commit e518ce8

Browse files
resolved issues
1 parent 1493800 commit e518ce8

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/test/java/com/thealgorithms/shufflealgorithm/UniquePairShuffleTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ void testPairShuffleTwoElements() {
6969

7070
// There should be 1 pair in the result
7171
assertEquals(1, pairs.size());
72-
assertEquals(1, pairs.get(0)[0]);
73-
assertEquals(2, pairs.get(0)[1]);
72+
int[] pair = pairs.get(0);
73+
74+
// Check that the pair contains both elements, regardless of order
75+
assertTrue((pair[0] == 1 && pair[1] == 2) || (pair[0] == 2 && pair[1] == 1));
7476
}
7577

7678
// Test case for larger even-length array

src/test/java/com/thealgorithms/shufflealgorithm/WeightedShuffleTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.thealgorithms.shufflealgorithm;
22

3-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
4-
import static org.junit.jupiter.api.Assertions.assertTrue;
5-
63
import com.thealgorithms.shufflealogrithm.WeightedShuffle;
74
import org.junit.jupiter.api.Test;
85

6+
import static org.junit.jupiter.api.Assertions.*;
7+
98
public class WeightedShuffleTest {
109

1110
// Test case for matching array and weights
@@ -15,14 +14,11 @@ void testWeightedShuffleBasic() {
1514
int[] weights = {1, 3, 2};
1615
WeightedShuffle.weightedShuffle(array, weights);
1716

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");
2622
}
2723

2824
// Test case for empty array

0 commit comments

Comments
 (0)