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 CourseList class
/// </summary>
[TestFixture]
public class CourseListTests
{
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);
}
}
}
}