using NUnit.Framework; using UnityEngine; /// /// Test the MinigameList class /// [TestFixture] public class MinigameListTest { private MinigameList minigameList; /// /// Setup a minigameList with all possible minigames in the enum /// [SetUp] public void Setup_Minigame() { minigameList = ScriptableObject.CreateInstance(); // Add a minigame for each index in the enum // Dumb way to access each index in the enum, couldn't find a different way to do it though foreach (var field in typeof(MinigameIndex).GetFields()) { if (field.IsLiteral) { MinigameIndex value = (MinigameIndex)field.GetValue(null); string name = field.Name; Minigame m = ScriptableObject.CreateInstance(); // This is all we will need to distinguish m.index = value; m.title = name; // Insert in front to guarantee that MinigameIndex will not line up with listIndex minigameList.minigames.Insert(0, m); } } } /// /// Check if all minigames can be correctly fetched via GetMinigameByIndex /// [Test] public void TestGetMinigameByIndex() { foreach (var field in typeof(MinigameIndex).GetFields()) { if (field.IsLiteral) { MinigameIndex value = (MinigameIndex)field.GetValue(null); string name = field.Name; Minigame m = minigameList.GetMinigameByIndex(value); Assert.AreEqual(m.title, name); } } } /// /// Check if all minigames can be correctly set as current via SetCurrentMinigame /// [Test] public void TestSetCurrentMinigame() { foreach (var field in typeof(MinigameIndex).GetFields()) { if (field.IsLiteral) { MinigameIndex value = (MinigameIndex)field.GetValue(null); string name = field.Name; minigameList.SetCurrentMinigame(value); // Fetch the current minigame and check if its name is the same as the one we made into the current one Minigame m = minigameList.minigames[minigameList.currentMinigameIndex]; Assert.AreEqual(m.title, name); } } } }