mirror of https://github.com/apache/lucene.git
just retry if automaton is too complex to determinize
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1700444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1017a685b2
commit
6d5b236dea
|
@ -257,18 +257,25 @@ public class AutomatonTestUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** return a random NFA/DFA for testing */
|
private static Automaton randomSingleAutomaton(Random random) {
|
||||||
public static Automaton randomAutomaton(Random random) {
|
while (true) {
|
||||||
// get two random Automata from regexps
|
try {
|
||||||
Automaton a1 = new RegExp(AutomatonTestUtil.randomRegexp(random), RegExp.NONE).toAutomaton();
|
Automaton a1 = new RegExp(AutomatonTestUtil.randomRegexp(random), RegExp.NONE).toAutomaton();
|
||||||
if (random.nextBoolean()) {
|
if (random.nextBoolean()) {
|
||||||
a1 = Operations.complement(a1, DEFAULT_MAX_DETERMINIZED_STATES);
|
a1 = Operations.complement(a1, DEFAULT_MAX_DETERMINIZED_STATES);
|
||||||
}
|
}
|
||||||
|
return a1;
|
||||||
Automaton a2 = new RegExp(AutomatonTestUtil.randomRegexp(random), RegExp.NONE).toAutomaton();
|
} catch (TooComplexToDeterminizeException tctde) {
|
||||||
if (random.nextBoolean()) {
|
// This can (rarely) happen if the random regexp is too hard; just try again...
|
||||||
a2 = Operations.complement(a2, DEFAULT_MAX_DETERMINIZED_STATES);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** return a random NFA/DFA for testing */
|
||||||
|
public static Automaton randomAutomaton(Random random) {
|
||||||
|
// get two random Automata from regexps
|
||||||
|
Automaton a1 = randomSingleAutomaton(random);
|
||||||
|
Automaton a2 = randomSingleAutomaton(random);
|
||||||
|
|
||||||
// combine them in random ways
|
// combine them in random ways
|
||||||
switch (random.nextInt(4)) {
|
switch (random.nextInt(4)) {
|
||||||
|
|
Loading…
Reference in New Issue