Added test-code and moved scripts to correct folders
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
"name": "InterfacesScripts",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:5c2b5ba89f9e74e418232e154bc5cc7a",
|
||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725"
|
||||
"GUID:5c2b5ba89f9e74e418232e154bc5cc7a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
9
Assets/Common/Interfaces/ModelIndex.cs
Normal file
9
Assets/Common/Interfaces/ModelIndex.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum ModelIndex
|
||||
{
|
||||
FINGERSPELLING,
|
||||
NONE
|
||||
}
|
||||
11
Assets/Common/Interfaces/ModelIndex.cs.meta
Normal file
11
Assets/Common/Interfaces/ModelIndex.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dbd5e1100bc81648b52206df369d0a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Common/Interfaces/ModelList.cs
Normal file
39
Assets/Common/Interfaces/ModelList.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Unity.Barracuda;
|
||||
/// <summary>
|
||||
/// This scriptable will hold tupples of Courseindices and models
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/ModelList")]
|
||||
public class ModelList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Index of the currently active model
|
||||
/// </summary>
|
||||
public int currentModelIndex = 0;
|
||||
|
||||
/// <summary>
|
||||
/// A list of all the models
|
||||
/// </summary>
|
||||
public List<ModelTuple> models = new List<ModelTuple>();
|
||||
|
||||
/// <summary>
|
||||
/// Get a model by modelindex
|
||||
/// </summary>
|
||||
/// <param name="modelIndex">ModelIndex of the model</param>
|
||||
/// <returns>Model associated with this index, null if no model was found</returns>
|
||||
public NNModel GetModelByIndex(ModelIndex modelIndex)
|
||||
{
|
||||
return models.Find((m) => m.index == modelIndex).model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function to find a model-index in the list based on its index
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void SetCurrentModel(ModelIndex index)
|
||||
{
|
||||
currentModelIndex = models.FindIndex((m) => m.index == index);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Interfaces/ModelList.cs.meta
Normal file
11
Assets/Common/Interfaces/ModelList.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a3f61c93a08c04496c49ffd10b9021
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Common/Interfaces/ModelTuple.cs
Normal file
18
Assets/Common/Interfaces/ModelTuple.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Barracuda;
|
||||
/// <summary>
|
||||
/// Small class to link a model to a courseIndex irrespective of its position in a list
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ModelTuple
|
||||
{
|
||||
/// <summary>
|
||||
/// ModelIndex to which the model corresponds
|
||||
/// </summary>
|
||||
public ModelIndex index;
|
||||
/// <summary>
|
||||
/// The model itself
|
||||
/// </summary>
|
||||
public NNModel model;
|
||||
}
|
||||
11
Assets/Common/Interfaces/ModelTuple.cs.meta
Normal file
11
Assets/Common/Interfaces/ModelTuple.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bce8507dcb30db447b69708ad4f5f962
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Barracuda;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"CommonScripts",
|
||||
"InterfacesScripts"
|
||||
"InterfacesScripts",
|
||||
"Unity.Barracuda",
|
||||
"SignPredictor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
77
Assets/Common/Tests/ModelListTest.cs
Normal file
77
Assets/Common/Tests/ModelListTest.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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