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

Add AreaSpeedProcessorTest, fix bug

parent 4aa98b41
......@@ -21,10 +21,10 @@ public class PedestrianPositionProcessor extends DataProcessor<TimestepPedestria
super("x", "y");
}
public Map<PedestrianIdKey, VPoint> getPositions(TimestepKey timestepKey) {
Map<PedestrianIdKey, VPoint> getPositions(TimestepKey timestepKey) {
return this.getData().entrySet().stream()
.filter(e -> e.getKey().equals(timestepKey))
.collect(Collectors.toMap(e -> new PedestrianIdKey(e.getKey().getPedestrianId()), e -> e.getValue()));
.filter(e -> e.getKey().getTimestep().equals(timestepKey.getTimestep()))
.collect(Collectors.toMap(e -> new PedestrianIdKey(e.getKey().getPedestrianId()), Map.Entry::getValue));
}
@Override
......
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Test;
import org.vadere.state.attributes.processor.AttributesAreaProcessor;
import org.vadere.util.geometry.shapes.VRectangle;
import static org.junit.Assert.assertEquals;
public class AreaSpeedProcessorTest extends ProcessorTest {
@Before
public void setup() {
processorTestEnv = new AreaSpeedProcessorTestEnv();
super.setup();
}
@Override
public void assertInit(DataProcessor p) throws NoSuchFieldException, IllegalAccessException {
assertEquals("Must be zero after init.", 0, p.getData().size());
assertEquals("Must be zero after init.", 0, (int) r.valOfField("lastStep"));
AttributesAreaProcessor attr = (AttributesAreaProcessor) p.getAttributes();
assertEquals(attr.getMeasurementArea(), r.valOfField("measurementArea"));
}
@Test
public void doUpdate() throws Exception {
AttributesAreaProcessor attr = (AttributesAreaProcessor) p.getAttributes();
attr.setMeasurementArea(new VRectangle(0, 0, 4, 5));
processorTestEnv.init();
super.doUpdate();
}
@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.TimestepKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesAreaSpeedProcessor;
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 AreaSpeedProcessorTestEnv extends ProcessorTestEnv<TimestepKey, Double> {
private PedestrianListBuilder b = new PedestrianListBuilder();
@SuppressWarnings("unchecked")
AreaSpeedProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(AreaSpeedProcessor.class);
testedProcessor.setId(nextProcessorId());
int pedPosProcId = nextProcessorId();
int pedVelProcId = nextProcessorId();
AttributesAreaSpeedProcessor attr =
(AttributesAreaSpeedProcessor) testedProcessor.getAttributes();
attr.setPedestrianPositionProcessorId(pedPosProcId);
attr.setPedestrianVelocityProcessorId(pedVelProcId);
PedestrianVelocityProcessorTestEnv pedVelProcEnv = new PedestrianVelocityProcessorTestEnv(pedVelProcId);
DataProcessor pedVelProc = pedVelProcEnv.getTestedProcessor();
addRequiredProcessors(pedVelProcEnv);
Mockito.when(manager.getProcessor(pedVelProcId)).thenReturn(pedVelProc);
PedestrianPositionProcessorTestEnv pedPosProcEnv = new PedestrianPositionProcessorTestEnv(pedPosProcId);
DataProcessor pedPosProc = pedPosProcEnv.getTestedProcessor();
addRequiredProcessors(pedPosProcEnv);
Mockito.when(manager.getProcessor(pedPosProcId)).thenReturn(pedPosProc);
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
TimestepKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
@Override
public void loadDefaultSimulationStateMocks() {
addSimState(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.0, 0.0))
.add(2, new VPoint(0.0, 0.0))
.add(3, new VPoint(7.0, 4.0)); //not in area
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(0.0);
int step = state.getStep();
addToExpectedOutput(new TimestepKey(step), 0.0);
}
});
addSimState(new SimulationStateMock(2) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(1.0, 1.0)) //dist = 1.0
.add(2, new VPoint(3.0, 4.0)) //dist = 5.0
.add(3, new VPoint(8.0, 4.0)); //not in area
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(2.0);
int step = state.getStep();
double time = 2.0 - 0.0;
double areaSpeed = (1.0 / time + 5.0 / time) / 2; // 2 = noOfPeds
addToExpectedOutput(new TimestepKey(step), areaSpeed);
}
});
addSimState(new SimulationStateMock(3) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(3.0, 1.0)) //dist = 2.0
.add(2, new VPoint(5.0, 4.0)) //not in area
.add(3, new VPoint(8.0, 8.0)); //not in area
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(3.0);
int step = state.getStep();
double time = 3.0 - 2.0; // time in this step
double areaSpeed = (2.0 / time) / 1; // 1 = noOfPeds
addToExpectedOutput(new TimestepKey(step), areaSpeed);
}
});
addSimState(new SimulationStateMock(4) {
@Override
public void mockIt() {
b.clear().add(1, new VPoint(6.0, 1.0)) // not in area
.add(2, new VPoint(7.0, 4.0)) // not in area
.add(3, new VPoint(9.0, 8.0)); // not in area
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(3.0);
int step = state.getStep();
addToExpectedOutput(new TimestepKey(step), Double.NaN);
}
});
}
@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(Double.toString(e.getValue()));
outputList.add(sj.toString());
});
return outputList;
}
}
......@@ -15,12 +15,21 @@ import java.util.StringJoiner;
import static org.mockito.Mockito.when;
public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Double>{
public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<TimestepPedestrianIdKey, Double> {
private PedestrianListBuilder b = new PedestrianListBuilder();
private SimulationStateMock state1;
private SimulationStateMock state2;
PedestrianVelocityProcessorTestEnv(){
PedestrianVelocityProcessorTestEnv() {
this(1);
}
@SuppressWarnings("unchecked")
PedestrianVelocityProcessorTestEnv(int nextProcessorId) {
testedProcessor = processorFactory.createDataProcessor(PedestrianVelocityProcessor.class);
testedProcessor.setId(nextProcessorId());
testedProcessor.setId(nextProcessorId);
this.nextProcessorId = nextProcessorId + 1;
DataProcessor pedPosProc;
PedestrianPositionProcessorTestEnv pedPosProcEnv;
......@@ -45,11 +54,7 @@ public class PedestrianVelocityProcessorTestEnv extends ProcessorTestEnv<Timest
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
PedestrianListBuilder b = new PedestrianListBuilder();
SimulationStateMock state1;
SimulationStateMock state2;
public void loadSimulationStateMocksWithBackstep2(){
void loadSimulationStateMocksWithBackstep2() {
clearStates();
addSimState(state1);
......
......@@ -4,13 +4,17 @@ import org.vadere.util.geometry.shapes.VRectangle;
/**
* @author Mario Teixeira Parente
*
*/
public class AttributesAreaProcessor extends AttributesProcessor {
private VRectangle measurementArea = new VRectangle(0, 0, 1, 1);
private VRectangle measurementArea = new VRectangle(0, 0, 1, 1);
public VRectangle getMeasurementArea() {
return this.measurementArea;
}
public VRectangle getMeasurementArea() {
return this.measurementArea;
}
public void setMeasurementArea(VRectangle measurementArea) {
checkSealed();
this.measurementArea = measurementArea;
}
}
......@@ -2,18 +2,27 @@ package org.vadere.state.attributes.processor;
/**
* @author Mario Teixeira Parente
*
*/
public class AttributesAreaSpeedProcessor extends AttributesAreaProcessor {
private int pedestrianPositionProcessorId;
private int pedestrianVelocityProcessorId;
private int pedestrianPositionProcessorId;
private int pedestrianVelocityProcessorId;
public int getPedestrianPositionProcessorId() {
return this.pedestrianPositionProcessorId;
}
public int getPedestrianPositionProcessorId() {
return this.pedestrianPositionProcessorId;
}
public int getPedestrianVelocityProcessorId() {
return this.pedestrianVelocityProcessorId;
}
public void setPedestrianPositionProcessorId(int id) {
checkSealed();
this.pedestrianPositionProcessorId = id;
}
public int getPedestrianVelocityProcessorId() {
return this.pedestrianVelocityProcessorId;
}
public void setPedestrianVelocityProcessorId(int id) {
checkSealed();
this.pedestrianVelocityProcessorId = id;
}
}
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