1
0

GasMixtureTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using Content.Server.Atmos;
  2. using Content.Server.Atmos.EntitySystems;
  3. using Content.Shared.Atmos;
  4. using Robust.Shared.GameObjects;
  5. namespace Content.IntegrationTests.Tests.Atmos
  6. {
  7. [TestFixture]
  8. [TestOf(typeof(GasMixture))]
  9. public sealed class GasMixtureTest
  10. {
  11. [Test]
  12. public async Task TestMerge()
  13. {
  14. await using var pair = await PoolManager.GetServerClient();
  15. var server = pair.Server;
  16. var atmosphereSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<AtmosphereSystem>();
  17. await server.WaitAssertion(() =>
  18. {
  19. var a = new GasMixture(10f);
  20. var b = new GasMixture(10f);
  21. a.AdjustMoles(Gas.Oxygen, 50);
  22. b.AdjustMoles(Gas.Nitrogen, 50);
  23. // a now has 50 moles of oxygen
  24. Assert.Multiple(() =>
  25. {
  26. Assert.That(a.TotalMoles, Is.EqualTo(50));
  27. Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(50));
  28. });
  29. // b now has 50 moles of nitrogen
  30. Assert.Multiple(() =>
  31. {
  32. Assert.That(b.TotalMoles, Is.EqualTo(50));
  33. Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(50));
  34. });
  35. atmosphereSystem.Merge(b, a);
  36. // b now has its contents and the contents of a
  37. Assert.Multiple(() =>
  38. {
  39. Assert.That(b.TotalMoles, Is.EqualTo(100));
  40. Assert.That(b.GetMoles(Gas.Oxygen), Is.EqualTo(50));
  41. Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(50));
  42. });
  43. // a should be the same, however.
  44. Assert.Multiple(() =>
  45. {
  46. Assert.That(a.TotalMoles, Is.EqualTo(50));
  47. Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(50));
  48. });
  49. });
  50. await pair.CleanReturnAsync();
  51. }
  52. [Test]
  53. [TestCase(0.5f)]
  54. [TestCase(0.25f)]
  55. [TestCase(0.75f)]
  56. [TestCase(1f)]
  57. [TestCase(0f)]
  58. [TestCase(Atmospherics.BreathPercentage)]
  59. public async Task RemoveRatio(float ratio)
  60. {
  61. await using var pair = await PoolManager.GetServerClient();
  62. var server = pair.Server;
  63. await server.WaitAssertion(() =>
  64. {
  65. var a = new GasMixture(10f);
  66. a.AdjustMoles(Gas.Oxygen, 100);
  67. a.AdjustMoles(Gas.Nitrogen, 100);
  68. var origTotal = a.TotalMoles;
  69. // we remove moles from the mixture with a ratio.
  70. var b = a.RemoveRatio(ratio);
  71. // check that the amount of moles in the original and the new mixture are correct.
  72. Assert.Multiple(() =>
  73. {
  74. Assert.That(b.TotalMoles, Is.EqualTo(origTotal * ratio));
  75. Assert.That(a.TotalMoles, Is.EqualTo(origTotal - b.TotalMoles));
  76. });
  77. Assert.Multiple(() =>
  78. {
  79. Assert.That(b.GetMoles(Gas.Oxygen), Is.EqualTo(100 * ratio));
  80. Assert.That(b.GetMoles(Gas.Nitrogen), Is.EqualTo(100 * ratio));
  81. });
  82. Assert.Multiple(() =>
  83. {
  84. Assert.That(a.GetMoles(Gas.Oxygen), Is.EqualTo(100 - b.GetMoles(Gas.Oxygen)));
  85. Assert.That(a.GetMoles(Gas.Nitrogen), Is.EqualTo(100 - b.GetMoles(Gas.Nitrogen)));
  86. });
  87. });
  88. await pair.CleanReturnAsync();
  89. }
  90. }
  91. }