Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

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