Resolve WES-127-Refactor_Themelist
This commit is contained in:
committed by
Jelle De Geest
parent
564ec209c7
commit
ea13788199
@@ -5,7 +5,9 @@
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"CommonScripts",
|
||||
"InterfacesScripts"
|
||||
"InterfacesScripts",
|
||||
"Unity.Barracuda",
|
||||
"SignPredictor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
80
Assets/Common/Tests/ModelListTest.cs
Normal file
80
Assets/Common/Tests/ModelListTest.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
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;
|
||||
ModelList.ModelTuple model = new ModelList.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 current model can be correctly gotten as current via GetCurrentModel
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetCurrentModel()
|
||||
{
|
||||
System.Random random = new System.Random();
|
||||
ModelIndex value = (ModelIndex)random.Next(modelList.models.Count);
|
||||
modelList.SetCurrentModel(value);
|
||||
|
||||
Assert.AreEqual(modelList.models[modelList.currentModelIndex].model, modelList.GetCurrentModel());
|
||||
|
||||
// Check if empty model fails gracefully (returns null)
|
||||
Assert.IsNull(ScriptableObject.CreateInstance<ModelList>().GetCurrentModel());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if all models can be correctly set as current via SetCurrentModel
|
||||
/// </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 model and check if its name is the same as the one we made into the current one
|
||||
ModelList.ModelTuple m = modelList.models[modelList.currentModelIndex];
|
||||
|
||||
Assert.AreEqual(m.index, value);
|
||||
Assert.IsTrue(m.model is NNModel || m.model is null);
|
||||
}
|
||||
}
|
||||
ModelList emptyList = ScriptableObject.CreateInstance<ModelList>();
|
||||
emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING);
|
||||
|
||||
Assert.IsTrue(emptyList.currentModelIndex == -1);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/ModelListTest.cs.meta
Normal file
11
Assets/Common/Tests/ModelListTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1313e0cc80244354eb6e2d0c1e891941
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user