Resolve WES-187 "Unit tests account and system"
This commit is contained in:
committed by
Jerome Coudron
parent
c4b6c60288
commit
b9bbef8dcf
28
Assets/Common/Tests/EditMode/CommonEditMode.asmdef
Normal file
28
Assets/Common/Tests/EditMode/CommonEditMode.asmdef
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "CommonEditMode",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"CommonScripts",
|
||||
"InterfacesScripts",
|
||||
"SignPredictor",
|
||||
"NatML.ML",
|
||||
"ArchitectureScripts"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Common/Tests/EditMode/CommonEditMode.asmdef.meta
Normal file
7
Assets/Common/Tests/EditMode/CommonEditMode.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51e9387d41ea4c92e959a2181b19e568
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Common/Tests/EditMode/CourseListTests.cs
Normal file
80
Assets/Common/Tests/EditMode/CourseListTests.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/EditMode/CourseListTests.cs.meta
Normal file
11
Assets/Common/Tests/EditMode/CourseListTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c340877c5585b545805be35e071e2fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Common/Tests/EditMode/MinigameListTests.cs
Normal file
80
Assets/Common/Tests/EditMode/MinigameListTests.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the MinigameList class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class MinigameListTests
|
||||
{
|
||||
private MinigameList minigameList;
|
||||
|
||||
/// <summary>
|
||||
/// Setup a minigameList with all possible minigames in the enum
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup_Minigame()
|
||||
{
|
||||
minigameList = ScriptableObject.CreateInstance<MinigameList>();
|
||||
|
||||
// Add a minigame 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(MinigameIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
MinigameIndex value = (MinigameIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
Minigame m = ScriptableObject.CreateInstance<Minigame>();
|
||||
// This is all we will need to distinguish
|
||||
m.index = value;
|
||||
m.title = name;
|
||||
|
||||
// Insert in front to guarantee that MinigameIndex will not line up with listIndex
|
||||
minigameList.minigames.Insert(0, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if all minigames can be correctly fetched via GetMinigameByIndex
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestGetMinigameByIndex()
|
||||
{
|
||||
foreach (var field in typeof(MinigameIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
MinigameIndex value = (MinigameIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
Minigame m = minigameList.GetMinigameByIndex(value);
|
||||
|
||||
Assert.AreEqual(m.title, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if all minigames can be correctly set as current via SetCurrentMinigame
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetCurrentMinigame()
|
||||
{
|
||||
foreach (var field in typeof(MinigameIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
MinigameIndex value = (MinigameIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
minigameList.SetCurrentMinigame(value);
|
||||
|
||||
// Fetch the current minigame and check if its name is the same as the one we made into the current one
|
||||
Minigame m = minigameList.minigames[minigameList.currentMinigameIndex];
|
||||
|
||||
Assert.AreEqual(m.title, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/EditMode/MinigameListTests.cs.meta
Normal file
11
Assets/Common/Tests/EditMode/MinigameListTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee6e0c438a9ea5a44abcb8adb89c6e9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/Common/Tests/EditMode/ModelListTests.cs
Normal file
88
Assets/Common/Tests/EditMode/ModelListTests.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using NatML;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// Test the ModelList class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ModelListTests
|
||||
{
|
||||
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);
|
||||
|
||||
#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<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);
|
||||
#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<ModelList>();
|
||||
emptyList.SetCurrentModel(ModelIndex.FINGERSPELLING);
|
||||
|
||||
Assert.IsTrue(emptyList.currentModelIndex == -1);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/EditMode/ModelListTests.cs.meta
Normal file
11
Assets/Common/Tests/EditMode/ModelListTests.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:
|
||||
61
Assets/Common/Tests/EditMode/ThemeListTests.cs
Normal file
61
Assets/Common/Tests/EditMode/ThemeListTests.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the ThemeList class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ThemeListTests
|
||||
{
|
||||
private ThemeList themeList;
|
||||
|
||||
/// <summary>
|
||||
/// Setup a ThemeList with all possible themes in the enum
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup_Minigame()
|
||||
{
|
||||
themeList = ScriptableObject.CreateInstance<ThemeList>();
|
||||
|
||||
// Add a theme 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(ThemeIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
ThemeIndex value = (ThemeIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
Theme theme = ScriptableObject.CreateInstance<Theme>();
|
||||
// This is all we will need to distinguish
|
||||
theme.themeIndex = value;
|
||||
theme.title = name;
|
||||
|
||||
// Insert in front to guarantee that themeIndex will not line up with listIndex
|
||||
themeList.themes.Insert(0, theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if all themes can be correctly set as current via SetCurrentTheme
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestSetCurrentMinigame()
|
||||
{
|
||||
foreach (var field in typeof(ThemeIndex).GetFields())
|
||||
{
|
||||
if (field.IsLiteral)
|
||||
{
|
||||
ThemeIndex value = (ThemeIndex)field.GetValue(null);
|
||||
string name = field.Name;
|
||||
themeList.SetCurrentTheme(value);
|
||||
|
||||
// Fetch the current theme and check if its name is the same as the one we made into the current one
|
||||
Theme m = themeList.themes[themeList.currentThemeIndex];
|
||||
|
||||
Assert.AreEqual(m.title, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/EditMode/ThemeListTests.cs.meta
Normal file
11
Assets/Common/Tests/EditMode/ThemeListTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d1fb3d0097b3794eb1cbbe7a4577e1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/Common/Tests/EditMode/ThemeTests.cs
Normal file
41
Assets/Common/Tests/EditMode/ThemeTests.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the Theme class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ThemeTests
|
||||
{
|
||||
private Theme theme;
|
||||
private List<string> names = new List<string>() { "appel", "peer", "banaan" };
|
||||
/// <summary>
|
||||
/// Setup a theme with some learnables in it
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
theme = ScriptableObject.CreateInstance<Theme>();
|
||||
foreach (string name in names)
|
||||
{
|
||||
Learnable learnable = new Learnable();
|
||||
learnable.name = name;
|
||||
theme.learnables.Add(learnable);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Test if all the learnables are stored in the theme
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestThemeLearnables()
|
||||
{
|
||||
// Check if each of the learnables is kept
|
||||
foreach (Learnable learnable in theme.learnables)
|
||||
{
|
||||
names.Remove(learnable.name);
|
||||
}
|
||||
// Assert that all items have been checked
|
||||
Assert.IsTrue(names.Count == 0);
|
||||
}
|
||||
}
|
||||
11
Assets/Common/Tests/EditMode/ThemeTests.cs.meta
Normal file
11
Assets/Common/Tests/EditMode/ThemeTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a5f73ff286a8624eb185a9d7a08cd1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user