Files
unity-application/Assets/Common/Tests/ModelListTest.cs
2023-03-27 10:57:30 +02:00

78 lines
2.4 KiB
C#

using NUnit.Framework;
using Unity.Barracuda;
using UnityEngine;
/// <summary>
/// Test the ModelList class
/// </summary>
[TestFixture]
public class ModelListTest
{
private ModelList modelList;
/// <summary>
/// Setup a ModelList with all possible Models in the enum
/// </summary>
[SetUp]
public void Setup_Model()
{
modelList = ScriptableObject.CreateInstance<ModelList>();
// Add a Model 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(ModelIndex).GetFields())
{
if (field.IsLiteral)
{
ModelIndex value = (ModelIndex)field.GetValue(null);
string name = field.Name;
ModelTuple model = new ModelTuple();
// This is all we will need to distinguish
model.index = value;
// Insert in front to guarantee that ModelIndex will not line up with listIndex
modelList.models.Insert(0, model);
}
}
}
/// <summary>
/// Check if getModelByIndex returns the NMModel or return null if there is no model
/// </summary>
[Test]
public void TestGetModelByIndex()
{
foreach (var field in typeof(ModelIndex).GetFields())
{
if (field.IsLiteral)
{
ModelIndex value = (ModelIndex)field.GetValue(null);
string name = field.Name;
Assert.IsTrue(modelList.GetModelByIndex(value) is NNModel || modelList.GetModelByIndex(value) is null);
}
}
}
/// <summary>
/// Check if all courses can be correctly set as current via SetCurrentCourse
/// </summary>
[Test]
public void TestSetCurrentModel()
{
foreach (var field in typeof(ModelIndex).GetFields())
{
if (field.IsLiteral)
{
ModelIndex value = (ModelIndex)field.GetValue(null);
string name = field.Name;
modelList.SetCurrentModel(value);
// Fetch the current course and check if its name is the same as the one we made into the current one
ModelTuple m = modelList.models[modelList.currentModelIndex];
Assert.AreEqual(m.index, value);
}
}
}
}