The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit ab0e0d72 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

AreaDensityVoroniProcessorTest

Added Test for Processor. ToDo The Voroni Algorithm does not work
for the corner case if all Pedestrian (more than 2) ar collinear. This
is not really a problem because this case is rare.
parent ecd5102f
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
public class AreaDensityVoronoiProcessorTest extends ProcessorTest {
@Before
public void setup(){
public void setup() {
processorTestEnv = new AreaDensityVoronoiProcessorTestEnv();
super.setup();
}
@Test
public void doUpdate() throws Exception {
AreaDensityVoronoiProcessorTestEnv env = (AreaDensityVoronoiProcessorTestEnv) processorTestEnv;
env.loadOneCircleEvent();
super.doUpdate();
}
/**
* This will fail. The implementation fails to create the write segmentation if all
* Pedestrian are collinear.
*/
@Test
@Ignore
public void withCollinear() throws Exception {
AreaDensityVoronoiProcessorTestEnv env = (AreaDensityVoronoiProcessorTestEnv) processorTestEnv;
env.loadCollinearSetup();
super.doUpdate();
}
@Test
@Ignore
public void init() throws Exception {
super.init();
}
......
......@@ -4,7 +4,6 @@ import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesAreaDensityVoronoiProcessor;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -14,20 +13,19 @@ import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import static org.mockito.ArgumentMatchers.doubleThat;
import static org.mockito.Mockito.when;
public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv <TimestepKey, Double>{
public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv<TimestepKey, Double> {
PedestrianListBuilder b = new PedestrianListBuilder();
AreaDensityVoronoiProcessorTestEnv(){
AreaDensityVoronoiProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(AreaDensityVoronoiProcessor.class);
testedProcessor.setId(nextProcessorId());
AttributesAreaDensityVoronoiProcessor attr =
(AttributesAreaDensityVoronoiProcessor)testedProcessor.getAttributes();
attr.setVoronoiArea(new VRectangle(0, 0, 16,16));
attr.setMeasurementArea(new VRectangle(0, 0, 16,16));
(AttributesAreaDensityVoronoiProcessor) testedProcessor.getAttributes();
attr.setVoronoiArea(new VRectangle(0, 0, 16, 16));
attr.setMeasurementArea(new VRectangle(0, 0, 16, 16));
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepKey.class,
......@@ -36,54 +34,47 @@ public class AreaDensityVoronoiProcessorTestEnv extends ProcessorTestEnv <Timest
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
@Override
public void loadDefaultSimulationStateMocks() {
// addSimState(new SimulationStateMock(1) {
// @Override
// public void mockIt() {
// b.clear().add(1, new VPoint(1,1));
// b.add(2, new VPoint(3,1));
// b.add(3, new VPoint(3,3));
// b.add(4, new VPoint(1,3));
// when(state.getTopography().getElements(Agent.class)).thenReturn(b.getAgentList());
//
// int step = state.getStep();
// addToExpectedOutput(new TimestepKey(step), 0.25);
// }
// });
SimulationStateMock fourCoLinear = new SimulationStateMock(1) {
public void loadCollinearSetup() {
clearStates();
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.0,1.0));
b.add(2, new VPoint(2.0,2.0));
b.add(3, new VPoint(3.0,3.0));
b.add(4, new VPoint(4.0,4.0));
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(2.0, 2.0));
b.add(3, new VPoint(3.0, 3.0));
b.add(4, new VPoint(4.0, 4.0));
when(state.getTopography().getElements(Agent.class)).thenReturn(b.getAgentList());
int step = state.getStep();
addToExpectedOutput(new TimestepKey(step), 8.0/16.0);
addToExpectedOutput(new TimestepKey(step), 4.0 / (16.0 * 16.0));
}
};
});
}
SimulationStateMock oneCircleEvent = new SimulationStateMock(1) {
public void loadOneCircleEvent() {
clearStates();
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(3.0,6.5));
b.add(2, new VPoint(6.0,8.0));
b.clear().add(1, new VPoint(3.0, 6.5));
b.add(2, new VPoint(6.0, 8.0));
VPoint m = new VPoint(6.0, 4.0); //circle mid
b.add(3, m.add(new VPoint(2.5,3.0)));
b.add(3, m.add(new VPoint(2.5, 3.0)));
when(state.getTopography().getElements(Agent.class)).thenReturn(b.getAgentList());
int step = state.getStep();
addToExpectedOutput(new TimestepKey(step), 8.0/16.0);
addToExpectedOutput(new TimestepKey(step), 3.0 / (16.0 * 16.0));
}
};
});
}
addSimState(oneCircleEvent);
@Override
public void loadDefaultSimulationStateMocks() {
clearStates();
}
@Override
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
......@@ -46,4 +47,7 @@ public class PedestrianListBuilder {
return out;
}
public List<Agent> getAgentList() {
return new LinkedList<>(out);
}
}
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