Commit 969d4f54 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add Test for overlap Messages of TopographyChecker

parent 7d67883e
......@@ -321,6 +321,7 @@ TopographyChecker.overlap.target.stair=A target and a stairs element overlap in
TopographyChecker.overlap.source.stair=A source and a stairs element overlap in scenario.
TopographyChecker.overlap.source.target=A source and a target element overlap in scenario.
TopographyChecker.overlap.source.source=Two source overlap. This can cause overlapping when useFreeSpaceOnly is not set.
TopographyChecker.overlap.target.target=Two targets overlap.
TopographyChecker.overlap.obstacle.stairs.err=Stairs is completely contained in an obstacle.
TopographyChecker.overlap.obstacle.stairs.warn=Stairs contains an obstacle. This setup works put is not tested. Split in two stairs.
TopographyChecker.overlap.obstacle.target.err=Target is completely contained in an obstacle.
......
......@@ -317,6 +317,7 @@ TopographyChecker.overlap.target.stair=Ein Ziel und eine Treppen \u00fcberlappen
TopographyChecker.overlap.source.stair=Eine Quelle und eine Treppe \u00fcberlappen im Scenario.
TopographyChecker.overlap.source.target=Eine Quelle und eine Ziel \u00fcberappen im Scenario.
TopographyChecker.overlap.source.source=Zwei Quellen \u00fcberlappen. Wenn useFreeSpaceOnly nicht gesetzt ist kann dies zu \u00fcberlappungen von Pedestrians f\u00fchren.
TopographyChecker.overlap.target.target=Zwei Ziele \u00fcberlappen.
TopographyChecker.overlap.obstacle.stairs.err=Treppe ist komplett in einem Hinderniss eingeschossen.
TopographyChecker.overlap.obstacle.stairs.warn=Treppe hat ein Hinderiss in sich. Dies ist m\u00f6glich aber nicht getestet. Wenn m\u00f6glich in zwei treppen aufteilen.
TopographyChecker.overlap.obstacle.target.err=Ziel ist komplett in einem Hinderniss eingeschlossen
......
......@@ -161,7 +161,7 @@ public class TopographyChecker {
.reason(TopographyCheckerReason.OVERLAP_OBSTACLE_TARGET_ERR).build());
}else if (obstacle.overlapWith(target)) {
ret.add(msgBuilder.warning().target(obstacle, target)
.reason(TopographyCheckerReason.OVERLAP_OBSTACLE_TARGET_ERR).build());
.reason(TopographyCheckerReason.OVERLAP_OBSTACLE_TARGET_WARN).build());
}
}
......@@ -208,7 +208,10 @@ public class TopographyChecker {
}
private void handelTargetTargetOverlap(ScenarioElement e1, ScenarioElement e2, List<TopographyCheckerMessage> ret) {
//todo
if (e1.overlapWith(e2)) {
ret.add(msgBuilder.warning().target(e1, e2)
.reason(TopographyCheckerReason.OVERLAP_TARGET_TARGET).build());
}
}
// WARN total overlap == partial overlap
......@@ -375,8 +378,4 @@ public class TopographyChecker {
return ret;
}
public void doCreatorChecks() {
}
}
......@@ -56,6 +56,10 @@ public class TopographyCheckerMessage implements Comparable<TopographyCheckerMes
this.reasonModifier = reasonModifier;
}
public boolean isMessageForAllElements(Integer... ids){
return msgTarget.affectsAllTargets(ids);
}
private Comparator<TopographyCheckerMessage> sortByType() {
return (o1, o2) -> {
if (o1.equals(o2))
......
......@@ -31,6 +31,15 @@ public class TopographyCheckerMessageTarget {
this.targets = new ArrayList<>(Arrays.asList(targets));;
}
public boolean affectsAllTargets(Integer... ids){
for (Integer id : ids) {
if(targets.stream().noneMatch(e -> e.getId() == id)){
return false;
}
}
return true;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
......@@ -15,6 +15,7 @@ public enum TopographyCheckerReason {
STAIRS_TREAD_DIM_WRONG("TopographyChecker.stairs.wrongTreadDim"),
OVERLAP_STAIR_STAIR("TopographyChecker.overlap.stair.stair"),
OVERLAP_TARGET_TARGET("TopographyChecker.overlap.target.target"),
OVERLAP_TARGET_STAIR("TopographyChecker.overlap.target.stair"),
OVERLAP_SOURCE_STAIR("TopographyChecker.overlap.source.stair"),
OVERLAP_SOURCE_TARGET("TopographyChecker.overlap.source.target"),
......
......@@ -4,6 +4,7 @@ import org.apache.commons.math3.util.Pair;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.vadere.simulator.projects.Scenario;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.state.attributes.scenario.builder.AttributesAgentBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesObstacleBuilder;
......@@ -14,21 +15,22 @@ import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Topography;
import org.vadere.tests.util.reflection.TestResourceHandler;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import java.awt.geom.Area;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.*;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
public class TopographyCheckerTest {
public class TopographyCheckerTest implements TestResourceHandler {
TopographyTestBuilder builder;
......@@ -527,6 +529,61 @@ public class TopographyCheckerTest {
assertEquals(TopographyCheckerReason.PEDESTRIAN_SPEED_NEGATIVE, msg.getReason());
}
@Test
public void testCheckOverlapAllCases(){
Scenario testScenarioWithErrors = getScenarioFromRelativeResource("TopographyCheckerTest.scenario");
TopographyChecker checker = new TopographyChecker(testScenarioWithErrors.getTopography());
List<TopographyCheckerMessage> out = checker.checkOverlap((type, type2) -> true); //activate all tests.
assertEquals(22, out.size());
List<TopographyCheckerMessage> errorMsg = out.stream()
.filter(m -> m.getMsgType().equals(TopographyCheckerMessageType.ERROR))
.collect(Collectors.toList());
assertEquals(6, errorMsg.size());
List<TopographyCheckerMessage> warnMsg = out.stream()
.filter(m -> m.getMsgType().equals(TopographyCheckerMessageType.WARN))
.collect(Collectors.toList());
assertEquals(16, warnMsg.size());
// Errors
assertIdAndReason(1,6,TopographyCheckerReason.OVERLAP_OBSTACLE_SOURCE, errorMsg);
assertIdAndReason(2,6,TopographyCheckerReason.OVERLAP_OBSTACLE_SOURCE, errorMsg);
assertIdAndReason(9,8,TopographyCheckerReason.OVERLAP_OBSTACLE_TARGET_ERR, errorMsg);
assertIdAndReason(11,13,TopographyCheckerReason.OVERLAP_OBSTACLE_STAIRS_ERR, errorMsg);
assertIdAndReason(35,36,TopographyCheckerReason.OVERLAP_STAIR_STAIR, errorMsg);
assertIdAndReason(35,36,TopographyCheckerReason.OVERLAP_STAIR_STAIR, errorMsg);
// Warnings
assertIdAndReason(4,5,TopographyCheckerReason.OVERLAP_OBSTACLE_OBSTACLE, warnMsg);
assertIdAndReason(9,7,TopographyCheckerReason.OVERLAP_OBSTACLE_TARGET_WARN, warnMsg);
assertIdAndReason(11,12,TopographyCheckerReason.OVERLAP_OBSTACLE_STAIRS_WARN, warnMsg);
assertIdAndReason(22,24,TopographyCheckerReason.OVERLAP_SOURCE_STAIR, warnMsg);
assertIdAndReason(22,25,TopographyCheckerReason.OVERLAP_SOURCE_STAIR, warnMsg);
assertIdAndReason(23,26,TopographyCheckerReason.OVERLAP_SOURCE_STAIR, warnMsg);
assertIdAndReason(30,32,TopographyCheckerReason.OVERLAP_TARGET_STAIR, warnMsg);
assertIdAndReason(30,33,TopographyCheckerReason.OVERLAP_TARGET_STAIR, warnMsg);
assertIdAndReason(31,34,TopographyCheckerReason.OVERLAP_TARGET_STAIR, warnMsg);
assertIdAndReason(17,19,TopographyCheckerReason.OVERLAP_SOURCE_TARGET, warnMsg);
assertIdAndReason(17,20,TopographyCheckerReason.OVERLAP_SOURCE_TARGET, warnMsg);
assertIdAndReason(18,21,TopographyCheckerReason.OVERLAP_SOURCE_TARGET, warnMsg);
assertIdAndReason(27,28,TopographyCheckerReason.OVERLAP_TARGET_TARGET, warnMsg);
assertIdAndReason(27,29,TopographyCheckerReason.OVERLAP_TARGET_TARGET, warnMsg);
assertIdAndReason(14,15,TopographyCheckerReason.OVERLAP_SOURCE_SOURCE, warnMsg);
assertIdAndReason(14,16,TopographyCheckerReason.OVERLAP_SOURCE_SOURCE, warnMsg);
}
private void assertIdAndReason(int idA, int idB, TopographyCheckerReason reason, List<TopographyCheckerMessage> messages){
List<TopographyCheckerMessage> msg = messages.stream()
.filter(m -> m.isMessageForAllElements(idA, idB) && m.getReason().equals(reason))
.collect(Collectors.toList());
assertEquals("expected Message with ids{" + idA + ", " + idB + "} and Reason: "+ reason.toString(), 1, msg.size());
}
private TopographyCheckerMessage hasOneElement(List<TopographyCheckerMessage> out){
assertEquals(1, out.size());
......@@ -545,4 +602,8 @@ public class TopographyCheckerTest {
assertEquals(TopographyCheckerMessageType.WARN, msg.getMsgType());
}
@Override
public Path getTestDir() {
return getPathFromResources("/data/TopographyChecker");
}
}
\ No newline at end of file
package org.vadere.tests.util.reflection;
import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.TestUtils;
import org.vadere.util.io.IOUtils;
......@@ -59,6 +61,16 @@ public interface TestResourceHandler {
return ret;
}
default Scenario getScenarioFromRelativeResource(String name){
Scenario scenario = null;
try {
scenario = ScenarioFactory.createScenarioWithScenarioFilePath(getRelativeTestPath(name));
} catch (IOException e) {
fail("Resource not found: " + getTestDir().resolve(name).toString());
}
return scenario;
}
default Path getTestFileBackup(String fileName) {
return getTestDirBackup().resolve(fileName);
}
......
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