Files
space-station-14/Content.IntegrationTests/Tests/Atmos/AlarmThresholdTest.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

143 lines
6.9 KiB
C#

using Content.IntegrationTests.Fixtures;
using Content.Shared.Atmos.Monitor;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Atmos
{
[TestFixture]
[TestOf(typeof(AtmosAlarmThreshold))]
public sealed class AlarmThresholdTest : GameTest
{
private const string AlarmThresholdTestDummyId = "AlarmThresholdTestDummy";
[TestPrototypes]
private const string Prototypes = $@"
- type: alarmThreshold
id: {AlarmThresholdTestDummyId}
upperBound: !type:AlarmThresholdSetting
threshold: 5
lowerBound: !type:AlarmThresholdSetting
threshold: 1
upperWarnAround: !type:AlarmThresholdSetting
threshold: 0.5
lowerWarnAround: !type:AlarmThresholdSetting
threshold: 1.5
";
[Test]
public async Task TestAlarmThreshold()
{
var pair = Pair;
var server = pair.Server;
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
AtmosAlarmThreshold threshold = default!;
var proto = prototypeManager.Index<AtmosAlarmThresholdPrototype>(AlarmThresholdTestDummyId);
threshold = new(proto);
await server.WaitAssertion(() =>
{
// ensure upper/lower bounds are calculated
Assert.Multiple(() =>
{
Assert.That(threshold.UpperWarningBound.Value, Is.EqualTo(5f * 0.5f));
Assert.That(threshold.LowerWarningBound.Value, Is.EqualTo(1f * 1.5f));
});
// ensure that setting bounds to zero/
// negative numbers is an invalid set
{
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, 0f);
Assert.That(threshold.UpperBound.Value, Is.EqualTo(5f));
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, -1f);
Assert.That(threshold.UpperBound.Value, Is.EqualTo(5f));
threshold.SetLimit(AtmosMonitorLimitType.LowerDanger, 0f);
Assert.That(threshold.LowerBound.Value, Is.EqualTo(1f));
threshold.SetLimit(AtmosMonitorLimitType.LowerDanger, -1f);
Assert.That(threshold.LowerBound.Value, Is.EqualTo(1f));
}
// test if making the lower bound higher
// than upper will adjust the upper value
{
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, 5f);
threshold.SetLimit(AtmosMonitorLimitType.LowerDanger, 6f);
Assert.That(threshold.LowerBound.Value, Is.LessThanOrEqualTo(threshold.UpperBound.Value));
}
// same as above, sets it lower
{
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, 5f);
threshold.SetLimit(AtmosMonitorLimitType.LowerDanger, 6f);
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, 1f);
Assert.That(threshold.LowerBound.Value, Is.LessThanOrEqualTo(threshold.UpperBound.Value));
}
// Check that the warning percentage is calculated correcly
{
threshold.SetLimit(AtmosMonitorLimitType.UpperWarning, threshold.UpperBound.Value * 0.5f);
Assert.That(threshold.UpperWarningPercentage.Value, Is.EqualTo(0.5f));
threshold.SetLimit(AtmosMonitorLimitType.LowerWarning, threshold.LowerBound.Value * 1.5f);
Assert.That(threshold.LowerWarningPercentage.Value, Is.EqualTo(1.5f));
threshold.SetLimit(AtmosMonitorLimitType.UpperWarning, threshold.UpperBound.Value * 0.5f);
Assert.That(threshold.UpperWarningPercentage.Value, Is.EqualTo(0.5f));
threshold.SetLimit(AtmosMonitorLimitType.LowerWarning, threshold.LowerBound.Value * 1.5f);
Assert.That(threshold.LowerWarningPercentage.Value, Is.EqualTo(1.5f));
}
// Check that the threshold reporting works correctly:
{
// Set threshold to some known state
threshold.SetLimit(AtmosMonitorLimitType.UpperDanger, 5f);
threshold.SetEnabled(AtmosMonitorLimitType.UpperDanger, true);
threshold.SetLimit(AtmosMonitorLimitType.LowerDanger, 1f);
threshold.SetEnabled(AtmosMonitorLimitType.LowerDanger, true);
threshold.SetLimit(AtmosMonitorLimitType.UpperWarning, 4f);
threshold.SetEnabled(AtmosMonitorLimitType.UpperWarning, true);
threshold.SetLimit(AtmosMonitorLimitType.LowerWarning, 2f);
threshold.SetEnabled(AtmosMonitorLimitType.LowerWarning, true);
// Check a value that's in between each upper/lower warning/panic:
threshold.CheckThreshold(3f, out var alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Normal));
threshold.CheckThreshold(1.5f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Warning));
threshold.CheckThreshold(4.5f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Warning));
threshold.CheckThreshold(5.5f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Danger));
threshold.CheckThreshold(0.5f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Danger));
// Check that enable/disable is respected:
threshold.CheckThreshold(123.4f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Danger));
threshold.SetEnabled(AtmosMonitorLimitType.UpperDanger, false);
threshold.CheckThreshold(123.4f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Warning));
threshold.SetEnabled(AtmosMonitorLimitType.UpperWarning, false);
threshold.CheckThreshold(123.4f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Normal));
// And for lower thresholds:
threshold.CheckThreshold(0.01f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Danger));
threshold.SetEnabled(AtmosMonitorLimitType.LowerDanger, false);
threshold.CheckThreshold(0.01f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Warning));
threshold.SetEnabled(AtmosMonitorLimitType.LowerWarning, false);
threshold.CheckThreshold(0.01f, out alarmType);
Assert.That(alarmType, Is.EqualTo(AtmosAlarmType.Normal));
}
});
}
}
}