using System.Collections; using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; using KairoEngine.Stats; namespace KairoEngine.Stats.EditorTests { public class StatsControllerTests { private StatsController controller; [SetUp] public void Setup() { controller = new StatsController(); StatGroup statGroup = ScriptableObject.CreateInstance("StatGroup") as StatGroup; statGroup.statTemplates.Add(CreateStatTemplate().Setup("Endurance", "Stamina and HP", 0, 0, 10, "", "maxValue / 2", "", "")); statGroup.statTemplates.Add(CreateStatTemplate().Setup("Hitpoints", "damage points", 0, 0, 0, "", "maxValue", "", "s('Endurance') * 10")); controller.StatGroup = statGroup; } private StatTemplate CreateStatTemplate() => ScriptableObject.CreateInstance("StatTemplate") as StatTemplate; [TearDown] public void TearDown() { controller = null; } [Test] public void StatsController_New_Controller_Test() { Assert.NotNull(controller); } [Test] public void StatsController_GetStatValue_Test() { int n = controller.GetStatValue("Hitpoints"); Assert.AreEqual(50, n); } [Test] public void StatsController_GetStat_NotNull_Test() { Assert.NotNull(controller.GetStat("Hitpoints")); } [Test] public void StatsController_GetStat_WrongName_Test() { Assert.IsNull(controller.GetStat("HitpointZ")); } [Test] public void StatConstroller_GetStat_With_Modifier_Test() { Stat stat = controller.GetStat("Endurance"); stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring")); int n = stat.value; Assert.AreEqual(6, n); Assert.AreEqual(60, controller.GetStat("Hitpoints").maxValue); } [Test] public void StatConstroller_GetStat_With_Multiple_Modifier_Test() { Stat stat = controller.GetStat("Endurance"); stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring")); stat.modifiers.Add(new StatModifier("-", 1, "", "", "Endurance", "Hangover")); stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested")); stat.modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well fed")); int n = stat.value; Assert.AreEqual(7, n); Assert.AreEqual(70, controller.GetStat("Hitpoints").maxValue); } [Test] public void StatConstroller_GetStat_With_MaxValue_Modifier_Test() { controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested")); controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring")); Stat stat = controller.GetStat("Hitpoints"); stat.modifiers.Add(new StatModifier("+", 20, "", "max", "Hitpoints", "Healthy")); Assert.AreEqual(90, stat.maxValue); } [Test] public void StatConstroller_GetStat_With_MinValue_Modifier_Test() { controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Well rested")); controller.GetStat("Endurance").modifiers.Add(new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring")); Stat stat = controller.GetStat("Hitpoints"); stat.modifiers.Add(new StatModifier("-", 20, "", "min", "Hitpoints", "Death Defiance")); Assert.AreEqual(-20, stat.minValue); } [Test] public void StatConstroller_GetStat_With_Percentage_Modifier_Test() { Stat stat = controller.GetStat("Hitpoints"); stat.modifiers.Add(new StatModifier("+", 100, "%", "max", "Hitpoints", "Healthy")); Assert.AreEqual(100, stat.maxValue); } [Test] public void StatConstroller_Add_StatModifier() { Stat stat = controller.GetStat("Endurance"); StatModifier modifier = new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"); Assert.AreEqual(false, stat.modifiers.HasModifier(modifier)); stat.modifiers.Add(modifier); Assert.AreEqual(true, stat.modifiers.HasModifier(modifier)); } [Test] public void StatConstroller_Remove_StatModifier() { Stat stat = controller.GetStat("Endurance"); StatModifier modifier = new StatModifier("+", 1, "", "", "Endurance", "Vitality Ring"); stat.modifiers.Add(modifier); Assert.AreEqual(true, stat.modifiers.HasModifier(modifier)); stat.modifiers.Remove(modifier); Assert.AreEqual(false, stat.modifiers.HasModifier(modifier)); } } }