Commit 2fb363ec authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Implemented "SimpleCognitionModelTest"

parent c962231f
Pipeline #204409 passed with stages
in 119 minutes and 18 seconds
package org.vadere.simulator.control.psychology.cognition;
import org.junit.Test;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.*;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.shapes.VPoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.assertEquals;
public class SimpleCognitionModelTest {
private Topography createTopography() {
return new Topography();
}
private List<Pedestrian> createPedestrians(int totalPedestrians) {
List<Pedestrian> pedestrians = new ArrayList<>();
long seed = 0;
Random random = new Random(seed);
for (int i = 0; i < totalPedestrians; i++) {
AttributesAgent attributesAgent = new AttributesAgent(i);
Pedestrian pedestrian = new Pedestrian(attributesAgent, random);
pedestrian.setPosition(new VPoint(i, i));
pedestrians.add(pedestrian);
}
return pedestrians;
}
private void testCognitionLayer(SelfCategory defaultSelfCategory, SelfCategory expectedSelfCategory, Stimulus presentStimulus) {
List<Pedestrian> pedestrians = createPedestrians(2);
for (Pedestrian pedestrian : pedestrians) {
pedestrian.setMostImportantStimulus(presentStimulus);
pedestrian.setSelfCategory(defaultSelfCategory);
}
SimpleCognitionModel simpleCognitionModel = new SimpleCognitionModel();
simpleCognitionModel.initialize(createTopography());
simpleCognitionModel.update(pedestrians);
for (Pedestrian pedestrian : pedestrians) {
assertEquals(expectedSelfCategory, pedestrian.getSelfCategory());
}
}
@Test
public void updatesSetsChangeTargetOnChangeTargetStimulus() {
testCognitionLayer(SelfCategory.TARGET_ORIENTED,
SelfCategory.CHANGE_TARGET,
new ChangeTarget());
}
@Test
public void updatesSetsInsideThreatOnThreatStimulus() {
testCognitionLayer(SelfCategory.TARGET_ORIENTED,
SelfCategory.INSIDE_THREAT_AREA,
new Threat());
}
@Test
public void updatesSetsWaitOnWaitStimulus() {
testCognitionLayer(SelfCategory.TARGET_ORIENTED,
SelfCategory.WAIT,
new Wait());
}
@Test
public void updatesSetsWaitOnWaitInAreaStimulus() {
testCognitionLayer(SelfCategory.TARGET_ORIENTED,
SelfCategory.WAIT,
new WaitInArea());
}
@Test
public void updatesSetsTargetOrientedOnElapsedTime() {
testCognitionLayer(SelfCategory.WAIT,
SelfCategory.TARGET_ORIENTED,
new ElapsedTime());
}
}
\ No newline at end of file
......@@ -144,7 +144,7 @@ public class SimplePerceptionModelTest {
@Test
public void updateUsesClosestThreatForPedestrian() {
// Place threat at (0,0) and (5,0) with radii 5 and
// Place threats at (0,0) and (5,0) with radius 5 and
// place pedestrians at (1,0) and (4,0) and check result.
Topography topography = createTopography();
......
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