Resolve WES-187 "Unit tests account and system"
This commit is contained in:
committed by
Jerome Coudron
parent
c4b6c60288
commit
b9bbef8dcf
80
Assets/Common/Tests/EditMode/MinigameListTests.cs
Normal file
80
Assets/Common/Tests/EditMode/MinigameListTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user