From 33bf336cd48bbd8a656e41e7c8a52e45a89a97b9 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 1 Jul 2014 16:52:20 +0000 Subject: [PATCH] remove dead states after union(), just like intersection() and complement() do git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1607139 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/automaton/Operations.java | 2 +- .../org/apache/lucene/util/automaton/TestOperations.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java index 24f85f8a8d6..02e84c220b5 100644 --- a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java +++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java @@ -505,7 +505,7 @@ final public class Operations { result.finishState(); - return result; + return removeDeadStates(result); } // Simple custom ArrayList diff --git a/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java b/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java index e4f228033f0..7b2db1f0080 100644 --- a/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java +++ b/lucene/core/src/test/org/apache/lucene/util/automaton/TestOperations.java @@ -34,7 +34,14 @@ public class TestOperations extends LuceneTestCase { Collections.sort(strings); Automaton union = Automata.makeStringUnion(strings); assertTrue(union.isDeterministic()); - assertTrue(Operations.sameLanguage(union, naiveUnion(strings))); + assertFalse(Operations.hasDeadStatesFromInitial(union)); + + Automaton naiveUnion = naiveUnion(strings); + assertTrue(naiveUnion.isDeterministic()); + assertFalse(Operations.hasDeadStatesFromInitial(naiveUnion)); + + + assertTrue(Operations.sameLanguage(union, naiveUnion)); } private static Automaton naiveUnion(List strings) {