Fluid spread refactor (#11908)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Fix undefined
This commit is contained in:
Ygg01
2022-11-15 12:30:59 +01:00
committed by GitHub
parent 89b959f931
commit 75ea093d78
17 changed files with 719 additions and 336 deletions

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using Content.Shared;
using NUnit.Framework;
using Robust.Shared.Maths;
using Robust.UnitTesting;
namespace Content.Tests.Shared;
[TestFixture]
public sealed class DirectionRandomizerTest : RobustUnitTest
{
[Test]
[TestCase(new[]
{
Direction.East,
Direction.NorthEast,
Direction.West,
Direction.NorthWest,
Direction.South,
Direction.SouthWest,
Direction.North,
Direction.SouthEast,
})]
[TestCase(new[]
{
Direction.East,
Direction.West,
Direction.South,
Direction.North,
})]
[TestCase(new[]
{
Direction.East,
Direction.West,
})]
public void TestRandomization(Direction[] x)
{
var set = new HashSet<Direction>(x);
var randomizer = new Span<Direction>(x);
randomizer.Shuffle();
foreach (var direction in randomizer)
{
if (set.Contains(direction))
{
set.Remove(direction);
}
else
{
// Asserts no double direction
Assert.Fail("Post randomization the enumerator had repeated direction");
}
}
// Because of above foreach this asserts
// rand[1,2,3] - [1,2,3] == {}
// i.e. randomized set minus original set is empty
Assert.IsTrue(set.Count == 0, "Each element must appear once ");
}
}