Merge branch 'Common-Interfaces-Tests' into 'development'

Resolve Common-Interfaces-Tests

See merge request wesign/unity-application!63
This commit was merged in pull request #63.
This commit is contained in:
Jerome Coudron
2023-03-25 13:12:56 +00:00
10 changed files with 296 additions and 27 deletions

View File

@@ -1,25 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class BasicTests
{
// A Test behaves as an ordinary method
[Test]
public void BasicTestsSimplePasses()
{
// Use the Assert class to test conditions
}
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame.
[UnityTest]
public IEnumerator BasicTestsWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// Use yield to skip a frame.
yield return null;
}
}

View File

@@ -4,7 +4,8 @@
"references": [ "references": [
"UnityEngine.TestRunner", "UnityEngine.TestRunner",
"UnityEditor.TestRunner", "UnityEditor.TestRunner",
"CommonScripts" "CommonScripts",
"InterfacesScripts"
], ],
"includePlatforms": [ "includePlatforms": [
"Editor" "Editor"

View File

@@ -0,0 +1,80 @@
using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the CourseList class
/// </summary>
[TestFixture]
public class CourseListTest
{
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);
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 298e34c71d9e68260a1e06d1d4e94be1 guid: 1c340877c5585b545805be35e071e2fd
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,80 @@
using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the MinigameList class
/// </summary>
[TestFixture]
public class MinigameListTest
{
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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee6e0c438a9ea5a44abcb8adb89c6e9b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using NUnit.Framework;
using UnityEngine;
/// <summary>
/// Test the ThemeList class
/// </summary>
[TestFixture]
public class ThemeListTest
{
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.index = 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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d1fb3d0097b3794eb1cbbe7a4577e1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using NUnit.Framework;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Test the Theme class
/// </summary>
[TestFixture]
public class ThemeTest
{
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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a5f73ff286a8624eb185a9d7a08cd1a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: