DamageSpecifierTest.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using Content.Shared.Damage;
  3. using Content.Shared.FixedPoint;
  4. namespace Content.IntegrationTests.Tests.Damageable;
  5. [TestFixture]
  6. [TestOf(typeof(DamageSpecifier))]
  7. public sealed class DamageSpecifierTest
  8. {
  9. [Test]
  10. public void TestDamageSpecifierOperations()
  11. {
  12. // Test basic math operations.
  13. // I've already nearly broken these once. When editing the operators.
  14. DamageSpecifier input1 = new() { DamageDict = Input1 };
  15. DamageSpecifier input2 = new() { DamageDict = Input2 };
  16. DamageSpecifier output1 = new() { DamageDict = Output1 };
  17. DamageSpecifier output2 = new() { DamageDict = Output2 };
  18. DamageSpecifier output3 = new() { DamageDict = Output3 };
  19. DamageSpecifier output4 = new() { DamageDict = Output4 };
  20. DamageSpecifier output5 = new() { DamageDict = Output5 };
  21. Assert.Multiple(() =>
  22. {
  23. Assert.That(-input1, Is.EqualTo(output1));
  24. Assert.That(input1 / 2, Is.EqualTo(output2));
  25. Assert.That(input1 * 2, Is.EqualTo(output3));
  26. });
  27. var difference = input1 - input2;
  28. Assert.That(difference, Is.EqualTo(output4));
  29. var difference2 = -input2 + input1;
  30. Assert.That(difference, Is.EqualTo(difference2));
  31. difference.Clamp(-0.25f, 0.25f);
  32. Assert.That(difference, Is.EqualTo(output5));
  33. }
  34. private static readonly Dictionary<string, FixedPoint2> Input1 = new()
  35. {
  36. { "A", 1.5f },
  37. { "B", 2 },
  38. { "C", 3 }
  39. };
  40. private static readonly Dictionary<string, FixedPoint2> Input2 = new()
  41. {
  42. { "A", 1 },
  43. { "B", 2 },
  44. { "C", 5 },
  45. { "D", 0.05f }
  46. };
  47. private static readonly Dictionary<string, FixedPoint2> Output1 = new()
  48. {
  49. { "A", -1.5f },
  50. { "B", -2 },
  51. { "C", -3 }
  52. };
  53. private static readonly Dictionary<string, FixedPoint2> Output2 = new()
  54. {
  55. { "A", 0.75f },
  56. { "B", 1 },
  57. { "C", 1.5 }
  58. };
  59. private static readonly Dictionary<string, FixedPoint2> Output3 = new()
  60. {
  61. { "A", 3f },
  62. { "B", 4 },
  63. { "C", 6 }
  64. };
  65. private static readonly Dictionary<string, FixedPoint2> Output4 = new()
  66. {
  67. { "A", 0.5f },
  68. { "B", 0 },
  69. { "C", -2 },
  70. { "D", -0.05f }
  71. };
  72. private static readonly Dictionary<string, FixedPoint2> Output5 = new()
  73. {
  74. { "A", 0.25f },
  75. { "B", 0 },
  76. { "C", -0.25f },
  77. { "D", -0.05f }
  78. };
  79. }