Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit f1143bc7 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Started with unit test "LastFootStepsTest".

VadereState/src/org/vadere/state/scenario/Pedestrian.java:
- Fixed bug in copy constructor: member "salientBehavior" was not copied.
parent ab7db35b
Pipeline #102885 passed with stages
in 118 minutes and 46 seconds
......@@ -26,7 +26,7 @@ public class SalientBehaviorCognition {
this.topography = topography;
}
public void setSalientBehaviorForPedestrians(Collection<Pedestrian> pedestrians) {
public void setSalientBehaviorForPedestrians(Collection<Pedestrian> pedestrians, double simTimeInSec) {
for (Pedestrian pedestrian : pedestrians) {
// TODO: Set salient behavior for each pedestrian individually based on the most important event and/or if
// the pedestrian could not move for several time steps.
......
......@@ -69,6 +69,7 @@ public class Pedestrian extends Agent {
isChild = other.isChild;
isLikelyInjured = other.isLikelyInjured;
mostImportantEvent = other.mostImportantEvent;
salientBehavior = other.salientBehavior;
if (other.groupIds != null) {
groupIds = new LinkedList<>(other.groupIds);
......
package org.vadere.state.simulation;
import java.util.ArrayList;
/**
* Store the last foot steps of an agent to calculate the agent's average speed during simulation.
*/
public class LastFootSteps {
// Variables
private int capacity;
private ArrayList<FootStep> footSteps;
// Constructors
public LastFootSteps(int capacity) {
this.capacity = capacity;
this.footSteps = new ArrayList<>(capacity);
}
// Getters
public int getCapacity() { return capacity; }
public ArrayList<FootStep> getFootSteps() { return footSteps; }
// Methods
public boolean add(FootStep footStep) {
if (footSteps.size() >= capacity) {
footSteps.remove(0);
}
boolean successful = footSteps.add(footStep);
return successful;
}
public double getAverageSpeedInMeterPerSecond() {
double speed = Double.NaN;
if (footSteps.size() > 0) {
// Speed is length divided by time.
double distance = footSteps.stream().mapToDouble(footStep -> footStep.length()).sum();
// This approach works also if "footSteps.size() == 1"
double time = getYoungestFootStep().getEndTime() - getOldestFootStep().getStartTime();
speed = distance / time;
}
return speed;
}
public FootStep getOldestFootStep() {
FootStep oldestFootStep = null;
if (footSteps.size() > 0) {
oldestFootStep = footSteps.get(0);
}
return oldestFootStep;
}
public FootStep getYoungestFootStep() {
FootStep youngestFootStep = null;
if (footSteps.size() > 0) {
youngestFootStep = footSteps.get(footSteps.size() - 1);
}
return youngestFootStep;
}
}
package org.vadere.state.simulation;
import org.junit.Before;
import org.junit.Test;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.ArrayList;
import static org.junit.Assert.*;
public class LastFootStepsTest {
private static Double ALLOWED_DOUBLE_ERROR_FOR_TIME = 10e-3;
private int expectedFootStepCapacity;
private LastFootSteps lastFootSteps;
@Before
public void setUp() {
expectedFootStepCapacity = 10;
lastFootSteps = new LastFootSteps(expectedFootStepCapacity);
}
@Test
public void getCapacityReturnsCapacityPassedToContructor() {
int expectedCapacity = 10;
LastFootSteps lastFootSteps = new LastFootSteps(expectedCapacity);
int actualCapacity = lastFootSteps.getCapacity();
assertEquals(expectedCapacity, actualCapacity);
}
@Test
public void getFootStepsReturnsAnEmptyFootStepListByDefault() {
int expectedListSize = 0;
assertEquals(expectedListSize, lastFootSteps.getFootSteps().size());
}
@Test
public void getFootStepsReturnsListOfSizeOneIfOneElementWasAdded() {
FootStep footStep = new FootStep();
lastFootSteps.getFootSteps().add(footStep);
int expectedListSize = 1;
assertEquals(expectedListSize, lastFootSteps.getFootSteps().size());
}
@Test
public void addInsertsAnElementAndSizeIsIncrementedProperly() {
FootStep footStep = new FootStep();
lastFootSteps.add(footStep);
int expectedListSize = 1;
assertEquals(expectedListSize, lastFootSteps.getFootSteps().size());
}
@Test
public void addInsertsThePassedFootStep() {
FootStep expectedFootStep = new FootStep(VPoint.ZERO, VPoint.ZERO, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
lastFootSteps.add(expectedFootStep);
FootStep actualFootStep = lastFootSteps.getFootSteps().get(0);
assertEquals(expectedFootStep.getEnd(), actualFootStep.getEnd());
assertEquals(expectedFootStep.getStart(), actualFootStep.getStart());
assertEquals(expectedFootStep.getEndTime(), actualFootStep.getEndTime(), ALLOWED_DOUBLE_ERROR_FOR_TIME);
assertEquals(expectedFootStep.getStartTime(), actualFootStep.getStartTime(), ALLOWED_DOUBLE_ERROR_FOR_TIME);
}
@Test
public void addAppendsElements() {
int totalFootSteps = 2;
FootStep[] expectedFootSteps = new FootStep[totalFootSteps];
for (int i = 0; i < totalFootSteps; i++) {
double startPositionX = i;
double startTime = i;
FootStep currentFootStep = new FootStep(new VPoint(startPositionX, 0), new VPoint(startPositionX + 1, 0),
startTime, startTime + 1);
expectedFootSteps[i] = currentFootStep;
lastFootSteps.add(currentFootStep);
}
ArrayList<FootStep> actualFootSteps = lastFootSteps.getFootSteps();
for (int i = 0; i < actualFootSteps.size(); i++) {
assertEquals(expectedFootSteps[i].getStartTime(), lastFootSteps.getFootSteps().get(i).getStartTime(),
ALLOWED_DOUBLE_ERROR_FOR_TIME);
}
}
@Test
public void addRemovesOldestElementIfCapacityIsExceeded() {
int totalFootSteps = expectedFootStepCapacity * 4;
for (int i = 0; i < totalFootSteps; i++) {
double startPositionX = i;
double startTime = i;
FootStep currentFootStep = new FootStep(new VPoint(startPositionX, 0), new VPoint(startPositionX + 1, 0),
startTime, startTime + 1);
lastFootSteps.add(currentFootStep);
if (i < expectedFootStepCapacity) {
assertEquals(currentFootStep.getStartTime(), lastFootSteps.getFootSteps().get(i).getStartTime(), ALLOWED_DOUBLE_ERROR_FOR_TIME);
} else {
double expectedStartTimeHead = (startTime - expectedFootStepCapacity) + 1;
double actualStartTimeHead = lastFootSteps.getFootSteps().get(0).getStartTime();
assertEquals(expectedStartTimeHead, actualStartTimeHead, ALLOWED_DOUBLE_ERROR_FOR_TIME);
double expectedStartTimeTail = startTime;
double actualStartTimeTail = lastFootSteps.getFootSteps().get(expectedFootStepCapacity - 1).getStartTime();
assertEquals(expectedStartTimeTail, actualStartTimeTail, ALLOWED_DOUBLE_ERROR_FOR_TIME);
}
}
}
@Test
public void getAverageSpeedInMeterPerSecond() {
// TODO: Implement test.
}
@Test
public void getOldestFootStep() {
// TODO: Implement test.
}
@Test
public void getYoungestFootStep() {
// TODO: Implement test.
}
}
\ No newline at end of file
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