diff --git a/Assets/SpellingBee/PlayModeTests.meta b/Assets/SpellingBee/PlayModeTests.meta new file mode 100644 index 0000000..3834c70 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2fd5cdf8e7f70bf4882b352aaaa8a2bf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs b/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs new file mode 100644 index 0000000..b115206 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs @@ -0,0 +1,78 @@ +using System.Collections; +using System.Linq; +using System.IO; + +using NUnit.Framework; +using TMPro; +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.SceneManagement; + + +public class GameControllerTests +{ + + [UnitySetUp] + public IEnumerator SetupFunction() + { + string path = $"{Application.persistentDataPath}/unit_test_users.json"; + var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}"; + + using (StreamWriter writer = new StreamWriter(path)) + { + writer.Write(oneUser); + } + + SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/Game"); + yield return new WaitForSeconds(0.2f); + } + + [UnityTest] + public IEnumerator CheckScoreTest() + { + GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController)); + yield return new WaitForSeconds(0.2f); + Assert.AreEqual(0, gameController.CalculateScore()); + gameController.NextWord(); + Assert.AreEqual(5, gameController.CalculateScore()); + gameController.NextLetter(true); + Assert.AreEqual(6, gameController.CalculateScore()); + } + + [UnityTest] + public IEnumerator ActivateGameOverTest() + { + GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController)); + gameController.ActivateGameOver(); + + yield return new WaitForSeconds(0.2f); + GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel)); + Assert.NotNull(gameEndedPanel); + Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text); + + } + + [UnityTest] + public IEnumerator ActivateWinTests() + { + GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController)); + gameController.ActivateWin(); + + yield return new WaitForSeconds(0.2f); + GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel)); + Assert.NotNull(gameEndedPanel); + Assert.AreEqual("GEWONNEN", gameEndedPanel.endText.text); + } + + [UnityTest] + public IEnumerator CheckGameOverTest() + { + GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController)); + gameController.AddSeconds(-60); + + yield return new WaitForSeconds(0.1f); + GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel)); + Assert.NotNull(gameEndedPanel); + Assert.AreEqual("VERLOREN", gameEndedPanel.endText.text); + } +} diff --git a/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs.meta b/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs.meta new file mode 100644 index 0000000..60a0a9f --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/GameControllerTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b8e6983596a4a49488dc71c4980b53c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs b/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs new file mode 100644 index 0000000..0f9a041 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs @@ -0,0 +1,52 @@ +using System.Collections; +using System.Linq; +using System.IO; + +using NUnit.Framework; +using TMPro; +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.SceneManagement; + + +public class GameEndedPanelTests +{ + + [UnitySetUp] + public IEnumerator SetupFunction() + { + string path = $"{Application.persistentDataPath}/unit_test_users.json"; + var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}"; + + using (StreamWriter writer = new StreamWriter(path)) + { + writer.Write(oneUser); + } + + SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/Game"); + yield return new WaitForSeconds(0.2f); + } + + [UnityTest] + public IEnumerator ScoreTest() + { + GameController gameController = (GameController)GameObject.FindObjectOfType(typeof(GameController)); + gameController.NextWord(); + gameController.NextLetter(false); + gameController.NextLetter(true); + gameController.NextLetter(false); + yield return new WaitForSeconds(1f); + + + gameController.ActivateWin(); + + GameEndedPanel gameEndedPanel = (GameEndedPanel)GameObject.FindObjectOfType(typeof(GameEndedPanel)); + Assert.NotNull(gameEndedPanel); + Assert.AreEqual("Score: 6", gameEndedPanel.scoreText.text); + Assert.AreEqual("1", gameEndedPanel.lettersRightText.text); + Assert.AreEqual("2", gameEndedPanel.lettersWrongText.text); + Assert.AreEqual("3", gameEndedPanel.lettersTotalText.text); + Assert.AreEqual("00:01", gameEndedPanel.timeText.text); + + } +} diff --git a/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs.meta b/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs.meta new file mode 100644 index 0000000..cdad8f1 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8161cc9db422724cbfe7634320ecad4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef b/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef new file mode 100644 index 0000000..a332ab7 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef @@ -0,0 +1,25 @@ +{ + "name": "SpellingBeePlayModeTests", + "rootNamespace": "", + "references": [ + "UnityEngine.TestRunner", + "UnityEditor.TestRunner", + "InterfacesScripts", + "Unity.TextMeshPro", + "SpellingBeeScripts", + "AccountsScripts" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef.meta b/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef.meta new file mode 100644 index 0000000..43a8731 --- /dev/null +++ b/Assets/SpellingBee/PlayModeTests/SpellingBeePlayModeTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8024acb9574451c40ba558529a3ef51c +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SpellingBee/Scripts/GameController.cs b/Assets/SpellingBee/Scripts/GameController.cs index 4ad3d3e..651a58b 100644 --- a/Assets/SpellingBee/Scripts/GameController.cs +++ b/Assets/SpellingBee/Scripts/GameController.cs @@ -241,7 +241,7 @@ public partial class GameController : MonoBehaviour /// /// Randomly shuffle the list of words /// - private void ShuffleWords() + public void ShuffleWords() { for (int i = words.Count - 1; i > 0; i--) { @@ -257,7 +257,7 @@ public partial class GameController : MonoBehaviour /// Calculate the score /// /// The calculated score - private int CalculateScore() + public int CalculateScore() { return spelledWords * 5 + correctLetters; } @@ -265,7 +265,7 @@ public partial class GameController : MonoBehaviour /// /// Displays the game over panel and score values /// - private void ActivateGameOver() + public void ActivateGameOver() { gameEnded = true; DeleteWord(); @@ -287,7 +287,7 @@ public partial class GameController : MonoBehaviour /// /// Display win screen /// - private void ActivateWin() + public void ActivateWin() { gameEnded = true; DeleteWord(); @@ -309,7 +309,7 @@ public partial class GameController : MonoBehaviour /// /// Update and save the scores /// - private void SaveScores() + public void SaveScores() { // Calculate new score int newScore = CalculateScore(); @@ -344,7 +344,7 @@ public partial class GameController : MonoBehaviour /// /// Delete all letter objects /// - private void DeleteWord() + public void DeleteWord() { for (int i = 0; i < letters.Count; i++) { @@ -357,7 +357,7 @@ public partial class GameController : MonoBehaviour /// Adds seconds to timer /// /// - private void AddSeconds(int seconds) + public void AddSeconds(int seconds) { timerValue += (float)seconds; bonusTimeText.SetActive(true); @@ -368,7 +368,7 @@ public partial class GameController : MonoBehaviour /// Display the next letter /// /// true if the letter was correctly signed, false otherwise - private void NextLetter(bool successful) + public void NextLetter(bool successful) { // Change color of current letter (skip spaces) if (successful) @@ -402,7 +402,7 @@ public partial class GameController : MonoBehaviour /// /// Display next word in the series /// - private void NextWord() + public void NextWord() { DeleteWord(); spelledWords++; @@ -425,7 +425,7 @@ public partial class GameController : MonoBehaviour /// Displays the word that needs to be spelled /// /// The word to display - private void DisplayWord(string word) + public void DisplayWord(string word) { for (int i = 0; i < word.Length; i++) {