Make GasMixture enumerable
I noticed that enumerating gases is frequently done in an annoying way with Enum.GetValues. So I made it better. Now GasMixture is IEnumerable<(Gas gas, float moles)> and it just works.
This commit is contained in:
30
Content.Tests/Shared/Atmos/GasMixtureTest.cs
Normal file
30
Content.Tests/Shared/Atmos/GasMixtureTest.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Content.Shared.Atmos;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Content.Tests.Shared.Atmos;
|
||||
|
||||
[TestFixture, TestOf(typeof(GasMixture))]
|
||||
[Parallelizable(ParallelScope.All)]
|
||||
public sealed class GasMixtureTest
|
||||
{
|
||||
[Test]
|
||||
public void TestEnumerate()
|
||||
{
|
||||
var mixture = new GasMixture();
|
||||
mixture.SetMoles(Gas.Oxygen, 20);
|
||||
mixture.SetMoles(Gas.Nitrogen, 10);
|
||||
mixture.SetMoles(Gas.Plasma, 80);
|
||||
|
||||
var expectedList = new (Gas, float)[Atmospherics.TotalNumberOfGases];
|
||||
for (var i = 0; i < Atmospherics.TotalNumberOfGases; i++)
|
||||
{
|
||||
expectedList[i].Item1 = (Gas)i;
|
||||
}
|
||||
|
||||
expectedList[(int)Gas.Oxygen].Item2 = 20f;
|
||||
expectedList[(int)Gas.Nitrogen].Item2 = 10f;
|
||||
expectedList[(int)Gas.Plasma].Item2 = 80f;
|
||||
|
||||
Assert.That(mixture, Is.EquivalentTo(expectedList));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user