< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadScene()0%2100%
TestAllSimulationConfigFilesLoad()0%1821300%

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]
 011  public void LoadScene() {
 012    SceneManager.LoadScene("Scenes/MainScene");
 013  }
 14
 15  [UnityTest]
 016  public IEnumerator TestAllSimulationConfigFilesLoad() {
 017    string configPath = ConfigLoader.GetStreamingAssetsFilePath("Configs/Simulations");
 018    string[] configFiles = Directory.GetFiles(configPath, "*.pbtxt");
 19
 020    Assert.IsTrue(configFiles.Length > 0, "No simulation configuration files found.");
 21
 022    bool isPaused = false;
 023    double epsilon = 0.0002;
 024    for (int i = 0; i < configFiles.Length; ++i) {
 025      if (i % 2 == 1) {
 026        SimManager.Instance.PauseSimulation();
 027        isPaused = true;
 028      }
 029      yield return new WaitForSecondsRealtime(0.1f);
 030      SimManager.Instance.LoadNewConfig(configFiles[i]);
 031      yield return new WaitForSecondsRealtime(0.1f);
 032      double elapsedTime = SimManager.Instance.GetElapsedSimulationTime();
 033      if (isPaused) {
 034        List<Agent> agents = SimManager.Instance.GetActiveAgents();
 035        foreach (Agent agent in agents) {
 036          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
 042          } else if (agent is Threat threat) {
 43            // All threats start in the INITIALIZED phase.
 044            Assert.AreEqual(
 45                Agent.FlightPhase.INITIALIZED, threat.GetFlightPhase(),
 46                "All threats should be in the INITIALIZED flight phase after loading while paused.");
 047          }
 048        }
 049        Assert.LessOrEqual(
 50            Mathf.Abs(Time.fixedDeltaTime), epsilon,
 51            "Fixed delta time should be approximately 0 after loading while paused.");
 052        Assert.LessOrEqual(Mathf.Abs(Time.timeScale), epsilon,
 53                           "Time scale should be approximately 0 after loading while paused.");
 054        Assert.IsFalse(elapsedTime > 0 + epsilon,
 55                       "Simulation time should not have advanced after loading while paused.");
 056      } else {
 057        Assert.IsTrue(elapsedTime > 0 + epsilon,
 58                      "Simulation time should have advanced after loading while not paused.");
 059        Assert.LessOrEqual(
 60            Mathf.Abs(Time.fixedDeltaTime -
 61                      (1.0f / SimManager.Instance.SimulatorConfig.PhysicsUpdateRate)),
 62            epsilon, "Physics update rate should be 1 / SimulatorConfig.PhysicsUpdateRate.");
 063      }
 64
 065      if (isPaused) {
 066        SimManager.Instance.ResumeSimulation();
 067        isPaused = false;
 068        yield return new WaitForSecondsRealtime(0.1f);
 069        Assert.IsTrue(SimManager.Instance.GetElapsedSimulationTime() > 0 + epsilon,
 70                      "Simulation time should have advanced after resuming.");
 071      }
 072    }
 073  }
 74}