|
19 | 19 |
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.util.Arrays;
|
| 22 | +import java.util.Collections; |
22 | 23 | import java.util.HashSet;
|
23 | 24 | import java.util.Set;
|
24 | 25 | import java.util.stream.Collectors;
|
@@ -401,6 +402,35 @@ public void testUnorderedWithRepeatsAndMaxGaps() throws IOException {
|
401 | 402 | source, "field1", 3, new int[][] {{}, {0, 3, 2, 6}, {3, 6}, {}, {0, 3, 2, 6}, {}});
|
402 | 403 | }
|
403 | 404 |
|
| 405 | + public void testIntervalDisjunctionToStringStability() { |
| 406 | + /* |
| 407 | + Sanity check that the subclauses of a disjunction are presented in sorted order via the toString() method. |
| 408 | + The exact order is irrelevant, but ensuring stability of output makes the output more useful; e.g., for external |
| 409 | + comparison across different JVMs, etc... |
| 410 | + */ |
| 411 | + final int size = |
| 412 | + random().nextInt(22) + 4; // ensure a reasonably large minimum number of clauses |
| 413 | + final String[] terms = new String[size]; |
| 414 | + for (int i = 0; i < size; i++) { |
| 415 | + terms[i] = Character.toString((char) ('a' + i)); |
| 416 | + } |
| 417 | + final String expected = Arrays.stream(terms).collect(Collectors.joining(",", "or(", ")")); |
| 418 | + |
| 419 | + /* |
| 420 | + NOTE: shuffling below shouldn't matter at the moment (because the disjunction subSources are destined for a |
| 421 | + HashMap, so will be reordered anyway); but it might matter if the internal implementation of |
| 422 | + DisjunctionIntervalsSource changes. |
| 423 | + */ |
| 424 | + Collections.shuffle(Arrays.asList(terms), random()); |
| 425 | + |
| 426 | + IntervalsSource source = |
| 427 | + Intervals.or( |
| 428 | + Arrays.stream(terms) |
| 429 | + .map((term) -> Intervals.term(term)) |
| 430 | + .toArray((sz) -> new IntervalsSource[sz])); |
| 431 | + assertEquals(expected, source.toString()); |
| 432 | + } |
| 433 | + |
404 | 434 | public void testIntervalDisjunction() throws IOException {
|
405 | 435 | IntervalsSource source =
|
406 | 436 | Intervals.or(Intervals.term("pease"), Intervals.term("hot"), Intervals.term("notMatching"));
|
|
0 commit comments