Refactor MobThresholds and Stamina tests. (#43156)

Add 561 more tests.
This commit is contained in:
Moony 2026-03-10 21:12:56 +01:00 committed by Coryler
parent b26a9735aa
commit 6db5d7860a
2 changed files with 49 additions and 27 deletions

View File

@ -1,3 +1,4 @@
using Content.IntegrationTests.Utility;
using Content.Shared.Alert;
using Content.Shared.Mobs.Components;
@ -5,33 +6,31 @@ namespace Content.IntegrationTests.Tests.Damageable;
public sealed class MobThresholdsTest
{
/// <summary>
/// Inspects every entity prototype with a <see cref="MobThresholdsComponent"/> and makes
/// sure that every possible mob state is mapped to an <see cref="AlertPrototype"/>.
/// </summary>
private static string[] _entitiesWithThresholds = GameDataScrounger.EntitiesWithComponent("MobThresholds");
[Test]
public async Task ValidateMobThresholds()
[TestOf(typeof(MobThresholdsComponent))]
[TestCaseSource(nameof(_entitiesWithThresholds))]
[Description("Ensures every entity with mob thresholds has valid mob state configuration corresponding to some AlertPrototype.")]
public async Task ValidateMobThresholds(string protoKey)
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var entMan = server.EntMan;
var protoMan = server.ProtoMan;
var protos = pair.GetPrototypesWithComponent<MobThresholdsComponent>();
Assert.Multiple(() =>
{
foreach (var (proto, comp) in protos)
var proto = protoMan.Index(protoKey);
var comp = (MobThresholdsComponent)proto.Components["MobThresholds"].Component;
// See which mob states are mapped to alerts
var alertStates = comp.StateAlertDict.Keys;
// Check each mob state that this mob can be in
foreach (var (_, state) in comp.Thresholds)
{
// See which mob states are mapped to alerts
var alertStates = comp.StateAlertDict.Keys;
// Check each mob state that this mob can be in
foreach (var (_, state) in comp.Thresholds)
{
// Make sure that an alert exists for each possible mob state
Assert.That(alertStates, Does.Contain(state), $"{proto.ID} does not have an alert state for mob state {state}");
}
// Make sure that an alert exists for each possible mob state
Assert.That(alertStates, Does.Contain(state), $"{proto.ID} does not have an alert state for mob state {state}");
}
});

View File

@ -1,27 +1,50 @@
using System.Linq;
using Content.IntegrationTests.Utility;
using Content.Shared.Damage.Components;
using Content.Shared.FixedPoint;
namespace Content.IntegrationTests.Tests.Damageable;
public sealed class StaminaComponentTest
{
private static string[] _entitiesWithStamina = GameDataScrounger.EntitiesWithComponent("Stamina");
[Test]
public async Task ValidatePrototypes()
[TestOf(typeof(StaminaComponent))]
[TestCaseSource(nameof(_entitiesWithStamina))]
[Description("Ensures every entity with Stamina has a valid stamina configuration.")]
public async Task ValidateStamina(string protoKey)
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var protos = pair.GetPrototypesWithComponent<StaminaComponent>();
var protoMan = server.ProtoMan;
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
foreach (var (proto, comp) in protos)
{
Assert.That(comp.AnimationThreshold, Is.LessThan(comp.CritThreshold),
$"Animation threshold on {proto.ID} must be less than its crit threshold.");
}
});
var proto = protoMan.Index(protoKey);
var comp = (StaminaComponent)proto.Components["Stamina"].Component;
Assert.That(comp.AnimationThreshold,
Is.LessThan(comp.CritThreshold),
$"Animation threshold on {proto.ID} must be less than its crit threshold.");
// TODO(Kaylie): "value is in range" serializer. Needs some serializationmanager improvements.
Assert.That(comp.Decay, Is.Positive.Or.Zero, "Negative decay results in nonsensical behavior.");
Assert.That(comp.Cooldown, Is.Positive.Or.Zero, "Negative cooldown results in nonsensical behavior");
Assert.That(comp.BaseCritThreshold, Is.Positive);
Assert.That(comp.CritThreshold, Is.Positive);
Assert.That(comp.AfterCritDecayMultiplier, Is.Positive);
Assert.That(comp.ForceStandStamina, Is.Positive);
// NUnit's analyzer is defective here. Cool.
#pragma warning disable NUnit2041
Assert.That(comp.StunModifierThresholds.Keys,
Has.All.GreaterThanOrEqualTo(FixedPoint2.Zero).And.LessThanOrEqualTo(FixedPoint2.New(1.0f)),
"The stun thresholds are percentages and should be in the [0, 1.0] range.");
#pragma warning restore NUnit2041
}
});
await pair.CleanReturnAsync();