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

Add PedestrianVelocityProcessorTest

parent b00b57f8
......@@ -52,6 +52,8 @@ public class PedestrianVelocityProcessor extends DataProcessor<TimestepPedestria
this.pedPosProc =
(PedestrianPositionProcessor) manager.getProcessor(attVelProc.getPedestrianPositionProcessorId());
this.backSteps = attVelProc.getBackSteps();
this.lastSimTimes = new LinkedList<>();
this.lastSimTimes.add(0.0);
}
private Double getVelocity(int timeStep, double currentSimTime, int pedId) {
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Test;
import org.vadere.state.attributes.processor.AttributesPedestrianVelocityProcessor;
import java.util.LinkedList;
import static org.junit.Assert.*;
public class PedestrianVelocityProcessorTest extends ProcessorTest {
@Before
public void setup(){
processorTestEnv = new PedestrianVelocityProcessorTestEnv();
super.setup();
}
@Override
public void assertInit(DataProcessor p) throws NoSuchFieldException, IllegalAccessException {
AttributesPedestrianVelocityProcessor attr = (AttributesPedestrianVelocityProcessor) p.getAttributes();
assertEquals("Must be zero after init.", 0, p.getData().size());
assertEquals("Must be zero after init.", 0, (int) r.valOfField("lastStep"));
assertEquals(attr.getBackSteps(), (int)r.valOfField("backSteps"));
assertEquals(1, ((LinkedList<Double>)r.valOfField("lastSimTimes")).size());
assertEquals(0.0, ((LinkedList<Double>)r.valOfField("lastSimTimes")).getFirst(), 0.000001);
}
@Test
public void doUpdate() throws Exception {
// default backstep = 1
super.doUpdate();
}
@Test public void withBackstepTow() throws Exception {
AttributesPedestrianVelocityProcessor attr =
(AttributesPedestrianVelocityProcessor) p.getAttributes();
attr.setBackSteps(2);
((PedestrianVelocityProcessorTestEnv) processorTestEnv).loadSimulationStateMocksWithBackstep2();
p.init(processorTestEnv.getManager());
super.doUpdate();
}
@Test
public void init() throws Exception {
super.init();
}
@Test
public void getAttributes() throws Exception {
}
}
\ No newline at end of file
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesPedestrianVelocityProcessor;
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;
import static org.mockito.Mockito.when;
public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Double>{
private DataProcessor pedPosProc;
private PedestrianPositionProcessorTestEnv pedPosProcEnv;
PedestrianVelocityProcessorTestEnv(){
testedProcessor = processorFactory.createDataProcessor(PedestrianVelocityProcessor.class);
testedProcessor.setId(nextProcessorId());
AttributesPedestrianVelocityProcessor attr =
(AttributesPedestrianVelocityProcessor) testedProcessor.getAttributes();
attr.setPedestrianPositionProcessorId(99);
pedPosProcEnv = new PedestrianPositionProcessorTestEnv(99);
pedPosProcEnv.init();
pedPosProc = pedPosProcEnv.getTestedProcessor();
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepPedestrianIdKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
when(manager.getProcessor(99)).thenReturn(pedPosProc);
}
PedestrianListBuilder b = new PedestrianListBuilder();
SimulationStateMock state1;
SimulationStateMock state2;
public void loadSimulationStateMocksWithBackstep2(){
states.clear();
pedPosProcEnv.getSimStates().clear();
states.add(state1);
states.add(state2);
states.add(new SimulationStateMock(3) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.5, 1.0))
.add(2, new VPoint(5.3, 6.3))
.add(3, new VPoint(5.7, 3.3));
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(2.0);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0.5);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 5.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
});
}
@Override
public void loadDefaultSimulationStateMocks() {
state1 = new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.0, 1.0))
.add(2, new VPoint(2.3, 2.3))
.add(3, new VPoint(5.7, 3.3));
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(0.0);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
};
states.add(state1);
state2 = new SimulationStateMock(2) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.5, 1.0))
.add(2, new VPoint(5.3, 6.3))
.add(3, new VPoint(5.7, 3.3));
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(1.0);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0.5);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 5.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
};
states.add(state2);
states.add(new SimulationStateMock(3) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.5, 1.0))
.add(2, new VPoint(5.3, 6.3))
.add(3, new VPoint(5.7, 3.3));
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(2.0);
int step = state.getStep();
addToExpectedOutput(new TimestepPedestrianIdKey(step, 1), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 2), 0.0);
addToExpectedOutput(new TimestepPedestrianIdKey(step, 3), 0.0);
pedPosProcEnv.addSimState(this);
}
});
}
@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