Files
space-station-14/Content.IntegrationTests/Tests/Chemistry/SolutionSystemTests.cs
T
Moony d42adbf05d Gametest Part 2: Preliminary refactor every test to use GameTest as the framework. (#43207)
* Pass 1.

* i'm FREE

* Prevent hangups.

* okay fine here's an attribute for settings, will polish later and prolly remove the overridable thing.

* sigh.

* fix singular trigger bug so LatheTest doesn't flake.

* Remove SystemAttribute usage.

* Poke

* I used the shotgun. You know why? Cause the shot gun doesn’t miss, and unlike the shitty hybrid taser it stops a criminal in their tracks in two hits. Bang, bang, and they’re fucking done. I use four shots just to make damn sure. Because, once again, I’m not there to coddle a buncha criminal scum sucking f------, I’m there to 1) Survive the fucking round. 2) Guard the armory. So you can absolutely get fucked. If I get unbanned, which I won’t, you can guarantee I will continue to use the shotgun to apprehend criminals. Because it’s quick, clean and effective as fuck. Why in the seven hells would I fuck around with the disabler shots, which take half a clip just to bring someone down, or with the tazer bolts which are slow as balls, impossible to aim and do about next to jack shit, fuck all. The shotgun is the superior law enforcement weapon. Because it stops crime. And it stops crime by reducing the number of criminals roaming the fucking halls.

* Change the faulty store test into two tests, one of which is ignored for failing.
2026-04-01 16:06:26 +00:00

262 lines
9.7 KiB
C#

