Fixed comments

ReagentUnit now implements IComparable and IEquateable.
ReagentUnit now uses double internally.
Added multiplication without shifting for ints.
InvariantCulture for some string things.
Added units tests for Equals and CompareTo.
Added unit tests to Solution that deals with nasty fractionals.
This commit is contained in:
PrPleGoo
2020-04-09 20:40:59 +02:00
parent 20cb9b92ab
commit 4e67f09488
3 changed files with 115 additions and 7 deletions

View File

@@ -118,5 +118,37 @@ namespace Content.Tests.Shared.Chemistry
var result = (int) Math.Round(a * (float) Math.Pow(10, 2));
Assert.AreEqual(expected, result);
}
[Test]
public void ReagentUnitMin()
{
var unorderedList = new[]
{
ReagentUnit.New(5),
ReagentUnit.New(3),
ReagentUnit.New(1),
ReagentUnit.New(2),
ReagentUnit.New(4),
};
var min = ReagentUnit.Min(unorderedList);
Assert.AreEqual(ReagentUnit.New(1), min);
}
[Test]
[TestCase(1, 0, false)]
[TestCase(0, 0, true)]
[TestCase(-1, 0, false)]
[TestCase(null, 0, true)]
[TestCase(1, 1, true)]
[TestCase(0, 1, false)]
[TestCase(-1, 1, false)]
[TestCase(null, 1, false)]
public void ReagentUnitEquals(int a, int b, bool expected)
{
var parameter = ReagentUnit.New(a);
var comparison = ReagentUnit.New(b);
Assert.AreEqual(comparison.Equals(parameter), parameter.Equals(comparison));
Assert.AreEqual(expected, comparison.Equals(parameter));
}
}
}

View File

@@ -203,6 +203,41 @@ namespace Content.Tests.Shared.Chemistry
Assert.That(splitSolution.TotalVolume.Int(), Is.EqualTo(750));
}
[Test]
public void SplitSolutionFractional()
{
var solution = new Solution();
solution.AddReagent("water", ReagentUnit.New(1));
solution.AddReagent("fire", ReagentUnit.New(2));
var splitSolution = solution.SplitSolution(ReagentUnit.New(1));
Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(0.67f));
Assert.That(solution.GetReagentQuantity("fire").Float(), Is.EqualTo(1.33f));
Assert.That(solution.TotalVolume.Int(), Is.EqualTo(2));
Assert.That(splitSolution.GetReagentQuantity("water").Float(), Is.EqualTo(0.33f));
Assert.That(splitSolution.GetReagentQuantity("fire").Float(), Is.EqualTo(0.67f));
Assert.That(splitSolution.TotalVolume.Int(), Is.EqualTo(1));
}
[Test]
[TestCase(0.03f, 0.01f, 0.02f)]
[TestCase(0.03f, 0.02f, 0.01f)]
public void SplitSolutionTinyFractionalBigSmall(float initial, float reduce, float remainder)
{
var solution = new Solution();
solution.AddReagent("water", ReagentUnit.New(initial));
var splitSolution = solution.SplitSolution(ReagentUnit.New(reduce));
Assert.That(solution.GetReagentQuantity("water").Float(), Is.EqualTo(remainder));
Assert.That(solution.TotalVolume.Float(), Is.EqualTo(remainder));
Assert.That(splitSolution.GetReagentQuantity("water").Float(), Is.EqualTo(reduce));
Assert.That(splitSolution.TotalVolume.Float(), Is.EqualTo(reduce));
}
[Test]
public void SplitSolutionMoreThanTotalRemovesAll()
{