Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests that run patrolling until completion #159

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions Assets/PlayModeTests/PatrollingSimulatorBuildingMapTestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;

using Maes.Map.MapGen;
using Maes.PatrollingAlgorithms;
using Maes.Simulation;
using Maes.Simulation.SimulationScenarios;

using NUnit.Framework;

using UnityEngine;

namespace PlayModeTests
{
using MySimulationScenario = PatrollingSimulationScenario;
using MySimulator = PatrollingSimulator;

public class PatrollingSimulatorBuildingMapTestTest : MonoBehaviour
{
private MySimulator _maes;
private PatrollingSimulation _simulation;

public void InitializeTestingSimulator()
{
_maes = new MySimulator();
var random = new System.Random(12345);
var mapSize = 50;

var constraintName = "Global";
var robotConstraints = StandardTestingConfiguration.GlobalRobotConstraints();
var mapConfig = new BuildingMapConfig(123, widthInTiles: mapSize, heightInTiles: mapSize);
var algoName = "conscientious_reactive";
const int robotCount = 1;
var spawningPosList = new List<Vector2Int>();
for (var amountOfSpawns = 0; amountOfSpawns < robotCount; amountOfSpawns++)
{
spawningPosList.Add(new Vector2Int(random.Next(0, mapSize), random.Next(0, mapSize)));
}

_maes.EnqueueScenario(
new MySimulationScenario(
seed: 123,
totalCycles: 4,
stopAfterDiff: false,
mapSpawner: generator => generator.GenerateMap(mapConfig),
robotSpawner: (buildingConfig, spawner) => spawner.SpawnRobotsAtPositions(
collisionMap: buildingConfig,
seed: 123,
numberOfRobots: robotCount,
spawnPositions: spawningPosList,
createAlgorithmDelegate: (_) => new ConscientiousReactiveAlgorithm()),
statisticsFileName: $"{algoName}-seed-{mapConfig.RandomSeed}-size-{mapSize}-comms-{constraintName}-robots-{robotCount}-SpawnTogether",
robotConstraints: robotConstraints
)
);
_simulation = _maes.SimulationManager.CurrentSimulation;
}

[TearDown]
public void ClearSimulator()
{
_maes.Destroy();
}

[Test(ExpectedResult = null)]
public IEnumerator TestConscientiousReactiveBuildingMap()
{
InitializeTestingSimulator();
_maes.SimulationManager.AttemptSetPlayState(Maes.UI.SimulationPlayState.FastAsPossible);
while (!_simulation.HasFinishedSim())
{
yield return null;
}
Assert.True(_simulation.HasFinishedSim());
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions Assets/PlayModeTests/PatrollingSimulatorCaveMapTestTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;

using Maes.Map.MapGen;
using Maes.PatrollingAlgorithms;
using Maes.Simulation;
using Maes.Simulation.SimulationScenarios;

using NUnit.Framework;

using UnityEngine;

namespace PlayModeTests
{
using MySimulationScenario = PatrollingSimulationScenario;
using MySimulator = PatrollingSimulator;

public class PatrollingSimulatorCaveMapTestTest : MonoBehaviour
{
private MySimulator _maes;
private PatrollingSimulation _simulation;

public void InitializeTestingSimulator()
{
_maes = new MySimulator();
var random = new System.Random(12345);
var mapSize = 50;

var constraintName = "Global";
var robotConstraints = StandardTestingConfiguration.GlobalRobotConstraints();
var mapConfig = new CaveMapConfig(123, widthInTiles: mapSize, heightInTiles: mapSize);
var algoName = "conscientious_reactive";
const int robotCount = 1;
var spawningPosList = new List<Vector2Int>();
for (var amountOfSpawns = 0; amountOfSpawns < robotCount; amountOfSpawns++)
{
spawningPosList.Add(new Vector2Int(random.Next(0, mapSize), random.Next(0, mapSize)));
}

_maes.EnqueueScenario(
new MySimulationScenario(
seed: 123,
totalCycles: 4,
stopAfterDiff: false,
mapSpawner: generator => generator.GenerateMap(mapConfig),
robotSpawner: (buildingConfig, spawner) => spawner.SpawnRobotsAtPositions(
collisionMap: buildingConfig,
seed: 123,
numberOfRobots: robotCount,
spawnPositions: spawningPosList,
createAlgorithmDelegate: (_) => new ConscientiousReactiveAlgorithm()),
statisticsFileName: $"{algoName}-seed-{mapConfig.RandomSeed}-size-{mapSize}-comms-{constraintName}-robots-{robotCount}-SpawnTogether",
robotConstraints: robotConstraints
)
);
_simulation = _maes.SimulationManager.CurrentSimulation;
}

[TearDown]
public void ClearSimulator()
{
_maes.Destroy();
}

[Test(ExpectedResult = null)]
public IEnumerator TestConscientiousReactiveCaveMap()
{
InitializeTestingSimulator();
_maes.SimulationManager.AttemptSetPlayState(Maes.UI.SimulationPlayState.FastAsPossible);
while (!_simulation.HasFinishedSim())
{
yield return null;
}
Assert.True(_simulation.HasFinishedSim());
}
}
}
11 changes: 11 additions & 0 deletions Assets/PlayModeTests/PatrollingSimulatorCaveMapTestTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/PlayModeTests/StandardTestingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// Original repository: https://github.com/Molitany/MAES

using Maes.Map.MapGen;
using Maes.Robot;
using Maes.Simulation.SimulationScenarios;

namespace PlayModeTests
Expand All @@ -40,5 +41,23 @@ public static MapFactory EmptyCaveMapSpawner(int randomSeed)
return (generator => generator.GenerateMap(mapConfiguration));
}

public static RobotConstraints GlobalRobotConstraints()
{
return new RobotConstraints(
senseNearbyAgentsRange: 5f,
senseNearbyAgentsBlockedByWalls: true,
automaticallyUpdateSlam: true,
slamUpdateIntervalInTicks: 1,
slamSynchronizeIntervalInTicks: 10,
slamPositionInaccuracy: 0.2f,
mapKnown: true,
distributeSlam: false,
environmentTagReadRange: 100f,
slamRayTraceRange: 7f,
relativeMoveSpeed: 1f,
agentRelativeSize: 0.6f,
calculateSignalTransmissionProbability: (_, _) => true);
}

}
}
Loading