Commit df8b7ca8 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen

update grp unit tests.

parent ac7563f3
Pipeline #70000 failed with stages
in 63 minutes and 40 seconds
......@@ -52,7 +52,7 @@ public class GroupSourceController extends SourceController {
while (iter.hasNext()) {
int groupSize = iter.next();
List<VPoint> newGroup = spawnArray.getNextGroup(groupSize, random, getDynElementsAtSource());
if (newGroup.size() == 0)
if (newGroup.isEmpty())
throw new RuntimeException("Cannot spawn new Group. Source " + source.getId() + " is set " +
"to useFreeSpaceOnly == false but no space is left to spawn group without exactly" +
"overlapping with neighbours which can cause numerical problems. Use useFreeSpaceOnly == true (default)" +
......@@ -69,7 +69,7 @@ public class GroupSourceController extends SourceController {
while (iter.hasNext()) {
int groupSize = iter.next();
List<VPoint> newGroup = spawnArray.getNextFreeGroup(groupSize, getDynElementsAtSource());
if (newGroup != null) {
if (newGroup != null && !newGroup.isEmpty()) {
// add immediately to Scenario to update DynElementsAtSource
addElementToScenario(newGroup);
iter.remove();
......@@ -82,7 +82,7 @@ public class GroupSourceController extends SourceController {
while (iter.hasNext()) {
int groupSize = iter.next();
List<VPoint> newGroup = spawnArray.getNextGroup(groupSize, getDynElementsAtSource());
if (newGroup == null)
if (newGroup == null || newGroup.isEmpty())
throw new RuntimeException("Cannot spawn new Group. Source " + source.getId() + " is set " +
"to useFreeSpaceOnly == false but no space is left to spawn group without exactly" +
"overlapping with neighbours which can cause numerical problems. Use useFreeSpaceOnly == true (default)" +
......@@ -100,9 +100,9 @@ public class GroupSourceController extends SourceController {
}
private void addElementToScenario(List<VPoint> group) {
if (!isMaximumNumberOfSpawnedElementsReached()) {
if (!group.isEmpty() && !isMaximumNumberOfSpawnedElementsReached()) {
addNewAgentToScenario(group);
dynamicElementsCreatedTotal++;
dynamicElementsCreatedTotal += group.size();
}
}
......
......@@ -106,7 +106,7 @@ public abstract class SourceController {
return maxNumber != AttributesSource.NO_MAX_SPAWN_NUMBER_TOTAL
&& dynamicElementsCreatedTotal >= maxNumber;
}
abstract protected boolean isQueueEmpty();
abstract protected void determineNumberOfSpawnsAndNextEvent(double simTimeInSec);
......
......@@ -329,8 +329,9 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
@Test
public void testMaxSpawnNumberTotalWithSmallEndTime() {
int maxSpawnNumberTotal = 4;
SourceTestAttributesBuilder builder = new SourceTestAttributesBuilder()
.setMaxSpawnNumberTotal(4) // <-- not exhausted
.setMaxSpawnNumberTotal(maxSpawnNumberTotal) // <-- not exhausted
.setEndTime(2)
.setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
......@@ -341,7 +342,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
first().sourceController.update(2);
first().sourceController.update(3);
assertEquals(7, countPedestrians(0));
assertEquals(maxSpawnNumberTotal, countPedestrians(0));
}
@Test
......@@ -353,12 +354,13 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setMaxSpawnNumberTotal(maxSpawnNumberTotal) // <-- exhausted!
.setSourceDim(5.0, 5.0)
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
.setGroupSizeDistributionMock(4, 3, 4, 4);
.setGroupSizeDistributionMock(4, 3, 4, 4)
.setUseFreeSpaceOnly(false);
initialize(builder);
doUpdates(0, 50, 0, 200);
assertEquals(15, countPedestrians(0));
assertEquals(maxSpawnNumberTotal, countPedestrians(0));
}
......@@ -377,7 +379,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
doUpdates(0, 50, 0, 200);
assertEquals(15, countPedestrians(0));
assertEquals(maxSpawnNumberTotal, countPedestrians(0));
}
@Test
......@@ -387,14 +389,16 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
.setGroupSizeDistribution(0.0, 0.0, 0.25, 0.75)
.setSourceDim(new VRectangle(0, 0, 3, 4))
.setEndTime(4)
.setMaxSpawnNumberTotal(4)
.setMaxSpawnNumberTotal(6)
.setUseFreeSpaceOnly(false)
.setGroupSizeDistributionMock(3, 4, 4, 4, 3);
SourceTestAttributesBuilder builder2 = new SourceTestAttributesBuilder()
.setDistributionClass(TestSourceControllerUsingDistributions.ConstantTestDistribution.class)
.setGroupSizeDistribution(0.0, 1.0)
.setSourceDim(new VRectangle(20, 20, 3, 2))
.setEndTime(6)
.setMaxSpawnNumberTotal(6)
.setMaxSpawnNumberTotal(20)
.setUseFreeSpaceOnly(false)
.setGroupSizeDistributionMock(2, 2, 2, 2, 2, 2);
initialize(builder1);
......@@ -408,7 +412,7 @@ public class GroupSourceControllerTest extends TestSourceControllerUsingConstant
first().sourceController.update(2);
first().sourceController.update(3);
assertEquals(3 + 4 + 4, countPedestrians(0));
assertEquals(3 + 4, countPedestrians(0));
second().sourceController.update(2);
second().sourceController.update(3);
......
......@@ -147,7 +147,7 @@ public class SourceTestAttributesBuilder {
+ ",\"distributionParameters\": " + Arrays.toString(distributionParams)
+ ",\"startTime\": " + startTime
+ ",\"endTime\": " + endTime
+ ",\"spawnAtRandomPositions\": true"
+ ",\"spawnAtRandomPositions\": false"
+ ",\"useFreeSpaceOnly\": " + useFreeSpaceOnly
+ ",\"groupSizeDistribution\" : " + groupSizeDistribution() + "\n"
+ ",\"targetIds\": [1]}";
......
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