using Content.IntegrationTests.Fixtures;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Chemistry;
// We are adding two non-reactive solutions in these tests
// To ensure volume(A) + volume(B) = volume(A+B)
// reactions can change this assumption
[TestFixture]
[TestOf(typeof(SharedSolutionContainerSystem))]
public sealed class SolutionSystemTests : GameTest
{
[TestPrototypes]
private const string Prototypes = @"
- type: entity
id: SolutionTarget
components:
- type: SolutionContainerManager
solutions:
beaker:
maxVol: 50
- type: reagent
id: TestReagentA
name: reagent-name-nothing
desc: reagent-desc-nothing
physicalDesc: reagent-physical-desc-nothing
- type: reagent
id: TestReagentB
name: reagent-name-nothing
desc: reagent-desc-nothing
physicalDesc: reagent-physical-desc-nothing
- type: reagent
id: TestReagentC
specificHeat: 2.0
name: reagent-name-nothing
desc: reagent-desc-nothing
physicalDesc: reagent-physical-desc-nothing
";
private const string TestReagentA = "TestReagentA";
private const string TestReagentB = "TestReagentB";
private const string TestReagentC = "TestReagentC";
private const string Water = "Water";
private const string Oil = "Oil";
[Test]
public async Task TryAddTwoNonReactiveReagent()
{
var pair = Pair;
var server = pair.Server;
var entityManager = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var containerSystem = entityManager.System<SharedSolutionContainerSystem>();
var testMap = await pair.CreateTestMap();
var coordinates = testMap.GridCoords;
EntityUid beaker;
await server.WaitAssertion(() =>
{
var oilQuantity = FixedPoint2.New(15);
var waterQuantity = FixedPoint2.New(10);
var oilAdded = new Solution(Oil, oilQuantity);
var originalWater = new Solution(Water, waterQuantity);
beaker = entityManager.SpawnEntity("SolutionTarget", coordinates);
Assert.That(containerSystem
.TryGetSolution(beaker, "beaker", out var solutionEnt, out var solution));
solution.AddSolution(originalWater, protoMan);
Assert.That(containerSystem
.TryAddSolution(solutionEnt.Value, oilAdded));
var water = solution.GetTotalPrototypeQuantity(Water);
var oil = solution.GetTotalPrototypeQuantity(Oil);
Assert.Multiple(() =>
{
Assert.That(water, Is.EqualTo(waterQuantity));
Assert.That(oil, Is.EqualTo(oilQuantity));
});
});
}
// This test mimics current behavior
// i.e. if adding too much `TryAddSolution` adding will fail
[Test]
public async Task TryAddTooMuchNonReactiveReagent()
{
var pair = Pair;
var server = pair.Server;
var testMap = await pair.CreateTestMap();
var entityManager = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var containerSystem = entityManager.System<SharedSolutionContainerSystem>();
var coordinates = testMap.GridCoords;
EntityUid beaker;
await server.WaitAssertion(() =>
{
var oilQuantity = FixedPoint2.New(1500);
var waterQuantity = FixedPoint2.New(10);
var oilAdded = new Solution(Oil, oilQuantity);
var originalWater = new Solution(Water, waterQuantity);
beaker = entityManager.SpawnEntity("SolutionTarget", coordinates);
Assert.That(containerSystem
.TryGetSolution(beaker, "beaker", out var solutionEnt, out var solution));
solution.AddSolution(originalWater, protoMan);
Assert.That(containerSystem
.TryAddSolution(solutionEnt.Value, oilAdded), Is.False);
var water = solution.GetTotalPrototypeQuantity(Water);
var oil = solution.GetTotalPrototypeQuantity(Oil);
Assert.Multiple(() =>
{
Assert.That(water, Is.EqualTo(waterQuantity));
Assert.That(oil, Is.EqualTo(FixedPoint2.Zero));
});
});
}
// Unlike TryAddSolution this adds and two solution without then splits leaving only threshold in original
[Test]
public async Task TryMixAndOverflowTooMuchReagent()
{
var pair = Pair;
var server = pair.Server;
var entityManager = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var testMap = await pair.CreateTestMap();
var containerSystem = entityManager.System<SharedSolutionContainerSystem>();
var coordinates = testMap.GridCoords;
EntityUid beaker;
await server.WaitAssertion(() =>
{
var ratio = 9;
var threshold = 20;
var waterQuantity = FixedPoint2.New(10);
var oilQuantity = FixedPoint2.New(ratio * waterQuantity.Int());
var oilAdded = new Solution(Oil, oilQuantity);
var originalWater = new Solution(Water, waterQuantity);
beaker = entityManager.SpawnEntity("SolutionTarget", coordinates);
Assert.That(containerSystem
.TryGetSolution(beaker, "beaker", out var solutionEnt, out var solution));
solution.AddSolution(originalWater, protoMan);
Assert.That(containerSystem
.TryMixAndOverflow(solutionEnt.Value, oilAdded, threshold, out var overflowingSolution));
Assert.Multiple(() =>
{
Assert.That(solution.Volume, Is.EqualTo(FixedPoint2.New(threshold)));
var waterMix = solution.GetTotalPrototypeQuantity(Water);
var oilMix = solution.GetTotalPrototypeQuantity(Oil);
Assert.That(waterMix, Is.EqualTo(FixedPoint2.New(threshold / (ratio + 1))));
Assert.That(oilMix, Is.EqualTo(FixedPoint2.New(threshold / (ratio + 1) * ratio)));
Assert.That(overflowingSolution.Volume, Is.EqualTo(FixedPoint2.New(80)));
var waterOverflow = overflowingSolution.GetTotalPrototypeQuantity(Water);
var oilOverFlow = overflowingSolution.GetTotalPrototypeQuantity(Oil);
Assert.That(waterOverflow, Is.EqualTo(waterQuantity - waterMix));
Assert.That(oilOverFlow, Is.EqualTo(oilQuantity - oilMix));
});
});
}
// TryMixAndOverflow will fail if Threshold larger than MaxVolume
[Test]
public async Task TryMixAndOverflowTooBigOverflow()
{
var pair = Pair;
var server = pair.Server;
var entityManager = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var containerSystem = entityManager.System<SharedSolutionContainerSystem>();
var testMap = await pair.CreateTestMap();
var coordinates = testMap.GridCoords;
EntityUid beaker;
await server.WaitAssertion(() =>
{
var ratio = 9;
var threshold = 60;
var waterQuantity = FixedPoint2.New(10);
var oilQuantity = FixedPoint2.New(ratio * waterQuantity.Int());
var oilAdded = new Solution(Oil, oilQuantity);
var originalWater = new Solution(Water, waterQuantity);
beaker = entityManager.SpawnEntity("SolutionTarget", coordinates);
Assert.That(containerSystem
.TryGetSolution(beaker, "beaker", out var solutionEnt, out var solution));
solution.AddSolution(originalWater, protoMan);
Assert.That(containerSystem
.TryMixAndOverflow(solutionEnt.Value, oilAdded, threshold, out _),
Is.False);
});
}
[Test]
public async Task TestTemperatureCalculations()
{
var pair = Pair;
var server = pair.Server;
var protoMan = server.ResolveDependency<IPrototypeManager>();
const float temp = 100.0f;
// Adding reagent with adjusts temperature
await server.WaitAssertion(() =>
{
var solution = new Solution(TestReagentA, FixedPoint2.New(100)) { Temperature = temp };
Assert.That(solution.Temperature, Is.EqualTo(temp * 1));
solution.AddSolution(new Solution(TestReagentA, FixedPoint2.New(100)) { Temperature = temp * 3 }, protoMan);
Assert.That(solution.Temperature, Is.EqualTo(temp * 2));
solution.AddSolution(new Solution(TestReagentB, FixedPoint2.New(100)) { Temperature = temp * 5 }, protoMan);
Assert.That(solution.Temperature, Is.EqualTo(temp * 3));
});
// adding solutions combines thermal energy
await server.WaitAssertion(() =>
{
var solutionOne = new Solution(TestReagentA, FixedPoint2.New(100)) { Temperature = temp };
var solutionTwo = new Solution(TestReagentB, FixedPoint2.New(100)) { Temperature = temp };
solutionTwo.AddReagent(TestReagentC, FixedPoint2.New(100));
var thermalEnergyOne = solutionOne.GetHeatCapacity(protoMan) * solutionOne.Temperature;
var thermalEnergyTwo = solutionTwo.GetHeatCapacity(protoMan) * solutionTwo.Temperature;
solutionOne.AddSolution(solutionTwo, protoMan);
Assert.That(solutionOne.GetHeatCapacity(protoMan) * solutionOne.Temperature, Is.EqualTo(thermalEnergyOne + thermalEnergyTwo));
});
}
}