Refactor explosion prototype tests. (#43158)

Add 9 more tests.
This commit is contained in:
Moony 2026-03-10 20:56:10 +01:00 committed by Coryler
parent 13900c9ffb
commit bc5b6299a6
1 changed files with 28 additions and 10 deletions

View File

@ -1,27 +1,45 @@
using Content.IntegrationTests.Utility;
using Content.Shared.Explosion;
namespace Content.IntegrationTests.Tests.Explosion;
public sealed class ExplosionPrototypeTest
{
private static string[] _explosionKinds = GameDataScrounger.PrototypesOfKind<ExplosionPrototype>();
[Test]
public async Task ValidateExplosionPrototypes()
[TestOf(typeof(ExplosionPrototype))]
[TestCaseSource(nameof(_explosionKinds))]
[Description("Ensures various properties of ExplosionPrototype are correctly configured.")]
public async Task Validate(string protoKey)
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var entMan = server.EntMan;
var protoMan = server.ProtoMan;
var protos = protoMan.EnumeratePrototypes<ExplosionPrototype>();
var proto = protoMan.Index<ExplosionPrototype>(protoKey);
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{
foreach (var proto in protos)
{
Assert.That(proto._tileBreakChance, Is.Not.Empty, $"Empty tile break chance definitions for explosion prototype: {proto.ID}");
Assert.That(proto._tileBreakChance, Has.Length.EqualTo(proto._tileBreakIntensity.Length), $"Malformed tile break chance definitions for explosion prototype: {proto.ID}");
}
});
Assert.That(proto._tileBreakChance, Is.Not.Empty, $"Tile break chances cannot be empty.");
// this diagnostic is broken.
#pragma warning disable NUnit2041
Assert.That(proto._tileBreakChance,
Has.All.GreaterThanOrEqualTo(0.0f).And.LessThanOrEqualTo(1.0f),
"Tile break chances are probabilities and must be in the range [0, 1]");
#pragma warning restore NUnit2041
Assert.That(proto._tileBreakChance,
Has.Length.EqualTo(proto._tileBreakIntensity.Length),
$"Tile break chances don't match the tile break intensities.");
Assert.That(proto.FireStacks, Is.Null.Or.Positive);
Assert.That(proto.Temperature, Is.Null.Or.Positive);
Assert.That(proto.TileBreakRerollReduction, Is.Positive.Or.Zero);
Assert.That(proto.SmallSoundIterationThreshold, Is.Positive.Or.Zero);
Assert.That(proto.MaxCombineDistance, Is.Positive.Or.Zero);
Assert.That(proto.IntensityPerState, Is.Positive);
Assert.That(proto.FireStates, Is.Positive);
}
await pair.CleanReturnAsync();
}