11.3.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 739aba4a authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add overlap processor test for edge cases

parent 27b12f3f
......@@ -18,7 +18,6 @@ public class JoltTransformV4toV5 extends JoltTransformation {
@Override
protected void initPostHooks() {
postTransformHooks.add(this::cleanupPedestrianOverlapProcessorAttribute);
postTransformHooks.add(this::addOverlapProcessors);
postTransformHooks.add(JoltTransformV1toV2::sort);
}
......@@ -38,9 +37,6 @@ public class JoltTransformV4toV5 extends JoltTransformation {
return node;
}
private JsonNode addOverlapProcessors(JsonNode node) throws MigrationException {
return node;
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import static org.junit.Assert.*;
public class NumberOverlapsProcessorTest {
}
\ No newline at end of file
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.vadere.simulator.control.SimulationState;
......@@ -20,6 +21,25 @@ public class PedestrianOverlapProcessorTest extends ProcessorTest {
super.doUpdate();
}
@Test
public void doUpdateWithOverlap() throws Exception {
((PedestrianOverlapProcessorTestEnv)processorTestEnv).verySmallOverlapping();
super.doUpdate();
}
@Test
public void doUpdateWithoutOverlap() throws Exception {
((PedestrianOverlapProcessorTestEnv)processorTestEnv).verySmallNotOverlapping();
super.doUpdate();
}
@Test
@Ignore
public void doUpdateWithTouching() throws Exception {
((PedestrianOverlapProcessorTestEnv)processorTestEnv).touching();
super.doUpdate();
}
@Test
public void init() throws Exception {
assertInit(p);
......@@ -36,4 +56,7 @@ public class PedestrianOverlapProcessorTest extends ProcessorTest {
assertInit(p);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlap;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.LinkedCellsGrid;
......@@ -14,6 +15,7 @@ import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import static org.mockito.ArgumentMatchers.doubleThat;
import static org.mockito.Mockito.mock;
public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdOverlap, Double> {
......@@ -38,10 +40,10 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
LinkedCellsGrid<DynamicElement> getCellGridMock(PedestrianListBuilder b){
LinkedCellsGrid<DynamicElement> cellsGrid = new LinkedCellsGrid<>(0.0,0.0, 10.0, 10.0, 1);
LinkedCellsGrid<DynamicElement> getCellGridMock(PedestrianListBuilder b) {
LinkedCellsGrid<DynamicElement> cellsGrid = new LinkedCellsGrid<>(0.0, 0.0, 10.0, 10.0, 1);
b.getDynamicElementList().forEach(e -> cellsGrid.addObject(e));
return cellsGrid;
return cellsGrid;
}
@Override
......@@ -75,8 +77,8 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
Mockito.when(state.getTopography().getAttributesPedestrian().getRadius()).thenReturn(0.195);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 5), b.getDistByPedId(1,5));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 5, 1), b.getDistByPedId(5,1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 5), b.getDistByPedId(1, 5));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 5, 1), b.getDistByPedId(5, 1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 3), b.getDistByPedId(1, 3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 1), b.getDistByPedId(3, 1));
}
......@@ -94,25 +96,81 @@ public class PedestrianOverlapProcessorTestEnv extends ProcessorTestEnv<Timestep
Mockito.when(state.getTopography().getAttributesPedestrian().getRadius()).thenReturn(0.195);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 2), b.getDistByPedId(1,2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 3), b.getDistByPedId(1,3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 4), b.getDistByPedId(1,4));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 2), b.getDistByPedId(1, 2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 3), b.getDistByPedId(1, 3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 4), b.getDistByPedId(1, 4));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 1), b.getDistByPedId(2, 1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 3), b.getDistByPedId(2, 3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 4), b.getDistByPedId(2, 4));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 1), b.getDistByPedId(3, 1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 2), b.getDistByPedId(3, 2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 4), b.getDistByPedId(3, 4));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 1), b.getDistByPedId(4, 1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 2), b.getDistByPedId(4, 2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 3), b.getDistByPedId(4, 3));
}
});
}
public void verySmallOverlapping(){
AttributesAgent a = new AttributesAgent();
double distAtAxis = a.getRadius()*2 - 0.001; // this should count as overlap
double vertDistAt45deg = 2*Math.sqrt(0.5)*a.getRadius() - 0.001;
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
int step = 1;
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 1, 2), b.getDistByPedId(1, 2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 1), b.getDistByPedId(2, 1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 4), b.getDistByPedId(3, 4));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 3), b.getDistByPedId(4, 3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 5, 6), b.getDistByPedId(5, 6));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 6, 5), b.getDistByPedId(6, 5));
}
public void verySmallNotOverlapping() {
AttributesAgent a = new AttributesAgent();
double distAtAxis = a.getRadius()*2 + 0.001; // this should count as overlap
double vertDistAt45deg = 2*Math.sqrt(0.5)*a.getRadius() + 0.001;
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
}
public void touching() {
AttributesAgent a = new AttributesAgent();
double distAtAxis = a.getRadius()*2; // this should count as overlap
double vertDistAt45deg = 2*Math.sqrt(0.5)*a.getRadius();
addMockStates(a.getRadius(), distAtAxis, new VPoint(vertDistAt45deg, vertDistAt45deg));
}
public void addMockStates(double radius, double distAtAxis, VPoint vertDistAt45deg) {
clearStates();
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear();
b.add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.0, 1.0 + distAtAxis));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 1), b.getDistByPedId(2,1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 3), b.getDistByPedId(2,3));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 2, 4), b.getDistByPedId(2,4));
b.add(3, new VPoint(3.0, 3.0));
b.add(4, new VPoint(3.0 + distAtAxis, 3.0));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 1), b.getDistByPedId(3,1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 2), b.getDistByPedId(3,2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 3, 4), b.getDistByPedId(3,4));
b.add(5, new VPoint(6.0, 6.0));
b.add(6, new VPoint(6.0 , 6.0 ).add(vertDistAt45deg));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getTopography().getSpatialMap(DynamicElement.class)).thenReturn(getCellGridMock(b));
Mockito.when(state.getTopography().getAttributesPedestrian().getRadius()).thenReturn(radius);
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 1), b.getDistByPedId(4,1));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 2), b.getDistByPedId(4,2));
addToExpectedOutput(new TimestepPedestrianIdOverlap(step, 4, 3), b.getDistByPedId(4,3));
}
});
}
@Override
List<String> getExpectedOutputAsList() {
List<String> outputList = new ArrayList<>();
......
......@@ -129,11 +129,14 @@ public abstract class ProcessorTestEnv<K extends DataKey<K>, V> {
void removeState(int index) {
states.remove(index);
expectedOutput.remove(index);
requiredProcessors.forEach(env -> env.removeState(index));
requiredProcessors.forEach(env -> env.removeState(index));
}
void clearStates() {
states.clear();
expectedOutput.clear();
requiredProcessors.forEach(ProcessorTestEnv::clearStates);
}
......
......@@ -49,11 +49,19 @@ public class JoltTransformV4toV5Test extends JoltTransformationTest {
pathLastElementMustNotExist(v5, "scenario/attributesSimulation/needsBoundary");
}
/**
* Test with scenario containing a PedestrianOverlapProcessor processor. In this case
* The Attributes have to be deleted.
*/
@Test
public void PedestrianOverlapProcessorAttributeIsRemoved() {
testAttribute(test001(), 4, 1);
}
/**
* Test with scenario not containing a PedestrianOverlapProcessor processor. In this case
* Nothing should happen.
*/
@Test
public void NoPedestrianOverlapProcessor() {
testAttribute(test002(), 5, 0);
......
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