lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1700440 - /lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java
Date Tue, 01 Sep 2015 09:29:36 GMT
Author: mikemccand
Date: Tue Sep  1 09:29:36 2015
New Revision: 1700440

URL: http://svn.apache.org/r1700440
Log:
just retry if automaton is too complex to determinize

Modified:
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java

Modified: lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java?rev=1700440&r1=1700439&r2=1700440&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java
(original)
+++ lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/util/automaton/AutomatonTestUtil.java
Tue Sep  1 09:29:36 2015
@@ -256,19 +256,26 @@ public class AutomatonTestUtil {
       return ArrayUtil.toIntArray(soFar);
     }
   }
+
+  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);
+        }
+        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 = 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);
-    }
+    Automaton a1 = randomSingleAutomaton(random);
+    Automaton a2 = randomSingleAutomaton(random);
 
     // combine them in random ways
     switch (random.nextInt(4)) {



Mime
View raw message