You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2014/06/19 20:24:50 UTC

svn commit: r1603992 - in /lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial: ./ prefix/

Author: dsmiley
Date: Thu Jun 19 18:24:49 2014
New Revision: 1603992

URL: http://svn.apache.org/r1603992
Log:
LUCENE-5608: small test improvements.
Rename SpatialOpRecursivePrefixTreeTest to RandomSpatialOpFuzzyPrefixTreeTest.

Added:
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java
      - copied, changed from r1602791, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java
      - copied, changed from r1603308, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java
Removed:
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java
Modified:
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
    lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java?rev=1603992&r1=1603991&r2=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/QueryEqualsHashCodeTest.java Thu Jun 19 18:24:49 2014
@@ -91,8 +91,10 @@ public class QueryEqualsHashCodeTest ext
     Object second = generator.gen(args1);//should be the same
     assertEquals(first, second);
     assertEquals(first.hashCode(), second.hashCode());
-    second = generator.gen(args2);//now should be different
     assertNotSame(args1, args2);
+    second = generator.gen(args2);//now should be different
+    assertNotSame(first, second);
+    assertNotSame(first.hashCode(), second.hashCode());
   }
 
   private SpatialArgs makeArgs1() {

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java?rev=1603992&r1=1603991&r2=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java Thu Jun 19 18:24:49 2014
@@ -36,9 +36,8 @@ import org.apache.lucene.uninverting.Uni
 import org.apache.lucene.uninverting.UninvertingReader.Type;
 import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
 import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
-import org.apache.lucene.util.TestRuleLimitSysouts.Limit;
+import org.apache.lucene.util.TestUtil;
 import org.junit.After;
 import org.junit.Before;
 
@@ -63,7 +62,7 @@ public abstract class SpatialTestCase ex
 
   protected SpatialContext ctx;//subclass must initialize
 
-  Map<String,Type> uninvertMap = new HashMap<>();
+  protected Map<String,Type> uninvertMap = new HashMap<>();
   
   @Override
   @Before
@@ -77,8 +76,7 @@ public abstract class SpatialTestCase ex
     uninvertMap.put("bbox__maxY", Type.DOUBLE);
     uninvertMap.put("pointvector__x", Type.DOUBLE);
     uninvertMap.put("pointvector__y", Type.DOUBLE);
-    uninvertMap.put("SpatialOpRecursivePrefixTreeTest", Type.SORTED);
-    
+
     directory = newDirectory();
     final Random random = random();
     indexWriter = new RandomIndexWriter(random,directory, newIndexWriterConfig(random));

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java?rev=1603992&r1=1603991&r2=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/StrategyTestCase.java Thu Jun 19 18:24:49 2014
@@ -45,7 +45,6 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.logging.Logger;
 
@@ -224,6 +223,7 @@ public abstract class StrategyTestCase e
 //    }
 //    CheckHits.checkHits(random(), q, "", indexSearcher, expectedDocs);
 
+    //TopDocs is sorted but we actually don't care about the order
     TopDocs docs = indexSearcher.search(q, 1000);//calculates the score
     for (int i = 0; i < docs.scoreDocs.length; i++) {
       ScoreDoc gotSD = docs.scoreDocs[i];

Modified: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java?rev=1603992&r1=1603991&r2=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/DateNRStrategyTest.java Thu Jun 19 18:24:49 2014
@@ -29,7 +29,7 @@ import org.junit.Test;
 import java.io.IOException;
 import java.util.Calendar;
 
-public class DateNRStrategyTest extends BaseNonFuzzySpatialOpStrategyTest {
+public class DateNRStrategyTest extends RandomSpatialOpStrategyTestCase {
 
   static final int ITERATIONS = 10;
 

Copied: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java (from r1602791, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java?p2=lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java&p1=lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java&r1=1602791&r2=1603992&rev=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/SpatialOpRecursivePrefixTreeTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpFuzzyPrefixTreeTest.java Thu Jun 19 18:24:49 2014
@@ -39,6 +39,7 @@ import org.apache.lucene.spatial.prefix.
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
 import org.apache.lucene.spatial.query.SpatialArgs;
 import org.apache.lucene.spatial.query.SpatialOperation;
+import org.apache.lucene.uninverting.UninvertingReader;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -62,13 +63,23 @@ import static com.spatial4j.core.shape.S
 import static com.spatial4j.core.shape.SpatialRelation.INTERSECTS;
 import static com.spatial4j.core.shape.SpatialRelation.WITHIN;
 
-public class SpatialOpRecursivePrefixTreeTest extends StrategyTestCase {
+/** Randomized PrefixTree test that considers the fuzziness of the
+ * results introduced by grid approximation. */
+public class RandomSpatialOpFuzzyPrefixTreeTest extends StrategyTestCase {
 
   static final int ITERATIONS = 10;
 
   private SpatialPrefixTree grid;
   private SpatialContext ctx2D;
 
+  @Before
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    //Only for Disjoint.  Ugh; need to find a better way.  LUCENE-5692
+    uninvertMap.put(getClass().getSimpleName(), UninvertingReader.Type.SORTED);
+  }
+
   public void setupGrid(int maxLevels) throws IOException {
     if (randomBoolean())
       setupQuadGrid(maxLevels);

Copied: lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java (from r1603308, lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java?p2=lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java&p1=lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java&r1=1603308&r2=1603992&rev=1603992&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/BaseNonFuzzySpatialOpStrategyTest.java (original)
+++ lucene/dev/trunk/lucene/spatial/src/test/org/apache/lucene/spatial/prefix/RandomSpatialOpStrategyTestCase.java Thu Jun 19 18:24:49 2014
@@ -22,7 +22,6 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.spatial.StrategyTestCase;
 import org.apache.lucene.spatial.query.SpatialArgs;
 import org.apache.lucene.spatial.query.SpatialOperation;
-import org.junit.Ignore;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -36,10 +35,9 @@ import static com.carrotsearch.randomize
 /** Base test harness, ideally for SpatialStrategy impls that have exact results
  * (not grid approximated), hence "not fuzzy".
  */
-@Ignore("not actually a test: can this be renamed to *TestCase????")
-public abstract class BaseNonFuzzySpatialOpStrategyTest extends StrategyTestCase {
+public abstract class RandomSpatialOpStrategyTestCase extends StrategyTestCase {
 
-  //TODO this is partially redundant with StrategyTestCase.runTestQuery & testOperation
+  //Note: this is partially redundant with StrategyTestCase.runTestQuery & testOperation
 
   protected void testOperationRandomShapes(final SpatialOperation operation) throws IOException {
     //first show that when there's no data, a query will result in no results
@@ -114,18 +112,19 @@ public abstract class BaseNonFuzzySpatia
       for (SearchResult result : got.results) {
         String id = result.getId();
         if (!remainingExpectedIds.remove(id)) {
-          fail("Shouldn't match", id, indexedShapes, queryShape);
+          fail("Shouldn't match", id, indexedShapes, queryShape, operation);
         }
       }
       if (!remainingExpectedIds.isEmpty()) {
         String id = remainingExpectedIds.iterator().next();
-        fail("Should have matched", id, indexedShapes, queryShape);
+        fail("Should have matched", id, indexedShapes, queryShape, operation);
       }
     }
   }
 
-  private void fail(String label, String id, List<Shape> indexedShapes, Shape queryShape) {
-    fail(label + " I#" + id + ":" + indexedShapes.get(Integer.parseInt(id)) + " Q:" + queryShape);
+  private void fail(String label, String id, List<Shape> indexedShapes, Shape queryShape, SpatialOperation operation) {
+    fail("[" + operation + "] " + label
+        + " I#" + id + ":" + indexedShapes.get(Integer.parseInt(id)) + " Q:" + queryShape);
   }
 
   protected void preQueryHavoc() {