From c24fe037f6710c7d2371e98ca248ca3fa33e2b3f Mon Sep 17 00:00:00 2001 From: Jerome Coudron Date: Sat, 6 May 2023 11:36:51 +0000 Subject: [PATCH] Resolve WES-187-unit-tests-hangman-and-minigame --- .gitignore | 1 + .../EditMode/UserAvatarListTests.cs.meta | 2 +- .../PlayMode/ArchitecturePlayMode.asmdef | 4 +- Assets/Hangman/Scripts/HangmanController.cs | 95 +++-- .../Hangman/Scripts/HangmanGameEndedPanel.cs | 9 +- .../Tests/PlayMode/HangmanPlayMode.asmdef | 9 +- .../Tests/PlayMode/HangmanPlaymodeTests.cs | 373 ++++++++++++++++++ .../PlayMode/HangmanPlaymodeTests.cs.meta | 11 + .../MediaPipeUnity/Scripts/SignPredictor.cs | 1 - Assets/NMLBuildCache.meta | 8 + Assets/NMLBuildCache/NatMLHub.asset | 20 + Assets/NMLBuildCache/NatMLHub.asset.meta | 8 + .../Tests/PlayMode/GameEndedPanelTests.cs | 7 + .../PlayMode/SpellingBeeControllerTests.cs | 7 + .../Tests/PlayMode/SpellingBeePlayMode.asmdef | 1 + .../Settings.json | 2 +- 16 files changed, 511 insertions(+), 47 deletions(-) create mode 100644 Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs create mode 100644 Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta create mode 100644 Assets/NMLBuildCache.meta create mode 100644 Assets/NMLBuildCache/NatMLHub.asset create mode 100644 Assets/NMLBuildCache/NatMLHub.asset.meta diff --git a/.gitignore b/.gitignore index 3532347..dde1162 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /[Bb]uilds/ /[Ll]ogs/ /[Uu]ser[Ss]ettings/ +/[Cc]ode[Cc]overage/ # MemoryCaptures can get excessive in size. # They also could contain extremely sensitive data diff --git a/Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs.meta b/Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs.meta index 64f3dd3..6ce355a 100644 --- a/Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs.meta +++ b/Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6c26e155ab597954a8c65fafe61a8e22 +guid: af1cab5bd60427144a07155705d63dd9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Architecture/Tests/PlayMode/ArchitecturePlayMode.asmdef b/Assets/Architecture/Tests/PlayMode/ArchitecturePlayMode.asmdef index 53991f0..c0d9a71 100644 --- a/Assets/Architecture/Tests/PlayMode/ArchitecturePlayMode.asmdef +++ b/Assets/Architecture/Tests/PlayMode/ArchitecturePlayMode.asmdef @@ -4,8 +4,8 @@ "references": [ "UnityEditor.TestRunner", "UnityEngine.TestRunner", - "ArchitectureScripts", - "AccountsScripts" + "AccountsScripts", + "ArchitectureScripts" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Hangman/Scripts/HangmanController.cs b/Assets/Hangman/Scripts/HangmanController.cs index f65b0ca..7ed0934 100644 --- a/Assets/Hangman/Scripts/HangmanController.cs +++ b/Assets/Hangman/Scripts/HangmanController.cs @@ -28,7 +28,7 @@ public class HangmanController : AbstractMinigameController /// /// This integer holds the total amount of wrong guesses the player has made /// - private int wrongs; + protected int wrongs; /// /// This integer holds the amount of correct letters of the word that the user has guessed @@ -189,17 +189,17 @@ public class HangmanController : AbstractMinigameController /// /// Score obtained when guessing a correct letter /// - private int correctLetterScore = 10; + public const int CORRECT_LETTER_SCORE = 10; /// /// Score obtained when guessing an incorrect letter /// - private int incorrectLetterScore = -5; + public const int INCORRECT_LETTER_SCORE = -5; /// /// Score obtained when guessing the entire word /// - private int winScore = 25; + public const int WIN_SCORE = 25; /// /// Set the AbstractMinigameController variable to inform it of the theme for the signPredictor @@ -296,7 +296,6 @@ public class HangmanController : AbstractMinigameController /// public void SinglePlayer() { - // This word is used for testing before dynamic word-fetching is added PickRandomWord(); StartGame(); } @@ -304,7 +303,7 @@ public class HangmanController : AbstractMinigameController /// /// Randomly select a word from a randomly selected theme, use this word for the hangman game for singleplayer. /// - private void PickRandomWord() + public void PickRandomWord() { // Get a random index for the themes // Then get a random index for a word to pull @@ -336,7 +335,6 @@ public class HangmanController : AbstractMinigameController StartGame(); } } - /// /// Update is called once per frame /// @@ -346,13 +344,7 @@ public class HangmanController : AbstractMinigameController { if (Input.GetKey(KeyCode.Backspace)) { - // Remove the last letter from the currentword - if (0 < currentWord.Length) - { - currentWord = currentWord[0..^1]; - inputTextField.text = currentWord; - } - Input.ResetInputAxes(); + BackSpacePressed(); } gotoGameButton.SetActive(MIN_INC_WORD_LENGHT <= currentWord.Length); @@ -379,7 +371,19 @@ public class HangmanController : AbstractMinigameController }); } } - + /// + /// Functionality to be called when the backspace-key is pressed during input-mode + /// + public void BackSpacePressed() + { + // Remove the last letter from the currentword + if (0 < currentWord.Length) + { + currentWord = currentWord[0..^1]; + inputTextField.text = currentWord; + } + Input.ResetInputAxes(); + } /// /// Handles sign logic, so that it does not have to run every frame /// This function is called when the UpdateFeedback has accepted a letter @@ -413,7 +417,10 @@ public class HangmanController : AbstractMinigameController break; } } - + /// + /// Takes the currentSign and tries to enter it into the word if playing + /// When in input-mode it will just add the letter to the currentWord + /// public void ConfirmAccept() { string letter = currentSign; @@ -462,7 +469,9 @@ public class HangmanController : AbstractMinigameController SwitchMode(1); } } - + /// + /// The letter got rejected, start the letter-fetching process again + /// public void ConfirmDeny() { confirmPanel.SetActive(false); @@ -473,7 +482,10 @@ public class HangmanController : AbstractMinigameController else if (mode == 4) SwitchMode(1); } - + /// + /// Outside function to switch the modes this allows the gameIsactive-logic to be properly attached to the modes + /// + /// public void SwitchMode(int mode) { this.mode = mode; @@ -487,7 +499,6 @@ public class HangmanController : AbstractMinigameController gameIsActive = false; } } - /// /// Change the image that is being displayed /// @@ -501,10 +512,9 @@ public class HangmanController : AbstractMinigameController hangmanImage.sprite = sprite; scoreDisplay.text = $"Score: {CalculateScore()}"; - scoreBonus.text = $"{incorrectLetterScore}"; + scoreBonus.text = $"{INCORRECT_LETTER_SCORE}"; scoreBonus.color = new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f); } - /// /// In this function, the letters of the word selected in DisplayWord are updated after a correct guess. /// @@ -512,7 +522,6 @@ public class HangmanController : AbstractMinigameController private void UpdateWord(string c) { int hits = 0; - for (int i = 0; i < currentWord.Length; i++) { if (currentWord[i] == c[0]) @@ -530,10 +539,9 @@ public class HangmanController : AbstractMinigameController } scoreDisplay.text = $"Score: {CalculateScore()}"; - scoreBonus.text = $"+{hits * correctLetterScore}"; + scoreBonus.text = $"+{hits * CORRECT_LETTER_SCORE}"; scoreBonus.color = new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f); } - /// /// This function returns the score that the user currently has /// @@ -541,11 +549,8 @@ public class HangmanController : AbstractMinigameController public override int CalculateScore() { int won = corrects == currentWord.Length ? 1 : 0; - return corrects * correctLetterScore + wrongs * incorrectLetterScore + winScore * won; + return corrects * CORRECT_LETTER_SCORE + wrongs * INCORRECT_LETTER_SCORE + WIN_SCORE * won; } - - // The following functions originate from Spellingbee - /// /// Delete all letter objects /// @@ -557,7 +562,6 @@ public class HangmanController : AbstractMinigameController } letters.Clear(); } - /// /// Displays the word that needs to be spelled /// @@ -577,7 +581,6 @@ public class HangmanController : AbstractMinigameController txt.text = c == ' ' ? "" : Char.ToString('_'); } } - /// /// The logic to process the signs sent by the signPredictor /// @@ -625,7 +628,6 @@ public class HangmanController : AbstractMinigameController feedbackProgressImage.color = red; } } - // The logic for the internal workings of the game if (accuracy > threshold) { @@ -667,7 +669,6 @@ public class HangmanController : AbstractMinigameController timerCircle.fillAmount = currentTime; } } - /// /// The logic to set the scoreboard of hangman /// @@ -692,7 +693,6 @@ public class HangmanController : AbstractMinigameController score: CalculateScore() ); } - /// /// The hangman-specific logic that needs to be called at the start of the game /// @@ -723,4 +723,33 @@ public class HangmanController : AbstractMinigameController DeleteWord(); } + // The following functions are only used for testing + public string getCurrentWord() + { + return currentWord; + } + public int getCurrentMode() + { + return mode; + } + public int getCorrects() + { + return corrects; + } + public int getWrongs() + { + return wrongs; + } + public string getUsedLetters() + { + return usedLettersText.text; + } + public void ProcessSignForTests(float accuracy, string sign) + { + ProcessMostProbableSign(accuracy, sign); + } + public float getCurrentTime() + { + return currentTime; + } } diff --git a/Assets/Hangman/Scripts/HangmanGameEndedPanel.cs b/Assets/Hangman/Scripts/HangmanGameEndedPanel.cs index 4e6eb8f..982556e 100644 --- a/Assets/Hangman/Scripts/HangmanGameEndedPanel.cs +++ b/Assets/Hangman/Scripts/HangmanGameEndedPanel.cs @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; using TMPro; using UnityEngine; using UnityEngine.UI; @@ -73,15 +70,11 @@ public class HangmanGameEndedPanel : AbstractGameEndedPanel lettersWrongText.text = incorrectLetters.ToString(); lettersTotalText.text = (correctLetters + incorrectLetters).ToString(); - // Accuracy + // Accuracy, should always be true if (correctLetters + incorrectLetters > 0) { accuracyText.text = ((correctLetters) * 100f / (correctLetters + incorrectLetters)).ToString("#.##") + "%"; } - else - { - accuracyText.text = "-"; - } // Words wordText.text = guessWord; diff --git a/Assets/Hangman/Tests/PlayMode/HangmanPlayMode.asmdef b/Assets/Hangman/Tests/PlayMode/HangmanPlayMode.asmdef index 99559ed..5ba47e9 100644 --- a/Assets/Hangman/Tests/PlayMode/HangmanPlayMode.asmdef +++ b/Assets/Hangman/Tests/PlayMode/HangmanPlayMode.asmdef @@ -4,7 +4,14 @@ "references": [ "UnityEngine.TestRunner", "UnityEditor.TestRunner", - "HangmanScripts" + "AccountsScripts", + "HangmanScripts", + "SignPredictor", + "MinigameScripts", + "Unity.TextMeshPro", + "CommonScripts", + "InterfacesScripts", + "ArchitectureScripts" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs b/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs new file mode 100644 index 0000000..280e288 --- /dev/null +++ b/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs @@ -0,0 +1,373 @@ +using NUnit.Framework; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor; +using UnityEngine; +using UnityEngine.TestTools; +public class HangmanPlaymodeTests +{ + private HangmanController hangmanController; + + private int multiplayerConfirmInput = 4; + + /// + /// SetupFunction to reach the hangman-game + /// + /// + [UnitySetUp] + public IEnumerator SetupFunction() + { + string path = $"{Application.persistentDataPath}/wesign_unit_test.json"; + string oneUser = $"{{\"version\":1027,\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}"; + + File.WriteAllText(path, oneUser); + PersistentDataController.PATH = path; + PersistentDataController.GetInstance().Load(); + AssetDatabase.LoadAssetAtPath("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake(); + + // Go to the minigame-selection scene to make sure that the minigameIndex is set correctly + SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen"); + yield return new WaitForSeconds(0.2f); + var minigameScreen = GameObject.FindObjectOfType(); + minigameScreen.minigameList.SetCurrentMinigame(MinigameIndex.HANGMAN); + + // Go to the Hangman-game + SystemController.GetInstance().LoadNextScene("Hangman/Scenes/HangmanGame"); + yield return new WaitForSeconds(0.2f); + + // Fetch the hangmanController + hangmanController = GameObject.FindObjectOfType(); + yield return new WaitForSeconds(0.2f); + + // Fetch the SignPredictor and deactivate it, this stops the basic game-loop from happening + var signPredictor = GameObject.FindObjectOfType(); + GameObject signPredictorController = signPredictor.gameObject; + signPredictorController.SetActive(false); + yield return new WaitForSeconds(0.2f); + + // Put some old scores in the scoreboard to test its functionality + // One from one day ago + Score score1 = new Score(); + score1.scoreValue = 50; + score1.time = DateTime.Now.AddDays(-1).ToString(); + + // One from one hour ago + Score score2 = new Score(); + score2.scoreValue = 70; + score2.time = DateTime.Now.AddHours(-1).ToString(); + + // One from 5 minutes ago + Score score3 = new Score(); + score3.scoreValue = 90; + score3.time = DateTime.Now.AddMinutes(-5).ToString(); + + // Save the new score + var progress = UserList.GetCurrentUser().GetMinigameProgress(MinigameIndex.HANGMAN); + + // Get the current list of scores + List latestScores = progress.latestScores; + List highestScores = progress.highestScores; + + // Add the new score + latestScores.Add(score1); + highestScores.Add(score1); + latestScores.Add(score2); + highestScores.Add(score2); + latestScores.Add(score3); + highestScores.Add(score3); + + // Sort the scores + highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue)); + + // Only save the top 10 scores, so this list doesn't keep growing endlessly + progress.latestScores = latestScores.Take(10).ToList(); + progress.highestScores = highestScores.Take(10).ToList(); + + PersistentDataController.GetInstance().Save(); + + } + + /// + /// Tests the singleplayer functionality, only the winning side as losing is easier when the word is chosen beforehand. + /// + /// + [UnityTest] + public IEnumerator SinglePlayerTests() + { + // Start singlePlayer + hangmanController.SinglePlayer(); + + // Assert that a random word was generated and that the game has started + string currentWord = hangmanController.getCurrentWord(); + Assert.IsTrue(currentWord.Length > 0); + Assert.IsTrue(hangmanController.getCurrentMode() == 2); + + Assert.IsFalse(hangmanController.inputPanel.activeSelf); + Assert.IsFalse(hangmanController.playerPanel.activeSelf); + Assert.IsTrue(hangmanController.gamePanel.activeSelf); + Assert.IsFalse(hangmanController.gameEndedPanel.activeSelf); + + // Fetch the panel with the info for the fields and check if the controller has implemented them + var script = GameObject.FindObjectOfType(); + + Assert.IsTrue(hangmanController.inputTextField == script.guessesTextField); + Assert.IsTrue(hangmanController.feedbackText == script.feedbackText); + Assert.IsTrue(hangmanController.feedbackProgress == script.feedbackProgressBar); + Assert.IsTrue(hangmanController.feedbackProgressImage == script.feedbackProgressImage); + Assert.IsTrue(hangmanController.webcamScreen == script.webcamScreen); + Assert.IsTrue(hangmanController.timerCircle == script.timerCircle); + Assert.IsTrue(hangmanController.confirmPanel == script.confirmPanel); + Assert.IsTrue(hangmanController.confirmText == script.confirmText); + + Assert.IsTrue(hangmanController.getCorrects() == 0); + Assert.IsTrue(hangmanController.getWrongs() == 0); + Assert.IsTrue(hangmanController.getUsedLetters().Length == 0); + + // Start guessing the word, start by trying a wrong letter to check if the image changes + string letter = ""; + int localWrongs = 0; + + // Wait to run over the update-functionality + yield return new WaitForSeconds(0.2f); + + // Fetch a letter that isn't in the word + foreach (char let in new List() { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }) + { + if (!currentWord.Contains(let.ToString().ToUpper())) + { + letter = let.ToString().ToUpper(); + break; + } + } + // Input this knowingly-wrong letter + yield return ChooseLetter(letter); + localWrongs++; + // We know the letter is wrong, so check that the wrongs have increased + Assert.IsTrue(hangmanController.getWrongs() == localWrongs); + + // Check all the correct letters + Dictionary correctLetters = new Dictionary(); + foreach (char let in currentWord.ToUpper()) + { + letter = let.ToString(); + if (correctLetters.ContainsKey(letter)) + { + correctLetters[letter] += 1; + } + else + { + correctLetters.Add(letter, 1); + } + } + int localCorrects = 0; + // Now add each of the letters and check if the correct are correctly updated + foreach (string s in correctLetters.Keys) + { + yield return ChooseLetter(s); + + localCorrects += correctLetters[s]; + Assert.IsTrue(hangmanController.getCorrects() == localCorrects); + } + + // The game should be over now, check if the gameEndedPanel is active + Assert.IsTrue(hangmanController.gameEndedPanel.activeSelf); + + // Fetch the gameEndedPanel to check it's values + var gameEndedScript = GameObject.FindObjectOfType(); + Assert.IsTrue(gameEndedScript.endText.text == "GEWONNEN"); + Assert.IsTrue(gameEndedScript.lettersRightText.text == hangmanController.getCorrects().ToString()); + Assert.IsTrue(gameEndedScript.lettersWrongText.text == hangmanController.getWrongs().ToString()); + Assert.IsTrue(gameEndedScript.lettersTotalText.text == (hangmanController.getCorrects() + hangmanController.getWrongs()).ToString()); + + yield return null; + } + + /// + /// Tests the multiplayer-code + /// + /// + [UnityTest] + public IEnumerator MultiPlayerTests() + { + // Go to the input-screen + hangmanController.GoToInput(); + + // We will enter the word "testing" but will type a wrong letter after the 'i' that will be backspaced away + // Afterwards, we can go to the game and assert that the currectWord is indeed "testing" + + // Correct letters + yield return InputLetter("T"); + yield return InputLetter("E"); + yield return InputLetter("S"); + yield return InputLetter("T"); + yield return InputLetter("I"); + + // Wrong letter, will be backspaced away + yield return InputLetter("V"); + + yield return new WaitForSeconds(0.2f); + // We can't simulate a key-press so we will need to settle for just calling its logic + hangmanController.BackSpacePressed(); + + // Wrong letter, but this one will be rejected + while (hangmanController.getCurrentMode() != multiplayerConfirmInput) + { + hangmanController.ProcessSignForTests(1, "Q"); + yield return new WaitForSeconds(0.2f); + } + + hangmanController.ConfirmDeny(); + + // Final correct letters + yield return InputLetter("N"); + yield return InputLetter("G"); + + // We are satisfied with the word, pass it along + hangmanController.TwoPlayer(); + + Assert.IsTrue(hangmanController.getCurrentWord() == "TESTING"); + + // Input 9 wrong letters to lose the game + int localWrongs = 0; + Assert.IsTrue(hangmanController.getWrongs() == localWrongs); + foreach (string s in new List() { "A", "B", "C", "D", "F", "H", "J", "K", "L", "M", "N", "O", "P" }) + { + if (HangmanController.NUMBER_OF_FAILS_BEFORE_GAMEOVER >= localWrongs) + { + yield return ChooseLetter(s); + localWrongs++; + Assert.IsTrue(hangmanController.getWrongs() == localWrongs); + } + } + + // The game should be over now, resulting in a loss + Assert.IsTrue(hangmanController.gameEndedPanel.activeSelf); + + // Fetch the gameEndedPanel to check it's values + var gameEndedScript = GameObject.FindObjectOfType(); + Assert.IsTrue(gameEndedScript.endText.text == "VERLOREN"); + Assert.IsTrue(gameEndedScript.lettersRightText.text == hangmanController.getCorrects().ToString()); + Assert.IsTrue(gameEndedScript.lettersWrongText.text == hangmanController.getWrongs().ToString()); + Assert.IsTrue(gameEndedScript.lettersTotalText.text == (hangmanController.getCorrects() + hangmanController.getWrongs()).ToString()); + + yield return null; + } + + /// + /// Tests some remaning functionality regarding the feedback that isn't contained in the previous tests + /// + /// + [UnityTest] + public IEnumerator SignChangingTest() + { + hangmanController.SinglePlayer(); + + hangmanController.ProcessSignForTests(1, "A"); + yield return new WaitForSeconds(0.2f); + // The sign for A has been held for 0.2f seconds... + Assert.IsTrue(hangmanController.getCurrentTime() >= 0.2f && hangmanController.getCurrentTime() <= 0.3f); + + hangmanController.ProcessSignForTests(1, "B"); + yield return new WaitForSeconds(0.2f); + // The sign changed so the time needs to be at 0.2f again + Assert.IsTrue(hangmanController.getCurrentTime() >= 0.2f && hangmanController.getCurrentTime() <= 0.3f); + + hangmanController.ProcessSignForTests(1 / 10, "B"); + yield return new WaitForSeconds(0.2f); + // The sign changed is below the threshold, time is no longer tracked + Assert.IsTrue(hangmanController.getCurrentTime() == 0.0); + + for (float i = 0; i < 1; i += 0.02f) + { + hangmanController.ProcessSignForTests(i, "C"); + Assert.IsTrue(hangmanController.getCurrentTime() == 0.0); + } + + yield return null; + } + + /// + /// Test the functionality of the scoreboard to display multiple games + /// + /// + [UnityTest] + public IEnumerator ScoreBoardTest() + { + // Quickly play 2 games to test if scoreboard is correctly reset and if entries are correctly added + // Game 1 + hangmanController.GoToInput(); + yield return InputLetter("A"); + yield return InputLetter("A"); + yield return InputLetter("A"); + hangmanController.TwoPlayer(); + Assert.IsTrue(hangmanController.getCurrentWord() == "AAA"); + yield return ChooseLetter("A"); + yield return new WaitForSeconds(1f); + + Assert.IsTrue(hangmanController.gameEndedPanel.activeSelf); + var gameEndedScript = GameObject.FindObjectOfType(); + int firstEntries = gameEndedScript.scoreboardEntriesContainer.childCount; + + hangmanController.StartController(); + + // Game 2 + hangmanController.GoToInput(); + yield return InputLetter("A"); + yield return InputLetter("A"); + yield return InputLetter("A"); + hangmanController.TwoPlayer(); + Assert.IsTrue(hangmanController.getCurrentWord() == "AAA"); + yield return ChooseLetter("A"); + yield return new WaitForSeconds(1f); + Assert.IsTrue(hangmanController.gameEndedPanel.activeSelf); + + int secondEntries = gameEndedScript.scoreboardEntriesContainer.childCount; + + // Check that one entry has been added between the two games or that the scoreboard was already full + Assert.IsTrue(secondEntries == firstEntries + 1 || firstEntries == 10); + + yield return null; + } + + /// + /// Cleanup after testing + /// + [TearDown] + public void TearDown_HangmanTests() + { + PersistentDataController.PATH = null; + } + + /// + /// Private function to input a letter in multiplayer input-mode + /// + /// + /// + private IEnumerator InputLetter(string letter) + { + while (hangmanController.getCurrentMode() != multiplayerConfirmInput) + { + hangmanController.ProcessSignForTests(1, letter); + yield return new WaitForSeconds(0.2f); + } + + hangmanController.ConfirmAccept(); + } + + /// + /// Private function to input a letter in game-mode + /// + /// + /// + private IEnumerator ChooseLetter(string letter) + { + while (!hangmanController.getUsedLetters().Contains(letter)) + { + hangmanController.ProcessSignForTests(1, letter); + yield return new WaitForSeconds(0.2f); + } + } +} \ No newline at end of file diff --git a/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta b/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta new file mode 100644 index 0000000..a69dd18 --- /dev/null +++ b/Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cb27dbfd228c60c4084daf09571d85e8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs index ba4d1ab..2976a66 100644 --- a/Assets/MediaPipeUnity/Scripts/SignPredictor.cs +++ b/Assets/MediaPipeUnity/Scripts/SignPredictor.cs @@ -2,7 +2,6 @@ using Mediapipe; using Mediapipe.Unity; using NatML; using NatML.Features; -using NatML.Internal; using System.Collections; using System.Collections.Generic; using System.Diagnostics; diff --git a/Assets/NMLBuildCache.meta b/Assets/NMLBuildCache.meta new file mode 100644 index 0000000..7654294 --- /dev/null +++ b/Assets/NMLBuildCache.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b0fcd1404d38ac94aace1c5b3564cc04 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NMLBuildCache/NatMLHub.asset b/Assets/NMLBuildCache/NatMLHub.asset new file mode 100644 index 0000000..c2c1314 --- /dev/null +++ b/Assets/NMLBuildCache/NatMLHub.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 63770b348488e4a3983eb57792523f54, type: 3} + m_Name: NatMLHub + m_EditorClassIdentifier: + accessKey: + user: + email: + username: + billing: + plan: diff --git a/Assets/NMLBuildCache/NatMLHub.asset.meta b/Assets/NMLBuildCache/NatMLHub.asset.meta new file mode 100644 index 0000000..7ababa8 --- /dev/null +++ b/Assets/NMLBuildCache/NatMLHub.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 327974eea6e413e418ae0fddd61a0e00 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SpellingBee/Tests/PlayMode/GameEndedPanelTests.cs b/Assets/SpellingBee/Tests/PlayMode/GameEndedPanelTests.cs index 8ec0c00..177b5e0 100644 --- a/Assets/SpellingBee/Tests/PlayMode/GameEndedPanelTests.cs +++ b/Assets/SpellingBee/Tests/PlayMode/GameEndedPanelTests.cs @@ -16,6 +16,13 @@ public class SpellingBeeGameEndedPanelTests File.WriteAllText(path, oneUser); PersistentDataController.GetInstance().Load(); AssetDatabase.LoadAssetAtPath("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake(); + + // Go to the minigame-selection scene to make sure that the minigameIndex is set correctly + SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen"); + yield return new WaitForSeconds(0.2f); + ListMinigamesScreen minigameScreen = (ListMinigamesScreen)GameObject.FindObjectOfType(typeof(ListMinigamesScreen)); + minigameScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE); + SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame"); yield return new WaitForSeconds(0.2f); } diff --git a/Assets/SpellingBee/Tests/PlayMode/SpellingBeeControllerTests.cs b/Assets/SpellingBee/Tests/PlayMode/SpellingBeeControllerTests.cs index a849d3f..fd4120b 100644 --- a/Assets/SpellingBee/Tests/PlayMode/SpellingBeeControllerTests.cs +++ b/Assets/SpellingBee/Tests/PlayMode/SpellingBeeControllerTests.cs @@ -16,6 +16,13 @@ public class SpellingBeeControllerTests File.WriteAllText(path, oneUser); PersistentDataController.GetInstance().Load(); AssetDatabase.LoadAssetAtPath("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake(); + + // Go to the minigame-selection scene to make sure that the minigameIndex is set correctly + SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen"); + yield return new WaitForSeconds(0.2f); + ListMinigamesScreen minigameScreen = (ListMinigamesScreen)GameObject.FindObjectOfType(typeof(ListMinigamesScreen)); + minigameScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE); + SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame"); yield return new WaitForSeconds(0.2f); } diff --git a/Assets/SpellingBee/Tests/PlayMode/SpellingBeePlayMode.asmdef b/Assets/SpellingBee/Tests/PlayMode/SpellingBeePlayMode.asmdef index 73ed5b0..d4c21f1 100644 --- a/Assets/SpellingBee/Tests/PlayMode/SpellingBeePlayMode.asmdef +++ b/Assets/SpellingBee/Tests/PlayMode/SpellingBeePlayMode.asmdef @@ -10,6 +10,7 @@ "AccountsScripts", "SignPredictor", "MinigameScripts", + "CommonScripts", "ArchitectureScripts" ], "includePlatforms": [], diff --git a/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json b/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json index dea77e3..9368c67 100644 --- a/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json +++ b/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json @@ -6,7 +6,7 @@ { "type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "key": "IncludeAssemblies", - "value": "{\"m_Value\":\"AccountsScripts,ArchitectureScripts,CommonScripts,CourseScripts,HangmanScripts,InterfacesScripts,JustSignScripts,MinigameScripts,SignPredictor,SignPredictorInterfaces,SpellingBeeScripts\"}" + "value": "{\"m_Value\":\"AccountsScripts,CommonScripts,CourseScripts,HangmanScripts,InterfacesScripts,JustSignScripts,MinigameScripts,SignPredictor,SignPredictorInterfaces,SpellingBeeScripts\"}" }, { "type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",