Commit 8e03ddc1 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

add Test with multiple sources.

parent 91748aa4
...@@ -15,7 +15,6 @@ import org.vadere.state.attributes.scenario.AttributesAgent; ...@@ -15,7 +15,6 @@ import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesSource; import org.vadere.state.attributes.scenario.AttributesSource;
import org.vadere.state.attributes.scenario.SourceTestAttributesBuilder; import org.vadere.state.attributes.scenario.SourceTestAttributesBuilder;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.util.StateJsonConverter;
import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle; import org.vadere.util.geometry.shapes.VRectangle;
...@@ -27,7 +26,6 @@ import static org.junit.Assert.assertEquals; ...@@ -27,7 +26,6 @@ import static org.junit.Assert.assertEquals;
public class GroupSourceControllerTest extends TestSourceControllerUsingConstantSpawnRate { public class GroupSourceControllerTest extends TestSourceControllerUsingConstantSpawnRate {
private Integer[] groupSpawn;
private GroupModel m; private GroupModel m;
public SourceControllerFactory getSourceControllerFactory(SourceTestData d) { public SourceControllerFactory getSourceControllerFactory(SourceTestData d) {
...@@ -43,10 +41,15 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -43,10 +41,15 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
public void initialize(SourceTestAttributesBuilder builder) { public void initialize(SourceTestAttributesBuilder builder) {
super.initialize(builder); super.initialize(builder);
SourceTestData d = sourceTestData.get(sourceTestData.size() - 1); SourceTestData d = sourceTestData.get(sourceTestData.size() - 1);
if (groupSpawn.length > 0) {
GroupSizeDeterminatorRandom gsdRnd = Mockito.mock(GroupSizeDeterminatorRandom.class, Mockito.RETURNS_DEEP_STUBS); if (builder.getGroupSizeDistributionMock().length > 0) {
Integer[] groupSizeDistributionMock = builder.getGroupSizeDistributionMock();
GroupSizeDeterminatorRandom gsdRnd =
Mockito.mock(GroupSizeDeterminatorRandom.class, Mockito.RETURNS_DEEP_STUBS);
Mockito.when(gsdRnd.nextGroupSize()) Mockito.when(gsdRnd.nextGroupSize())
.thenReturn(groupSpawn[0], Arrays.copyOfRange(groupSpawn, 1, groupSpawn.length)); .thenReturn(groupSizeDistributionMock[0],
Arrays.copyOfRange(groupSizeDistributionMock,
1, groupSizeDistributionMock.length));
CentroidGroupFactory cgf = (CentroidGroupFactory) m.getGroupFactory(d.source.getId()); CentroidGroupFactory cgf = (CentroidGroupFactory) m.getGroupFactory(d.source.getId());
cgf.setGroupSizeDeterminator(gsdRnd); cgf.setGroupSizeDeterminator(gsdRnd);
} }
...@@ -58,8 +61,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -58,8 +61,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setOneTimeSpawn(0) .setOneTimeSpawn(0)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.5, 0.5); .setGroupSizeDistribution(0.0, 0.5, 0.5)
groupSpawn = new Integer[]{2, 2, 3, 3}; .setGroupSizeDistributionMock(2, 2, 3, 3);
initialize(builder); initialize(builder);
...@@ -81,8 +84,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -81,8 +84,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setStartTime(startTime).setEndTime(endTime) .setStartTime(startTime).setEndTime(endTime)
.setSpawnIntervalForConstantDistribution(10) .setSpawnIntervalForConstantDistribution(10)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.5, 0.5); .setGroupSizeDistribution(0.0, 0.5, 0.5)
groupSpawn = new Integer[]{2, 3, 2, 3}; .setGroupSizeDistributionMock(2, 3, 2, 3);
initialize(builder); initialize(builder);
first().sourceController.update(startTime); first().sourceController.update(startTime);
...@@ -103,8 +106,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -103,8 +106,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setStartTime(0).setEndTime(endTime) .setStartTime(0).setEndTime(endTime)
.setSpawnIntervalForConstantDistribution(5) .setSpawnIntervalForConstantDistribution(5)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.5, 0.5); .setGroupSizeDistribution(0.0, 0.5, 0.5)
groupSpawn = new Integer[]{2, 3, 2, 3}; .setGroupSizeDistributionMock(2, 3, 2, 3);
initialize(builder); initialize(builder);
for (double simTimeInSec = 0; simTimeInSec < endTime * 2; simTimeInSec += 1.0) { for (double simTimeInSec = 0; simTimeInSec < endTime * 2; simTimeInSec += 1.0) {
...@@ -123,8 +126,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -123,8 +126,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setStartTime(0).setEndTime(endTime) .setStartTime(0).setEndTime(endTime)
.setSpawnIntervalForConstantDistribution(0.1) .setSpawnIntervalForConstantDistribution(0.1)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.5, 0.5); .setGroupSizeDistribution(0.0, 0.5, 0.5)
groupSpawn = new Integer[]{2, 3, 2, 3, 2, 2, 3, 3, 3, 2, 2, 3, 3, 3, 3}; .setGroupSizeDistributionMock(2, 3, 2, 3, 2, 2, 3, 3, 3, 2, 2, 3, 3, 3, 3);
initialize(builder); initialize(builder);
for (double simTimeInSec = 0; simTimeInSec < endTime * 2; simTimeInSec += 1.0) { for (double simTimeInSec = 0; simTimeInSec < endTime * 2; simTimeInSec += 1.0) {
...@@ -148,7 +151,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -148,7 +151,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setUseFreeSpaceOnly(true) .setUseFreeSpaceOnly(true)
.setSourceDim(2 * d + 0.1, 4 * d + 0.1) .setSourceDim(2 * d + 0.1, 4 * d + 0.1)
.setGroupSizeDistribution(0.0, 0.0, 1); .setGroupSizeDistribution(0.0, 0.0, 1);
groupSpawn = new Integer[]{};
initialize(builder); initialize(builder);
for (double simTimeInSec = 0; simTimeInSec < 1000; simTimeInSec += 1.0) { for (double simTimeInSec = 0; simTimeInSec < 1000; simTimeInSec += 1.0) {
...@@ -180,8 +182,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -180,8 +182,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class) .setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 1); .setGroupSizeDistribution(0.0, 0.0, 1)
groupSpawn = new Integer[]{3, 3, 3, 3}; .setGroupSizeDistributionMock(3, 3, 3, 3);
initialize(builder); initialize(builder);
first().sourceController.update(0); first().sourceController.update(0);
...@@ -199,8 +201,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -199,8 +201,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class) .setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class)
.setEndTime(2) .setEndTime(2)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 1); // only groups of 3 .setGroupSizeDistribution(0.0, 0.0, 1) // only groups of 3
groupSpawn = new Integer[]{3, 3, 3, 3}; .setGroupSizeDistributionMock(3, 3, 3, 3);
initialize(builder); initialize(builder);
first().sourceController.update(1); first().sourceController.update(1);
...@@ -217,8 +219,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -217,8 +219,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setOneTimeSpawn(1) .setOneTimeSpawn(1)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 1); // only groups of 3 .setGroupSizeDistribution(0.0, 0.0, 1) // only groups of 3
groupSpawn = new Integer[]{3, 3, 3, 3}; .setGroupSizeDistributionMock(3, 3, 3, 3);
initialize(builder); initialize(builder);
first().sourceController.update(0); first().sourceController.update(0);
...@@ -235,7 +237,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -235,7 +237,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setSpawnNumber(10) .setSpawnNumber(10)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.0, 1); // only groups of 4 .setGroupSizeDistribution(0.0, 0.0, 0.0, 1); // only groups of 4
groupSpawn = new Integer[]{}; // do not mock group Dist.
initialize(builder); initialize(builder);
first().sourceController.update(1); first().sourceController.update(1);
...@@ -250,8 +251,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -250,8 +251,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setStartTime(0).setEndTime(1) .setStartTime(0).setEndTime(1)
.setSpawnIntervalForConstantDistribution(0.3) .setSpawnIntervalForConstantDistribution(0.3)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; // do not mock group Dist. .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
// per update only one "spawn action" is performed. // per update only one "spawn action" is performed.
...@@ -275,7 +276,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -275,7 +276,6 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setUseFreeSpaceOnly(true) .setUseFreeSpaceOnly(true)
.setSourceDim(2 * d + 0.1, 4 * d + 0.1) .setSourceDim(2 * d + 0.1, 4 * d + 0.1)
.setGroupSizeDistribution(0.0, 0.0, 0.0, 1); .setGroupSizeDistribution(0.0, 0.0, 0.0, 1);
groupSpawn = new Integer[]{};
initialize(builder); initialize(builder);
...@@ -295,8 +295,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -295,8 +295,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setMaxSpawnNumberTotal(0) // <-- max 0 -> spawn no peds at all .setMaxSpawnNumberTotal(0) // <-- max 0 -> spawn no peds at all
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
first().sourceController.update(1); first().sourceController.update(1);
...@@ -312,8 +312,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -312,8 +312,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setMaxSpawnNumberTotal(AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL) // <-- maximum not set .setMaxSpawnNumberTotal(AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL) // <-- maximum not set
.setEndTime(2) .setEndTime(2)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
first().sourceController.update(1); first().sourceController.update(1);
...@@ -329,8 +329,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -329,8 +329,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setMaxSpawnNumberTotal(4) // <-- not exhausted .setMaxSpawnNumberTotal(4) // <-- not exhausted
.setEndTime(2) .setEndTime(2)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
first().sourceController.update(1); first().sourceController.update(1);
...@@ -348,8 +348,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -348,8 +348,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setEndTime(endTime) .setEndTime(endTime)
.setMaxSpawnNumberTotal(maxSpawnNumberTotal) // <-- exhausted! .setMaxSpawnNumberTotal(maxSpawnNumberTotal) // <-- exhausted!
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
doUpdates(0, 50, 0, 200); doUpdates(0, 50, 0, 200);
...@@ -367,8 +367,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -367,8 +367,8 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setSpawnNumber(5) .setSpawnNumber(5)
.setMaxSpawnNumberTotal(maxSpawnNumberTotal) .setMaxSpawnNumberTotal(maxSpawnNumberTotal)
.setSourceDim(5.0, 5.0) .setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75); .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
groupSpawn = new Integer[]{4, 3, 4, 4}; .setGroupSizeDistributionMock(4, 3, 4, 4);
initialize(builder); initialize(builder);
doUpdates(0, 50, 0, 200); doUpdates(0, 50, 0, 200);
...@@ -379,18 +379,37 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant ...@@ -379,18 +379,37 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
@Test @Test
@Ignore @Ignore
public void multipleSources() { public void multipleSources() {
int maxSpawnNumberTotal = 4;
SourceTestAttributesBuilder builder1 = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder1 = new SourceTestAttributesBuilder()
.setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75) .setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
.setSourceDim(new VRectangle(0, 0, 3, 4)); .setSourceDim(new VRectangle(0, 0, 3, 4))
.setEndTime(4)
.setMaxSpawnNumberTotal(4)
.setGroupSizeDistributionMock(3, 4, 4, 4, 3);
SourceTestAttributesBuilder builder2 = new SourceTestAttributesBuilder() SourceTestAttributesBuilder builder2 = new SourceTestAttributesBuilder()
.setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class)
.setGroupSizeDistribution(0.0, 1.0) .setGroupSizeDistribution(0.0, 1.0)
.setSourceDim(new VRectangle(20, 20, 3, 2)); .setSourceDim(new VRectangle(20, 20, 3, 2))
groupSpawn = new Integer[]{4, 3, 4, 4}; // todo spawn group for multiple sources .setEndTime(6)
.setMaxSpawnNumberTotal(6)
.setGroupSizeDistributionMock(2, 2, 2, 2, 2, 2);
initialize(builder1); initialize(builder1);
initialize(builder2); initialize(builder2);
//todo test different Distributions for sources first().sourceController.update(1);
assertEquals(3, countPedestrians(0));
second().sourceController.update(1);
assertEquals(2, countPedestrians(1));
first().sourceController.update(2);
first().sourceController.update(3);
assertEquals(3 + 4 + 4, countPedestrians(0));
second().sourceController.update(2);
second().sourceController.update(3);
assertEquals(2 + 2 + 2, countPedestrians(1));
} }
......
...@@ -17,6 +17,7 @@ public class SourceTestAttributesBuilder { ...@@ -17,6 +17,7 @@ public class SourceTestAttributesBuilder {
private Class<? extends RealDistribution> distributionClass = ConstantDistribution.class; private Class<? extends RealDistribution> distributionClass = ConstantDistribution.class;
private double[] distributionParams = new double[] { 1 }; private double[] distributionParams = new double[] { 1 };
private double[] groupSizeDistribution = new double[]{0.0, 0.0, 1.0}; private double[] groupSizeDistribution = new double[]{0.0, 0.0, 1.0};
private Integer[] groupSizeDistributionMock = new Integer[]{};
private int maxSpawnNumberTotal = AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL; private int maxSpawnNumberTotal = AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL;
private double x0 = 0.0; private double x0 = 0.0;
private double y0 = 0.0; private double y0 = 0.0;
...@@ -113,6 +114,15 @@ public class SourceTestAttributesBuilder { ...@@ -113,6 +114,15 @@ public class SourceTestAttributesBuilder {
return this; return this;
} }
public SourceTestAttributesBuilder setGroupSizeDistributionMock(Integer... mock) {
this.groupSizeDistributionMock = mock;
return this;
}
public Integer[] getGroupSizeDistributionMock() {
return groupSizeDistributionMock;
}
private String groupSizeDistribution() { private String groupSizeDistribution() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("["); sb.append("[");
......
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