1
0

SolutionRoundingTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Content.Shared.Chemistry.Components;
  2. using Content.Shared.Chemistry.EntitySystems;
  3. using Content.Shared.Chemistry.Reaction;
  4. using Content.Shared.Chemistry.Reagent;
  5. using Content.Shared.FixedPoint;
  6. using Robust.Shared.GameObjects;
  7. namespace Content.IntegrationTests.Tests.Chemistry;
  8. [TestFixture]
  9. [TestOf(typeof(ChemicalReactionSystem))]
  10. public sealed class SolutionRoundingTest
  11. {
  12. // This test tests two things:
  13. // * A rounding error in reaction code while I was making chloral hydrate
  14. // * An assert with solution heat capacity calculations that I found a repro for while testing the above.
  15. [TestPrototypes]
  16. private const string Prototypes = @"
  17. - type: entity
  18. id: SolutionRoundingTestContainer
  19. components:
  20. - type: SolutionContainerManager
  21. solutions:
  22. beaker:
  23. maxVol: 100
  24. # This is the Chloral Hydrate recipe fyi.
  25. - type: reagent
  26. id: SolutionRoundingTestReagentA
  27. name: reagent-name-nothing
  28. desc: reagent-desc-nothing
  29. physicalDesc: reagent-physical-desc-nothing
  30. - type: reagent
  31. id: SolutionRoundingTestReagentB
  32. name: reagent-name-nothing
  33. desc: reagent-desc-nothing
  34. physicalDesc: reagent-physical-desc-nothing
  35. - type: reagent
  36. id: SolutionRoundingTestReagentC
  37. name: reagent-name-nothing
  38. desc: reagent-desc-nothing
  39. physicalDesc: reagent-physical-desc-nothing
  40. - type: reagent
  41. id: SolutionRoundingTestReagentD
  42. name: reagent-name-nothing
  43. desc: reagent-desc-nothing
  44. physicalDesc: reagent-physical-desc-nothing
  45. - type: reaction
  46. id: SolutionRoundingTestReaction
  47. impact: Medium
  48. reactants:
  49. SolutionRoundingTestReagentA:
  50. amount: 3
  51. SolutionRoundingTestReagentB:
  52. amount: 1
  53. SolutionRoundingTestReagentC:
  54. amount: 1
  55. products:
  56. SolutionRoundingTestReagentD: 1
  57. ";
  58. [Test]
  59. public async Task Test()
  60. {
  61. await using var pair = await PoolManager.GetServerClient();
  62. var server = pair.Server;
  63. var testMap = await pair.CreateTestMap();
  64. Solution solution = default;
  65. Entity<SolutionComponent> solutionEnt = default;
  66. await server.WaitPost(() =>
  67. {
  68. var system = server.System<SharedSolutionContainerSystem>();
  69. var beaker = server.EntMan.SpawnEntity("SolutionRoundingTestContainer", testMap.GridCoords);
  70. system.TryGetSolution(beaker, "beaker", out var newSolutionEnt, out var newSolution);
  71. solutionEnt = newSolutionEnt!.Value;
  72. solution = newSolution!;
  73. system.TryAddSolution(solutionEnt, new Solution("SolutionRoundingTestReagentC", 50));
  74. system.TryAddSolution(solutionEnt, new Solution("SolutionRoundingTestReagentB", 30));
  75. for (var i = 0; i < 9; i++)
  76. {
  77. system.TryAddSolution(solutionEnt, new Solution("SolutionRoundingTestReagentA", 10));
  78. }
  79. });
  80. await server.WaitAssertion(() =>
  81. {
  82. Assert.Multiple(() =>
  83. {
  84. Assert.That(
  85. solution.ContainsReagent("SolutionRoundingTestReagentA", null),
  86. Is.False,
  87. "Solution should not contain reagent A");
  88. Assert.That(
  89. solution.ContainsReagent("SolutionRoundingTestReagentB", null),
  90. Is.False,
  91. "Solution should not contain reagent B");
  92. Assert.That(
  93. solution![new ReagentId("SolutionRoundingTestReagentC", null)].Quantity,
  94. Is.EqualTo((FixedPoint2) 20));
  95. Assert.That(
  96. solution![new ReagentId("SolutionRoundingTestReagentD", null)].Quantity,
  97. Is.EqualTo((FixedPoint2) 30));
  98. });
  99. });
  100. await pair.CleanReturnAsync();
  101. }
  102. }