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 a4991ac2 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Add PedestrianFlowProcessorTest

parent ad66e039
......@@ -17,11 +17,16 @@ public class PedestrianDensityCountingProcessorTestEnv extends ProcessorTestEnv<
private PedestrianListBuilder b = new PedestrianListBuilder();
@SuppressWarnings("unchecked")
PedestrianDensityCountingProcessorTestEnv() {
this(1);
}
@SuppressWarnings("unchecked")
PedestrianDensityCountingProcessorTestEnv(int nextProcessorId) {
testedProcessor = processorFactory.createDataProcessor(PedestrianDensityCountingProcessor.class);
testedProcessor.setAttributes(new AttributesPedestrianDensityCountingProcessor());
testedProcessor.setId(nextProcessorId());
testedProcessor.setId(nextProcessorId);
this.nextProcessorId = nextProcessorId + 1;
int pedPosProcId = nextProcessorId();
AttributesPedestrianDensityCountingProcessor attr =
......@@ -51,10 +56,12 @@ public class PedestrianDensityCountingProcessorTestEnv extends ProcessorTestEnv<
@Override
public void mockIt() {
b.add(1, new VPoint(1.0, 1.0));
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.2, 1.2));
b.add(3, new VPoint(1.4, 1.4));
b.add(4, new VPoint(1.4 + Math.sqrt(radius) - 0.001, 1.4 + Math.sqrt(radius) - 0.001));
VPoint p = new VPoint(1.4, 1.4);
p = p.addPrecise(new VPoint(Math.sqrt(radius) - 0.001, Math.sqrt(radius) - 0.001));
b.add(4, p);
b.add(5, new VPoint(10.0, 10.0));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class PedestrianFlowProcessorTest extends ProcessorTest {
@Override
@Before
public void setup(){
processorTestEnv = new PedestrianFlowProcessorTestEnv();
super.setup();
}
@Override
@Test
public void doUpdate() throws Exception {
super.doUpdate();
}
@Override
@Test
public void init() throws Exception {
super.init();
}
}
\ No newline at end of file
package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesPedestrianDensityCountingProcessor;
import org.vadere.state.attributes.processor.AttributesPedestrianFlowProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
public class PedestrianFlowProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Double> {
private PedestrianListBuilder b = new PedestrianListBuilder();
private DataProcessor pedDensCountProc;
@SuppressWarnings("unchecked")
PedestrianFlowProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(PedestrianFlowProcessor.class);
testedProcessor.setId(nextProcessorId());
AttributesPedestrianFlowProcessor attr =
(AttributesPedestrianFlowProcessor) testedProcessor.getAttributes();
int pedDensCountProcId = nextProcessorId();
int pedVelProcId = nextProcessorId();
attr.setPedestrianDensityProcessorId(pedDensCountProcId);
attr.setPedestrianVelocityProcessorId(pedVelProcId);
PedestrianDensityCountingProcessorTestEnv pedDensCountProcEnv =
new PedestrianDensityCountingProcessorTestEnv(pedDensCountProcId);
pedDensCountProc = pedDensCountProcEnv.getTestedProcessor();
PedestrianVelocityProcessorTestEnv pedVelProcEnv =
new PedestrianVelocityProcessorTestEnv(pedVelProcId);
DataProcessor pedVelProc = pedVelProcEnv.getTestedProcessor();
Mockito.when(manager.getProcessor(pedDensCountProcId)).thenReturn(pedDensCountProc);
Mockito.when(manager.getProcessor(pedVelProcId)).thenReturn(pedVelProc);
addRequiredProcessors(pedVelProcEnv);
addRequiredProcessors(pedDensCountProcEnv);
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepPedestrianIdKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
@Override
public void loadDefaultSimulationStateMocks() {
AttributesPedestrianDensityCountingProcessor attr =
(AttributesPedestrianDensityCountingProcessor) pedDensCountProc.getAttributes();
double radius = attr.getRadius();
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.0, 1.0));
b.add(2, new VPoint(1.2, 1.2));
b.add(3, new VPoint(1.4, 1.4));
VPoint p = new VPoint(1.4, 1.4);
p = p.addPrecise(new VPoint(Math.sqrt(radius) - 0.001, Math.sqrt(radius) - 0.001));
b.add(4, p);
b.add(5, new VPoint(10.0, 10.0));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(0.0);
int step = state.getStep();
double circleArea = radius * radius * Math.PI;
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0.0 * 3.0 / circleArea);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 0.0 * 3.0 / circleArea);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0 * 4.0 / circleArea);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 4), 0.0 * 2.0 / circleArea);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 5), 0.0 * 1.0 / circleArea);
}
});
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
VPoint mov = new VPoint(3.0, 4.0); //dist = 5 time = 1 -> 5ms^-1
b.clear().add(1, new VPoint(1.0, 1.0).addPrecise(mov));
b.add(2, new VPoint(1.2, 1.2).addPrecise(mov));
b.add(3, new VPoint(1.4, 1.4).addPrecise(mov));
VPoint p = new VPoint(1.4, 1.4);
p = p.addPrecise(new VPoint(Math.sqrt(radius) - 0.001, Math.sqrt(radius) - 0.001));
b.add(4, p.addPrecise(mov));
b.add(5, new VPoint(10.0, 10.0).addPrecise(mov));
Mockito.when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
Mockito.when(state.getSimTimeInSec()).thenReturn(1.0);
int step = state.getStep();
double circleArea = radius * radius * Math.PI;
// parenthesis are needed to ensure the same precision created by the processor.
// Without parenthesis value for 5.0 * 3.0 / circleArea (radius 2.0) is off by
// 0.0000000000000001 and the test will do a String compare so it must match exactly
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 5.0 * (3.0 / circleArea));
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 5.0 * (3.0 / circleArea));
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 5.0 * (4.0 / circleArea));
addToExpectedOutput(new TimestepPedestrianIdKey(step, 4), 5.0 * (2.0 / circleArea));
addToExpectedOutput(new TimestepPedestrianIdKey(step, 5), 5.0 * (1.0 / circleArea));
}
});
}
@Override
List<String> getExpectedOutputAsList() {
List<String> outputList = new ArrayList<>();
expectedOutput.entrySet()
.stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.forEach(e -> {
StringJoiner sj = new StringJoiner(getDelimiter());
sj.add(Integer.toString(e.getKey().getTimestep()))
.add(Integer.toString(e.getKey().getPedestrianId()))
.add(Double.toString(e.getValue()));
outputList.add(sj.toString());
});
return outputList;
}
}
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