|
31 | 31 |
|
32 | 32 | import java.io.IOException; |
33 | 33 | import java.util.ArrayList; |
| 34 | +import java.util.Arrays; |
34 | 35 | import java.util.HashMap; |
35 | 36 | import java.util.List; |
36 | 37 | import java.util.Map; |
37 | 38 |
|
| 39 | +import static org.elasticsearch.test.ListMatcher.matchesList; |
38 | 40 | import static org.elasticsearch.test.MapMatcher.assertMap; |
39 | 41 | import static org.elasticsearch.test.MapMatcher.matchesMap; |
40 | 42 | import static org.hamcrest.Matchers.equalTo; |
@@ -89,6 +91,27 @@ private void testRead(BlockFactory factory) throws IOException { |
89 | 91 | } |
90 | 92 | } |
91 | 93 |
|
| 94 | + public void testCompactWithNulls() { |
| 95 | + assertCompactToUnique(new int[] { -1, -1, -1, -1, 0, 1, 2 }, List.of(0, 1, 2)); |
| 96 | + } |
| 97 | + |
| 98 | + public void testCompactNoNulls() { |
| 99 | + assertCompactToUnique(new int[] { 0, 1, 2 }, List.of(0, 1, 2)); |
| 100 | + } |
| 101 | + |
| 102 | + public void testCompactDups() { |
| 103 | + assertCompactToUnique(new int[] { 0, 0, 0, 1, 2 }, List.of(0, 1, 2)); |
| 104 | + } |
| 105 | + |
| 106 | + public void testCompactSkips() { |
| 107 | + assertCompactToUnique(new int[] { 2, 7, 1000 }, List.of(2, 7, 1000)); |
| 108 | + } |
| 109 | + |
| 110 | + private void assertCompactToUnique(int[] sortedOrds, List<Integer> expected) { |
| 111 | + int uniqueLength = SingletonOrdinalsBuilder.compactToUnique(sortedOrds); |
| 112 | + assertMap(Arrays.stream(sortedOrds).mapToObj(Integer::valueOf).limit(uniqueLength).toList(), matchesList(expected)); |
| 113 | + } |
| 114 | + |
92 | 115 | private final List<CircuitBreaker> breakers = new ArrayList<>(); |
93 | 116 | private final List<BlockFactory> blockFactories = new ArrayList<>(); |
94 | 117 |
|
|
0 commit comments