improved tests

parent 483bbe2b
......@@ -6,6 +6,8 @@ import static org.junit.Assert.assertTrue;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.heigit.bigspatialdata.oshdb.util.OSHDBBoundingBox;
import org.heigit.bigspatialdata.oshdb.util.geometry.OSHDBGeometryBuilder;
import org.heigit.ohsome.filter.GeometryFilter.ValueRange;
import org.heigit.ohsome.filter.GeometryTypeFilter.GeometryType;
import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
......@@ -20,13 +22,15 @@ public class ApplyOSMGeometryTest extends FilterTest {
@Test
public void testGeometryTypeFilterPoint() {
FilterExpression expression = parser.parse("geometry:point");
Filter expression = new GeometryTypeFilter(GeometryType.POINT, this.tagTranslator);
assertTrue(expression.isGeometryFilter());
assertTrue(expression.applyOSMGeometry(createTestEntityNode(), gf.createPoint()));
}
@Test
public void testGeometryTypeFilterLine() {
FilterExpression expression = parser.parse("geometry:line");
Filter expression = new GeometryTypeFilter(GeometryType.LINE, this.tagTranslator);
assertTrue(expression.isGeometryFilter());
OSMEntity validWay = createTestEntityWay(new long[]{1, 2, 3, 4, 1});
assertTrue(expression.applyOSMGeometry(validWay, gf.createLineString()));
assertFalse(expression.applyOSMGeometry(validWay, gf.createPolygon()));
......@@ -34,7 +38,8 @@ public class ApplyOSMGeometryTest extends FilterTest {
@Test
public void testGeometryTypeFilterPolygon() {
FilterExpression expression = parser.parse("geometry:polygon");
Filter expression = new GeometryTypeFilter(GeometryType.POLYGON, this.tagTranslator);
assertTrue(expression.isGeometryFilter());
OSMEntity validWay = createTestEntityWay(new long[]{1, 2, 3, 4, 1});
assertTrue(expression.applyOSMGeometry(validWay, gf.createPolygon()));
assertFalse(expression.applyOSMGeometry(validWay, gf.createLineString()));
......@@ -48,7 +53,8 @@ public class ApplyOSMGeometryTest extends FilterTest {
@Test
public void testGeometryTypeFilterOther() {
FilterExpression expression = parser.parse("geometry:other");
Filter expression = new GeometryTypeFilter(GeometryType.OTHER, this.tagTranslator);
assertTrue(expression.isGeometryFilter());
OSMEntity validRelation = createTestEntityRelation();
assertTrue(expression.applyOSMGeometry(validRelation, gf.createGeometryCollection()));
assertFalse(expression.applyOSMGeometry(validRelation, gf.createPolygon()));
......@@ -93,7 +99,8 @@ public class ApplyOSMGeometryTest extends FilterTest {
@Test
public void testGeometryFilterArea() {
FilterExpression expression = parser.parse("area:(1..2)");
Filter expression = new GeometryFilterArea(new ValueRange(1, 2));
assertTrue(expression.isGeometryFilter());
OSMEntity entity = createTestEntityWay(new long[] {1, 2, 3, 4, 1});
assertFalse(expression.applyOSMGeometry(entity,
// approx 0.3m²
......@@ -111,7 +118,8 @@ public class ApplyOSMGeometryTest extends FilterTest {
@Test
public void testGeometryFilterLength() {
FilterExpression expression = parser.parse("length:(1..2)");
Filter expression = new GeometryFilterLength(new ValueRange(1, 2));
assertTrue(expression.isGeometryFilter());
OSMEntity entity = createTestEntityWay(new long[] {1, 2});
assertFalse(expression.applyOSMGeometry(entity,
// approx 0.6m
......
......@@ -9,12 +9,13 @@ import java.util.Collections;
import org.heigit.bigspatialdata.oshdb.osm.OSMEntity;
import org.heigit.bigspatialdata.oshdb.osm.OSMType;
import org.heigit.bigspatialdata.oshdb.util.OSHDBTag;
import org.heigit.bigspatialdata.oshdb.util.geometry.Geo;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.OSMTag;
import org.heigit.bigspatialdata.oshdb.util.tagtranslator.OSMTagKey;
import org.heigit.ohsome.filter.GeometryFilter.ValueRange;
import org.heigit.ohsome.filter.GeometryTypeFilter.GeometryType;
import org.junit.Test;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
/**
......@@ -211,16 +212,24 @@ public class NegateTest extends FilterTest {
ConstantFilter expression = new ConstantFilter(true);
FilterExpression negation = expression.negate();
assertTrue(negation instanceof ConstantFilter);
assertNotEquals(expression.getState(), ((ConstantFilter) negation).getState());
OSMEntity node = createTestEntityNode();
assertNotEquals(expression.applyOSM(node), negation.applyOSM(node));
}
@Test
public void testGeometryFilters() {
public void testGeometryFilterLength() {
GeometryFilter expression = new GeometryFilterLength(new ValueRange(1, 2));
assertTrue(expression.isGeometryFilter());
OSMEntity entity = createTestEntityWay(new long[] {1, 2});
// approx 1.1m
Geometry geom = (new GeometryFactory()).createLineString(new Coordinate[]{
new Coordinate(0, 0),
new Coordinate(1E-5, 0)
});
Filter negation = expression.negate();
assertTrue(negation.isGeometryFilter());
assertNotEquals(
expression.applyOSMGeometry(entity, geom),
negation.applyOSMGeometry(entity, geom)
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment