using Content.IntegrationTests.Tests.Interaction; using Content.Server.Atmos.Components; using Content.Server.Atmos.EntitySystems; using Content.Shared.Atmos; using Content.Shared.Atmos.Components; using Content.Shared.Tests; using Robust.Shared.GameObjects; using Robust.Shared.Map.Components; using Robust.Shared.Maths; namespace Content.IntegrationTests.Tests.Atmos; /// /// Helper class for atmospherics tests. /// See on how to add new tests with custom maps. /// [TestFixture] public abstract class AtmosTest : InteractionTest { protected AtmosphereSystem SAtmos = default!; protected Content.Client.Atmos.EntitySystems.AtmosphereSystem CAtmos = default!; protected EntityLookupSystem LookupSystem = default!; protected Entity RelevantAtmos; /// /// Used in . Resolved during test setup. /// protected Entity ProcessEnt = default; protected virtual float Moles => 1000.0f; // 5% is a lot, but it can get this bad ATM... protected virtual float Tolerance => 0.05f; [SetUp] public override async Task Setup() { await base.Setup(); SAtmos = SEntMan.System(); CAtmos = CEntMan.System(); LookupSystem = SEntMan.System(); SEntMan.TryGetComponent(MapData.Grid, out var gridAtmosComp); SEntMan.TryGetComponent(MapData.Grid, out var overlayComp); SEntMan.TryGetComponent(MapData.Grid, out var mapGridComp); var xform = SEntMan.GetComponent(MapData.Grid); using (Assert.EnterMultipleScope()) { Assert.That(gridAtmosComp, Is.Not.Null, "Loaded map doesn't have a GridAtmosphereComponent on its grid. " + "Did you forget to override TestMapPath with a proper atmospherics testing map?"); Assert.That(overlayComp, Is.Not.Null, "Loaded map doesn't have a GasTileOverlayComponent on its grid. " + "Did you forget to override TestMapPath with a proper atmospherics testing map?"); Assert.That(mapGridComp, Is.Not.Null, "Loaded map doesn't have a MapGridComponent on its grid. " + "Did you forget to override TestMapPath with a proper atmospherics testing map?"); } RelevantAtmos = (MapData.Grid, gridAtmosComp); ProcessEnt = new Entity( MapData.Grid.Owner, gridAtmosComp, overlayComp, mapGridComp, xform); } /// /// Tries to get a mapped marker with a given name. /// /// Marker entities to look through /// Marker name to look up (set during mapping) /// Found marker EntityUid or Invalid /// True if found protected static bool GetMarker(Entity[] markers, string id, out EntityUid marker) { foreach (var ent in markers) { if (ent.Comp.Id == id) { marker = ent; return true; } } marker = EntityUid.Invalid; return false; } protected static float GetGridMoles(Entity grid) { var moles = 0.0f; foreach (var tile in grid.Comp.Tiles.Values) { moles += tile.Air?.TotalMoles ?? 0.0f; } return moles; } /// /// Asserts that test grid has this many moles, within tolerance percentage. /// protected void AssertGridMoles(float moles, float tolerance) { var gridMoles = GetGridMoles(RelevantAtmos); Assert.That(MathHelper.CloseToPercent(moles, gridMoles, tolerance), $"Grid has {gridMoles} moles, but {moles} was expected"); } /// /// Asserts that provided GasMixtures have same total moles, within tolerance percentage. /// protected void AssertMixMoles(GasMixture mix1, GasMixture mix2, float tolerance) { Assert.That(MathHelper.CloseToPercent(mix1.TotalMoles, mix2.TotalMoles, tolerance), $"GasMixtures do not match. Got {mix1.TotalMoles} and {mix2.TotalMoles} moles"); } }