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

81 lines
2.4 KiB
C#

using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the CourseList class
/// </summary>
[TestFixture]
public class CourseListTest
{
private CourseList courseList;
/// <summary>
/// Setup a CourseList with all possible courses in the enum
/// </summary>
[SetUp]
public void Setup_Minigame()
{
courseList = ScriptableObject.CreateInstance<CourseList>();
// Add a course 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(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
Course course = ScriptableObject.CreateInstance<Course>();
// This is all we will need to distinguish
course.index = value;
course.title = name;
// Insert in front to guarantee that courseIndex will not line up with listIndex
courseList.courses.Insert(0, course);
}
}
}
/// <summary>
/// Check if all courses can be correctly fetched via GetCourseByIndex
/// </summary>
[Test]
public void TestGetMinigameByIndex()
{
foreach (var field in typeof(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
Course m = courseList.GetCourseByIndex(value);
Assert.AreEqual(m.title, name);
}
}
}
/// <summary>
/// Check if all courses can be correctly set as current via SetCurrentCourse
/// </summary>
[Test]
public void TestSetCurrentMinigame()
{
foreach (var field in typeof(CourseIndex).GetFields())
{
if (field.IsLiteral)
{
CourseIndex value = (CourseIndex)field.GetValue(null);
string name = field.Name;
courseList.SetCurrentCourse(value);
// Fetch the current course and check if its name is the same as the one we made into the current one
Course m = courseList.courses[courseList.currentCourseIndex];
Assert.AreEqual(m.title, name);
}
}
}
}