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:
Michael McCandless 2015-09-01 09:32:44 +00:00
parent 1017a685b2
commit 6d5b236dea
1 changed files with 16 additions and 9 deletions

View File

@ -257,18 +257,25 @@ public class AutomatonTestUtil {
}
}
/** return a random NFA/DFA for testing */
public static Automaton randomAutomaton(Random random) {
// get two random Automata from regexps
private static Automaton randomSingleAutomaton(Random random) {
while (true) {
try {
Automaton a1 = new RegExp(AutomatonTestUtil.randomRegexp(random), RegExp.NONE).toAutomaton();
if (random.nextBoolean()) {
a1 = Operations.complement(a1, DEFAULT_MAX_DETERMINIZED_STATES);
}
Automaton a2 = new RegExp(AutomatonTestUtil.randomRegexp(random), RegExp.NONE).toAutomaton();
if (random.nextBoolean()) {
a2 = Operations.complement(a2, DEFAULT_MAX_DETERMINIZED_STATES);
return a1;
} catch (TooComplexToDeterminizeException tctde) {
// This can (rarely) happen if the random regexp is too hard; just try again...
}
}
}
/** 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
switch (random.nextInt(4)) {