From 001cf6dedbf7f28e0f09ba169fa103d250bbf5c7 Mon Sep 17 00:00:00 2001 From: Jerome Coudron Date: Sat, 25 Mar 2023 13:12:55 +0000 Subject: [PATCH] Resolve Common-Interfaces-Tests --- Assets/Common/Tests/BasicTest.cs | 25 ------ Assets/Common/Tests/CommonTests.asmdef | 3 +- Assets/Common/Tests/CourseListTest.cs | 80 +++++++++++++++++++ ...sicTest.cs.meta => CourseListTest.cs.meta} | 2 +- Assets/Common/Tests/MinigameListTest.cs | 80 +++++++++++++++++++ Assets/Common/Tests/MinigameListTest.cs.meta | 11 +++ Assets/Common/Tests/ThemeListTest.cs | 60 ++++++++++++++ Assets/Common/Tests/ThemeListTest.cs.meta | 11 +++ Assets/Common/Tests/ThemeTest.cs | 40 ++++++++++ Assets/Common/Tests/ThemeTest.cs.meta | 11 +++ 10 files changed, 296 insertions(+), 27 deletions(-) delete mode 100644 Assets/Common/Tests/BasicTest.cs create mode 100644 Assets/Common/Tests/CourseListTest.cs rename Assets/Common/Tests/{BasicTest.cs.meta => CourseListTest.cs.meta} (83%) create mode 100644 Assets/Common/Tests/MinigameListTest.cs create mode 100644 Assets/Common/Tests/MinigameListTest.cs.meta create mode 100644 Assets/Common/Tests/ThemeListTest.cs create mode 100644 Assets/Common/Tests/ThemeListTest.cs.meta create mode 100644 Assets/Common/Tests/ThemeTest.cs create mode 100644 Assets/Common/Tests/ThemeTest.cs.meta diff --git a/Assets/Common/Tests/BasicTest.cs b/Assets/Common/Tests/BasicTest.cs deleted file mode 100644 index 7da4cc0..0000000 --- a/Assets/Common/Tests/BasicTest.cs +++ /dev/null @@ -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; - } -} diff --git a/Assets/Common/Tests/CommonTests.asmdef b/Assets/Common/Tests/CommonTests.asmdef index b9a20ed..aaa7ab0 100644 --- a/Assets/Common/Tests/CommonTests.asmdef +++ b/Assets/Common/Tests/CommonTests.asmdef @@ -4,7 +4,8 @@ "references": [ "UnityEngine.TestRunner", "UnityEditor.TestRunner", - "CommonScripts" + "CommonScripts", + "InterfacesScripts" ], "includePlatforms": [ "Editor" diff --git a/Assets/Common/Tests/CourseListTest.cs b/Assets/Common/Tests/CourseListTest.cs new file mode 100644 index 0000000..db511b5 --- /dev/null +++ b/Assets/Common/Tests/CourseListTest.cs @@ -0,0 +1,80 @@ +using NUnit.Framework; +using UnityEngine; + +/// +/// Test the CourseList class +/// +[TestFixture] +public class CourseListTest +{ + private CourseList courseList; + + /// + /// Setup a CourseList with all possible courses in the enum + /// + [SetUp] + public void Setup_Minigame() + { + courseList = ScriptableObject.CreateInstance(); + + // 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(); + // 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); + } + } + } + + /// + /// Check if all courses can be correctly fetched via GetCourseByIndex + /// + [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); + } + } + } + + /// + /// Check if all courses can be correctly set as current via SetCurrentCourse + /// + [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); + } + } + } +} diff --git a/Assets/Common/Tests/BasicTest.cs.meta b/Assets/Common/Tests/CourseListTest.cs.meta similarity index 83% rename from Assets/Common/Tests/BasicTest.cs.meta rename to Assets/Common/Tests/CourseListTest.cs.meta index 597574e..fd4ee32 100644 --- a/Assets/Common/Tests/BasicTest.cs.meta +++ b/Assets/Common/Tests/CourseListTest.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 298e34c71d9e68260a1e06d1d4e94be1 +guid: 1c340877c5585b545805be35e071e2fd MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Common/Tests/MinigameListTest.cs b/Assets/Common/Tests/MinigameListTest.cs new file mode 100644 index 0000000..8dfa673 --- /dev/null +++ b/Assets/Common/Tests/MinigameListTest.cs @@ -0,0 +1,80 @@ +using NUnit.Framework; +using UnityEngine; + +/// +/// Test the MinigameList class +/// +[TestFixture] +public class MinigameListTest +{ + private MinigameList minigameList; + + /// + /// Setup a minigameList with all possible minigames in the enum + /// + [SetUp] + public void Setup_Minigame() + { + minigameList = ScriptableObject.CreateInstance(); + + // 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(); + // 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); + } + } + } + + /// + /// Check if all minigames can be correctly fetched via GetMinigameByIndex + /// + [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); + } + } + } + + /// + /// Check if all minigames can be correctly set as current via SetCurrentMinigame + /// + [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); + } + } + } +} diff --git a/Assets/Common/Tests/MinigameListTest.cs.meta b/Assets/Common/Tests/MinigameListTest.cs.meta new file mode 100644 index 0000000..1f61fe0 --- /dev/null +++ b/Assets/Common/Tests/MinigameListTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ee6e0c438a9ea5a44abcb8adb89c6e9b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Common/Tests/ThemeListTest.cs b/Assets/Common/Tests/ThemeListTest.cs new file mode 100644 index 0000000..f316212 --- /dev/null +++ b/Assets/Common/Tests/ThemeListTest.cs @@ -0,0 +1,60 @@ +using NUnit.Framework; +using UnityEngine; +/// +/// Test the ThemeList class +/// +[TestFixture] +public class ThemeListTest +{ + private ThemeList themeList; + + /// + /// Setup a ThemeList with all possible themes in the enum + /// + [SetUp] + public void Setup_Minigame() + { + themeList = ScriptableObject.CreateInstance(); + + // 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(); + // 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); + } + } + } + + /// + /// Check if all themes can be correctly set as current via SetCurrentTheme + /// + [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); + } + } + } +} diff --git a/Assets/Common/Tests/ThemeListTest.cs.meta b/Assets/Common/Tests/ThemeListTest.cs.meta new file mode 100644 index 0000000..18b947b --- /dev/null +++ b/Assets/Common/Tests/ThemeListTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d1fb3d0097b3794eb1cbbe7a4577e1d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Common/Tests/ThemeTest.cs b/Assets/Common/Tests/ThemeTest.cs new file mode 100644 index 0000000..e6db61f --- /dev/null +++ b/Assets/Common/Tests/ThemeTest.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; +using System.Collections.Generic; +using UnityEngine; +/// +/// Test the Theme class +/// +[TestFixture] +public class ThemeTest +{ + private Theme theme; + private List names = new List() { "appel", "peer", "banaan" }; + /// + /// Setup a theme with some learnables in it + /// + [SetUp] + public void Setup() + { + theme = ScriptableObject.CreateInstance(); + foreach (string name in names) + { + Learnable learnable = new Learnable(); + learnable.name = name; + theme.learnables.Add(learnable); + } + } + /// + /// Test if all the learnables are stored in the theme + /// + [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); + } +} diff --git a/Assets/Common/Tests/ThemeTest.cs.meta b/Assets/Common/Tests/ThemeTest.cs.meta new file mode 100644 index 0000000..3d4fbcf --- /dev/null +++ b/Assets/Common/Tests/ThemeTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4a5f73ff286a8624eb185a9d7a08cd1a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: