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

Add PedestrianEvacuationTimeProcessorTest

parent 2bafc108
package org.vadere.simulator.projects.dataprocessing.processor;
import org.junit.Before;
import org.junit.Test;
public class PedestrianEvacuationTimeProcessorTest extends ProcessorTest {
@Before
public void setup() {
processorTestEnv = new PedestrianEvacuationTimeProcessorTestEnv();
super.setup();
}
@Test
public void init() throws Exception {
super.init();
}
@Test
public void doUpdate() throws Exception {
super.doUpdate();
}
}
\ No newline at end of file
package org.vadere.simulator.projects.dataprocessing.processor;
import org.mockito.Mockito;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.writer.VadereWriterFactory;
import org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor;
import org.vadere.state.scenario.Pedestrian;
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 PedestrianEvacuationTimeProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
DataProcessor pedStartTimeProc;
PedestrianStartTimeProcessorTestEnv pedStartTimeProcEnv;
PedestrianListBuilder b = new PedestrianListBuilder();
PedestrianEvacuationTimeProcessorTestEnv() {
testedProcessor = processorFactory.createDataProcessor(PedestrianEvacuationTimeProcessor.class);
testedProcessor.setId(nextProcessorId());
AttributesPedestrianEvacuationTimeProcessor attr =
(AttributesPedestrianEvacuationTimeProcessor) testedProcessor.getAttributes();
attr.setPedestrianStartTimeProcessorId(99);
pedStartTimeProcEnv = new PedestrianStartTimeProcessorTestEnv(99);
pedStartTimeProc = pedStartTimeProcEnv.getTestedProcessor();
Mockito.when(manager.getProcessor(99)).thenReturn(pedStartTimeProc);
outputFile = outputFileFactory.createDefaultOutputfileByDataKey(
PedestrianIdKey.class,
testedProcessor.getId()
);
outputFile.setVadereWriterFactory(VadereWriterFactory.getStringWriterFactory());
}
@Override
public void loadDefaultSimulationStateMocks() {
states.add(new SimulationStateMock(1) {
@Override
public void mockIt() {
b.clear().add(new Integer[]{1, 3, 4});
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(0.4);
addToExpectedOutput(new PedestrianIdKey(1), 0.0);
addToExpectedOutput(new PedestrianIdKey(3), 0.0);
addToExpectedOutput(new PedestrianIdKey(4), 0.0);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(2) {
@Override
public void mockIt() {
b.clear().add(new Integer[]{1, 3, 4, 5, 8});
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(12.8);
addToExpectedOutput(new PedestrianIdKey(1), 12.8 - 0.4);
addToExpectedOutput(new PedestrianIdKey(3), 12.8 - 0.4);
addToExpectedOutput(new PedestrianIdKey(4), 12.8 - 0.4);
addToExpectedOutput(new PedestrianIdKey(5), 0.0);
addToExpectedOutput(new PedestrianIdKey(8), 0.0);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(3) {
@Override
public void mockIt() {
b.clear().add(new Integer[]{1, 5, 8});
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(34.7);
addToExpectedOutput(new PedestrianIdKey(1), 34.7 - 0.0);
addToExpectedOutput(new PedestrianIdKey(5), 34.7 - 12.8);
addToExpectedOutput(new PedestrianIdKey(8), 34.7 - 12.8);
pedStartTimeProcEnv.addSimState(this);
}
});
states.add(new SimulationStateMock(4) {
@Override
public void mockIt() {
b.clear().add(new Integer[]{1});
when(state.getTopography().getElements(Pedestrian.class)).thenReturn(b.getList());
when(state.getSimTimeInSec()).thenReturn(40.0);
addToExpectedOutput(new PedestrianIdKey(1), Double.NaN);
pedStartTimeProcEnv.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().getPedestrianId()))
.add(Double.toString(e.getValue()));
outputList.add(sj.toString());
});
return outputList;
}
}
......@@ -17,22 +17,33 @@ public class PedestrianListBuilder {
this.out = new LinkedList<>();
}
public PedestrianListBuilder add(int id){
public PedestrianListBuilder add(int id) {
out.add(new Pedestrian(new AttributesAgent(id), new Random()));
return this;
}
public PedestrianListBuilder add(int id, VPoint pos){
public PedestrianListBuilder add(int id, VPoint pos) {
Pedestrian p = new Pedestrian(new AttributesAgent(id), new Random());
p.setPosition(pos);
out.add(p);
return this;
}
public PedestrianListBuilder clear(){
public PedestrianListBuilder add(Integer... ids) {
for (Integer id : ids) {
Pedestrian p = new Pedestrian(new AttributesAgent(id), new Random());
out.add(p);
}
return this;
}
public PedestrianListBuilder clear() {
out = new LinkedList<>();
return this;
}
public List<Pedestrian> getList(){ return out;}
public List<Pedestrian> getList() {
return out;
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.projects.dataprocessing.writer.VadereStringWriter;
import org.vadere.simulator.projects.dataprocessing.datakey.PedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.outputfile.OutputFile;
import org.vadere.simulator.projects.dataprocessing.outputfile.PedestrianIdOutputFile;
......@@ -26,10 +25,15 @@ import static org.mockito.Mockito.when;
public class PedestrianStartTimeProcessorTestEnv extends ProcessorTestEnv<PedestrianIdKey, Double> {
PedestrianStartTimeProcessorTestEnv() {
this(1);
}
PedestrianStartTimeProcessorTestEnv(int nextProcessorId) {
super();
testedProcessor = processorFactory.createDataProcessor(PedestrianStartTimeProcessor.class);
testedProcessor.setId(nextProcessorId++);
testedProcessor.setId(nextProcessorId);
this.nextProcessorId = nextProcessorId++;
outputFile = outputFileFactory.createOutputfile(
PedestrianIdOutputFile.class,
......
......@@ -2,13 +2,17 @@ package org.vadere.state.attributes.processor;
/**
* @author Mario Teixeira Parente
*
*/
public class AttributesPedestrianEvacuationTimeProcessor extends AttributesProcessor {
private int pedestrianStartTimeProcessorId;
private int pedestrianStartTimeProcessorId;
public int getPedestrianStartTimeProcessorId() {
return this.pedestrianStartTimeProcessorId;
}
public int getPedestrianStartTimeProcessorId() {
return this.pedestrianStartTimeProcessorId;
}
public void setPedestrianStartTimeProcessorId(int id) {
checkSealed();
this.pedestrianStartTimeProcessorId = 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