StatsControllerTests.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using KairoEngine.Stats;
  7. namespace KairoEngine.Stats.EditorTests
  8. {
  9. public class StatsControllerTests
  10. {
  11. private StatsController controller;
  12. [SetUp]
  13. public void Setup()
  14. {
  15. controller = new StatsController();
  16. StatGroup statGroup = ScriptableObject.CreateInstance("StatGroup") as StatGroup;
  17. statGroup.statTemplates.Add(CreateStatTemplate().Setup("Endurance", "Stamina and HP", 0, 0, 10, "", "maxValue / 2", "", ""));
  18. statGroup.statTemplates.Add(CreateStatTemplate().Setup("Hitpoints", "damage points", 0, 0, 0, "", "maxValue", "", "s('Endurance') * 10"));
  19. controller.StatGroup = statGroup;
  20. }
  21. private StatTemplate CreateStatTemplate() => ScriptableObject.CreateInstance("StatTemplate") as StatTemplate;
  22. [TearDown]
  23. public void TearDown()
  24. {
  25. controller = null;
  26. }
  27. [Test]
  28. public void StatsController_New_Controller_Test()
  29. {
  30. Assert.NotNull(controller);
  31. }
  32. [Test]
  33. public void StatsController_GetStatValue_Test()
  34. {
  35. int n = controller.GetStatValue("Hitpoints");
  36. Assert.AreEqual(50, n);
  37. }
  38. [Test]
  39. public void StatsController_GetStat_NotNull_Test()
  40. {
  41. Assert.NotNull(controller.GetStat("Hitpoints"));
  42. }
  43. [Test]
  44. public void StatsController_GetStat_WrongName_Test()
  45. {
  46. Assert.IsNull(controller.GetStat("HitpointZ"));
  47. }
  48. [Test]
  49. public void StatConstroller_GetStat_With_Modifier_Test()
  50. {
  51. Stat stat = controller.GetStat("Endurance");
  52. stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"));
  53. int n = stat.value;
  54. Assert.AreEqual(6, n);
  55. Assert.AreEqual(60, controller.GetStat("Hitpoints").maxValue);
  56. }
  57. [Test]
  58. public void StatConstroller_GetStat_With_Multiple_Modifier_Test()
  59. {
  60. Stat stat = controller.GetStat("Endurance");
  61. stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"));
  62. stat.modifiers.Add(new StatModifier("-", 1, "", "", "Endurance", "Hangover"));
  63. stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested"));
  64. stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well fed"));
  65. int n = stat.value;
  66. Assert.AreEqual(7, n);
  67. Assert.AreEqual(70, controller.GetStat("Hitpoints").maxValue);
  68. }
  69. [Test]
  70. public void StatConstroller_GetStat_With_MaxValue_Modifier_Test()
  71. {
  72. controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested"));
  73. controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"));
  74. Stat stat = controller.GetStat("Hitpoints");
  75. stat.modifiers.Add(new StatModifier("+", 20, "", "max", "Hitpoints", "Healthy"));
  76. Assert.AreEqual(90, stat.maxValue);
  77. }
  78. [Test]
  79. public void StatConstroller_GetStat_With_MinValue_Modifier_Test()
  80. {
  81. controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested"));
  82. controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"));
  83. Stat stat = controller.GetStat("Hitpoints");
  84. stat.modifiers.Add(new StatModifier("-", 20, "", "min", "Hitpoints", "Death Defiance"));
  85. Assert.AreEqual(-20, stat.minValue);
  86. }
  87. [Test]
  88. public void StatConstroller_GetStat_With_Percentage_Modifier_Test()
  89. {
  90. Stat stat = controller.GetStat("Hitpoints");
  91. stat.modifiers.Add(new StatModifier("+", 100, "%", "max", "Hitpoints", "Healthy"));
  92. Assert.AreEqual(100, stat.maxValue);
  93. }
  94. [Test]
  95. public void StatConstroller_Add_StatModifier()
  96. {
  97. Stat stat = controller.GetStat("Endurance");
  98. StatModifier modifier = new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring");
  99. Assert.AreEqual(false, stat.modifiers.HasModifier(modifier));
  100. stat.modifiers.Add(modifier);
  101. Assert.AreEqual(true, stat.modifiers.HasModifier(modifier));
  102. }
  103. [Test]
  104. public void StatConstroller_Remove_StatModifier()
  105. {
  106. Stat stat = controller.GetStat("Endurance");
  107. StatModifier modifier = new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring");
  108. stat.modifiers.Add(modifier);
  109. Assert.AreEqual(true, stat.modifiers.HasModifier(modifier));
  110. stat.modifiers.Remove(modifier);
  111. Assert.AreEqual(false, stat.modifiers.HasModifier(modifier));
  112. }
  113. }
  114. }