Resolve WES-187 "Unit tests account and system"

This commit is contained in:
Dries Van Schuylenbergh
2023-04-30 15:51:41 +00:00
committed by Jerome Coudron
parent c4b6c60288
commit b9bbef8dcf
143 changed files with 2008 additions and 542 deletions

View File

@@ -0,0 +1,80 @@
using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the MinigameList class
/// </summary>
[TestFixture]
public class MinigameListTests
{
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);
}
}
}
}