Fix ScaleSolution() (#13630)
This commit is contained in:
@@ -317,7 +317,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
if (scale == 1)
|
||||
return;
|
||||
|
||||
if (scale == 0)
|
||||
if (scale <= 0)
|
||||
{
|
||||
RemoveAllSolution();
|
||||
return;
|
||||
@@ -326,7 +326,7 @@ namespace Content.Shared.Chemistry.Components
|
||||
_heatCapacity *= scale;
|
||||
Volume *= scale;
|
||||
|
||||
for (int i = 0; i <= Contents.Count; i++)
|
||||
for (int i = 0; i < Contents.Count; i++)
|
||||
{
|
||||
var old = Contents[i];
|
||||
Contents[i] = new ReagentQuantity(old.ReagentId, old.Quantity * scale);
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using NUnit.Framework;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Tests.Shared.Chemistry;
|
||||
|
||||
@@ -25,6 +26,51 @@ public sealed class Solution_Tests : ContentUnitTest
|
||||
Assert.That(quantity.Int(), Is.EqualTo(1000));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ScaleSolution()
|
||||
{
|
||||
var solution = new Solution();
|
||||
solution.AddReagent("water", FixedPoint2.New(20));
|
||||
solution.AddReagent("fire", FixedPoint2.New(30));
|
||||
|
||||
// Test integer scaling
|
||||
{
|
||||
var tmp = solution.Clone();
|
||||
tmp.ScaleSolution(0);
|
||||
Assert.That(tmp.Contents.Count, Is.EqualTo(0));
|
||||
Assert.That(tmp.Volume, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
tmp = solution.Clone();
|
||||
tmp.ScaleSolution(2);
|
||||
Assert.That(tmp.Contents.Count, Is.EqualTo(2));
|
||||
Assert.That(tmp.Volume, Is.EqualTo(FixedPoint2.New(100)));
|
||||
Assert.That(tmp.GetReagentQuantity("water"), Is.EqualTo(FixedPoint2.New(40)));
|
||||
Assert.That(tmp.GetReagentQuantity("fire"), Is.EqualTo(FixedPoint2.New(60)));
|
||||
}
|
||||
|
||||
// Test float scaling
|
||||
{
|
||||
var tmp = solution.Clone();
|
||||
tmp.ScaleSolution(0f);
|
||||
Assert.That(tmp.Contents.Count, Is.EqualTo(0));
|
||||
Assert.That(tmp.Volume, Is.EqualTo(FixedPoint2.Zero));
|
||||
|
||||
tmp = solution.Clone();
|
||||
tmp.ScaleSolution(2f);
|
||||
Assert.That(tmp.Contents.Count, Is.EqualTo(2));
|
||||
Assert.That(tmp.Volume, Is.EqualTo(FixedPoint2.New(100)));
|
||||
Assert.That(tmp.GetReagentQuantity("water"), Is.EqualTo(FixedPoint2.New(40)));
|
||||
Assert.That(tmp.GetReagentQuantity("fire"), Is.EqualTo(FixedPoint2.New(60)));
|
||||
|
||||
tmp = solution.Clone();
|
||||
tmp.ScaleSolution(0.3f);
|
||||
Assert.That(tmp.Contents.Count, Is.EqualTo(2));
|
||||
Assert.That(tmp.Volume, Is.EqualTo(FixedPoint2.New(15)));
|
||||
Assert.That(tmp.GetReagentQuantity("water"), Is.EqualTo(FixedPoint2.New(6)));
|
||||
Assert.That(tmp.GetReagentQuantity("fire"), Is.EqualTo(FixedPoint2.New(9)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConstructorAddReagent()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user