< Summary

Class:ConfigsTests
Assembly:bamlab.test.playmode
File(s):/github/workspace/Assets/Tests/PlayMode/ConfigsTests.cs
Covered lines:41
Uncovered lines:1
Coverable lines:42
Total lines:74
Line coverage:97.6% (41 of 42)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadScene()0%110100%
TestAllSimulationConfigFilesLoad()0%13.0313094.34%

File(s)

/github/workspace/Assets/Tests/PlayMode/ConfigsTests.cs

#LineLine coverage
 1using NUnit.Framework;
 2using System.IO;
 3using System.Collections;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7using UnityEngine.SceneManagement;
 8
 9public class ConfigsTests : TestBase {
 10  [OneTimeSetUp]
 111  public void LoadScene() {
 112    SceneManager.LoadScene("Scenes/MainScene");
 113  }
 14
 15  [UnityTest]
 116  public IEnumerator TestAllSimulationConfigFilesLoad() {
 117    string configPath = ConfigLoader.GetStreamingAssetsFilePath("Configs/Simulations");
 118    string[] configFiles = Directory.GetFiles(configPath, "*.pbtxt");
 19
 120    Assert.IsTrue(configFiles.Length > 0, "No simulation configuration files found.");
 21
 122    bool isPaused = false;
 123    double epsilon = 0.0002;
 2924    for (int i = 0; i < configFiles.Length; ++i) {
 1325      if (i % 2 == 1) {
 426        SimManager.Instance.PauseSimulation();
 427        isPaused = true;
 428      }
 929      yield return new WaitForSecondsRealtime(0.1f);
 930      SimManager.Instance.LoadNewConfig(configFiles[i]);
 931      yield return new WaitForSecondsRealtime(0.1f);
 932      double elapsedTime = SimManager.Instance.GetElapsedSimulationTime();
 1333      if (isPaused) {
 434        List<Agent> agents = SimManager.Instance.GetActiveAgents();
 170435        foreach (Agent agent in agents) {
 56436          if (agent is Interceptor interceptor) {
 37            // All interceptors start in the INITIALIZED phase.
 038            Assert.AreEqual(
 39                Agent.FlightPhase.INITIALIZED, interceptor.GetFlightPhase(),
 40                "All interceptors should be in the INITIALIZED flight phase after loading while paused.");
 41
 112842          } else if (agent is Threat threat) {
 43            // All threats start in the INITIALIZED phase.
 56444            Assert.AreEqual(
 45                Agent.FlightPhase.INITIALIZED, threat.GetFlightPhase(),
 46                "All threats should be in the INITIALIZED flight phase after loading while paused.");
 56447          }
 56448        }
 449        Assert.LessOrEqual(
 50            Mathf.Abs(Time.fixedDeltaTime), epsilon,
 51            "Fixed delta time should be approximately 0 after loading while paused.");
 452        Assert.LessOrEqual(Mathf.Abs(Time.timeScale), epsilon,
 53                           "Time scale should be approximately 0 after loading while paused.");
 454        Assert.IsFalse(elapsedTime > 0 + epsilon,
 55                       "Simulation time should not have advanced after loading while paused.");
 956      } else {
 557        Assert.IsTrue(elapsedTime > 0 + epsilon,
 58                      "Simulation time should have advanced after loading while not paused.");
 559        Assert.LessOrEqual(
 60            Mathf.Abs(Time.fixedDeltaTime -
 61                      (1.0f / SimManager.Instance.SimulatorConfig.PhysicsUpdateRate)),
 62            epsilon, "Physics update rate should be 1 / SimulatorConfig.PhysicsUpdateRate.");
 563      }
 64
 1365      if (isPaused) {
 466        SimManager.Instance.ResumeSimulation();
 467        isPaused = false;
 468        yield return new WaitForSecondsRealtime(0.1f);
 469        Assert.IsTrue(SimManager.Instance.GetElapsedSimulationTime() > 0 + epsilon,
 70                      "Simulation time should have advanced after resuming.");
 471      }
 972    }
 173  }
 74}