Commit 45b8f722 authored by Riegel's avatar Riegel
Browse files

Add tests for new datastructures

parent 01673d2c
Pipeline #10322 passed with stage
in 1 minute and 34 seconds
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
public class CompositePolygonTest {
@Test
public void testCompositePolygonParsing() throws CityGmlParseException, InvalidGmlFileException {
ParserConfiguration config = new ParserConfiguration(8, false);
CityDoctorModel m = CityGmlParser.parseCityGmlFile("src/test/resources/FZK_haus.gml", config);
Building b = m.getBuildings().get(0);
assertNotNull(b);
assertFalse(b.getBoundarySurfaces().isEmpty());
for (BoundarySurface bs : b.getBoundarySurfaces()) {
assertNotNull(bs);
assertFalse(bs.getGeometries().isEmpty());
for (Geometry geom : bs.getGeometries()) {
assertNotNull(geom);
assertFalse(geom.getPolygons().isEmpty());
}
}
}
}
package de.hft.stuttgart.citydoctor2.datastructure;
import de.hft.stuttgart.citydoctor2.check.AbstractCheck;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import org.citygml4j.core.model.core.ImplicitGeometry;
import org.citygml4j.core.model.core.TransformationMatrix4x4;
import org.junit.Before;
import org.junit.Test;
import org.xmlobjects.gml.model.geometry.DirectPosition;
import org.xmlobjects.gml.model.geometry.primitives.Point;
import org.xmlobjects.gml.model.geometry.primitives.PointProperty;
import org.xmlobjects.gml.util.jama.Matrix;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.*;
public class ImplicitGeometryTest {
private Path path;
private ParserConfiguration config;
private String pathString = "src/test/resources/ImplicitTestGeom.gml";
private TransformationMatrix4x4 origin;
@Before
public void setUp() {
path = Paths.get(pathString);
config = new ParserConfiguration(8, false);
Matrix og = new Matrix(4, 4);
og.set(0, 0, 1);
og.set(1, 1, 1);
og.set(2, 2, 1);
origin = new TransformationMatrix4x4(og);
}
@Test
public void testLibraryObjectParsing() {
LibraryObject lo = LibraryObject.of(path, config);
assertNotNull(lo);
LibraryObject lo2 = LibraryObject.of(path, config);
assertSame(lo, lo2);
}
@Test
public void testObjectTransform() {
LibraryObject lo = LibraryObject.of(path, config);
assertNotNull(lo);
ImplicitGeometry geom = new ImplicitGeometry();
geom.setTransformationMatrix(origin);
geom.setReferencePoint(new PointProperty(new Point(new DirectPosition(0, 0))));
ImplicitGeometryHolder igh = new ImplicitGeometryHolder(geom, lo);
assertNotNull(igh);
geom.setReferencePoint(new PointProperty(new Point(new DirectPosition(5, 8))));
ImplicitGeometryHolder igh2 = new ImplicitGeometryHolder(geom, lo);
assertNotNull(igh2);
assertNotEquals(igh, igh2);
BoundingBox bb1 = BoundingBox.of(igh.getPolygons());
BoundingBox bb2 = BoundingBox.of(igh2.getPolygons());
assertNotEquals(bb1, bb2);
}
@Test
public void testAccept() {
LibraryObject lib = LibraryObject.of(path, config);
assertNotNull(lib);
ImplicitGeometry geom = new ImplicitGeometry();
geom.setTransformationMatrix(origin);
geom.setReferencePoint(new PointProperty(new Point(new DirectPosition(0, 0))));
int polyCount = lib.getPolygons().size();
ImplicitGeometryHolder igh = new ImplicitGeometryHolder(geom, lib);
AtomicInteger loCounter = new AtomicInteger(0);
AbstractCheck c = new AbstractCheck() {
@Override
public void check(Polygon lo) {
loCounter.incrementAndGet();
}
};
igh.accept(c);
assertEquals("ImplicitGeometryHolder should only check polygons of prototype geometry",
polyCount, loCounter.intValue());
}
}
This diff is collapsed.
Supports Markdown
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