using NatML; using NUnit.Framework; using UnityEngine; /// /// Test the ModelList class /// [TestFixture] public class ModelListTest { private ModelList modelList; /// /// Setup a ModelList with all possible Models in the enum /// [SetUp] public void Setup_Model() { modelList = ScriptableObject.CreateInstance(); // 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); } } } /// /// Check if current model can be correctly gotten as current via GetCurrentModel /// [Test] public void TestGetCurrentModel() { System.Random random = new System.Random(); ModelIndex value = (ModelIndex)random.Next(modelList.models.Count); modelList.SetCurrentModel(value); #if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) Assert.AreEqual(modelList.models[modelList.currentModelIndex].modelWINDOWS, modelList.GetCurrentModel()); #elif (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX) Assert.AreEqual(modelList.models[modelList.currentModelIndex].modelMAC, modelList.GetCurrentModel()); #endif // Check if empty model fails gracefully (returns null) Assert.IsNull(ScriptableObject.CreateInstance().GetCurrentModel()); } /// /// Check if all models can be correctly set as current via SetCurrentModel /// [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); #if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) Assert.IsTrue(m.modelWINDOWS is MLModelData || m.modelWINDOWS is null); #elif (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX) Assert.IsTrue(m.modelMAC is MLModelData || m.modelMAC is null); #endif } } ModelList emptyList = ScriptableObject.CreateInstance(); emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING); Assert.IsTrue(emptyList.currentModelIndex == -1); } }