Removed RandomSeed; simply extend LuceneTestCase instead.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3795_lsp_spatial_module@1291611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2012-02-21 05:57:35 +00:00
parent 34ddc3c6c2
commit 8fc20e2b77
3 changed files with 6 additions and 55 deletions

View File

@ -1,34 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.lucene.spatial;
/**
* Reads "tests.seed" system property to initialized a global final constant.
* @author David Smiley - dsmiley@mitre.org
*/
public class RandomSeed {
private static final long _seed;
static {
_seed = Long.parseLong(System.getProperty("tests.seed", "" + System.currentTimeMillis()));
System.out.println("tests.seed="+_seed);
}
public static long seed() {
return _seed;
}
private RandomSeed() {}
}

View File

@ -17,26 +17,20 @@
package org.apache.lucene.spatial.base.distance; package org.apache.lucene.spatial.base.distance;
import org.apache.lucene.spatial.RandomSeed;
import org.apache.lucene.spatial.base.context.SpatialContext; import org.apache.lucene.spatial.base.context.SpatialContext;
import org.apache.lucene.spatial.base.context.simple.SimpleSpatialContext; import org.apache.lucene.spatial.base.context.simple.SimpleSpatialContext;
import org.apache.lucene.spatial.base.shape.SpatialRelation;
import org.apache.lucene.spatial.base.shape.Point; import org.apache.lucene.spatial.base.shape.Point;
import org.apache.lucene.spatial.base.shape.Rectangle; import org.apache.lucene.spatial.base.shape.Rectangle;
import org.apache.lucene.spatial.base.shape.SpatialRelation;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Random;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* @author David Smiley - dsmiley@mitre.org * @author David Smiley - dsmiley@mitre.org
*/ */
public class TestDistances { public class TestDistances extends LuceneTestCase {
private final Random random = new Random(RandomSeed.seed());
//NOTE! These are sometimes modified by tests. //NOTE! These are sometimes modified by tests.
private SpatialContext ctx; private SpatialContext ctx;
private double EPS; private double EPS;
@ -225,7 +219,6 @@ public class TestDistances {
for (double[] pair : lats) { for (double[] pair : lats) {
assertEquals("input "+pair[0],pair[1],ctx.normY(pair[0]),0); assertEquals("input "+pair[0],pair[1],ctx.normY(pair[0]),0);
} }
Random random = new Random(RandomSeed.seed());
for(int i = -1000; i < 1000; i += random.nextInt(10)*10) { for(int i = -1000; i < 1000; i += random.nextInt(10)*10) {
double d = ctx.normY(i); double d = ctx.normY(i);
assertTrue(i + " " + d, d >= -90 && d <= 90); assertTrue(i + " " + d, d >= -90 && d <= 90);
@ -241,7 +234,6 @@ public class TestDistances {
for (double[] pair : lons) { for (double[] pair : lons) {
assertEquals("input "+pair[0],pair[1],ctx.normX(pair[0]),0); assertEquals("input "+pair[0],pair[1],ctx.normX(pair[0]),0);
} }
Random random = new Random(RandomSeed.seed());
for(int i = -1000; i < 1000; i += random.nextInt(10)*10) { for(int i = -1000; i < 1000; i += random.nextInt(10)*10) {
double d = ctx.normX(i); double d = ctx.normX(i);
assertTrue(i + " " + d, d >= -180 && d < 180); assertTrue(i + " " + d, d >= -180 && d < 180);

View File

@ -17,32 +17,25 @@
package org.apache.lucene.spatial.base.shape; package org.apache.lucene.spatial.base.shape;
import org.apache.lucene.spatial.RandomSeed;
import org.apache.lucene.spatial.base.context.SpatialContext; import org.apache.lucene.spatial.base.context.SpatialContext;
import org.apache.lucene.spatial.base.distance.DistanceCalculator; import org.apache.lucene.spatial.base.distance.DistanceCalculator;
import org.apache.lucene.util.LuceneTestCase;
import org.junit.Before; import org.junit.Before;
import java.util.Random; import java.util.Random;
import static org.apache.lucene.spatial.base.shape.SpatialRelation.CONTAINS; import static org.apache.lucene.spatial.base.shape.SpatialRelation.*;
import static org.apache.lucene.spatial.base.shape.SpatialRelation.DISJOINT;
import static org.apache.lucene.spatial.base.shape.SpatialRelation.WITHIN;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/** /**
* @author David Smiley - dsmiley@mitre.org * @author David Smiley - dsmiley@mitre.org
*/ */
public abstract class AbstractTestShapes { public abstract class AbstractTestShapes extends LuceneTestCase {
protected Random random;
protected SpatialContext ctx; protected SpatialContext ctx;
private static final double EPS = 10e-9; private static final double EPS = 10e-9;
@Before @Before
public void beforeClass() { public void beforeClass() {
random = new Random(RandomSeed.seed());
ctx = getContext(); ctx = getContext();
} }