Files
unity-application/Assets/Common/Tests/MinigameListTest.cs
2023-03-25 13:12:55 +00:00

81 lines
2.5 KiB
C#

using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the MinigameList class
/// </summary>
[TestFixture]
public class MinigameListTest
{
private MinigameList minigameList;
/// <summary>
/// Setup a minigameList with all possible minigames in the enum
/// </summary>
[SetUp]
public void Setup_Minigame()
{
minigameList = ScriptableObject.CreateInstance<MinigameList>();
// 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<Minigame>();
// 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);
}
}
}
/// <summary>
/// Check if all minigames can be correctly fetched via GetMinigameByIndex
/// </summary>
[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);
}
}
}
/// <summary>
/// Check if all minigames can be correctly set as current via SetCurrentMinigame
/// </summary>
[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);
}
}
}
}