Resolve WES-187-unit-tests-hangman-and-minigame
This commit is contained in:
committed by
Jelle De Geest
parent
b10358930b
commit
c24fe037f6
1
.gitignore
vendored
1
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c26e155ab597954a8c65fafe61a8e22
|
||||
guid: af1cab5bd60427144a07155705d63dd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"references": [
|
||||
"UnityEditor.TestRunner",
|
||||
"UnityEngine.TestRunner",
|
||||
"ArchitectureScripts",
|
||||
"AccountsScripts"
|
||||
"AccountsScripts",
|
||||
"ArchitectureScripts"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -28,7 +28,7 @@ public class HangmanController : AbstractMinigameController
|
||||
/// <summary>
|
||||
/// This integer holds the total amount of wrong guesses the player has made
|
||||
/// </summary>
|
||||
private int wrongs;
|
||||
protected int wrongs;
|
||||
|
||||
/// <summary>
|
||||
/// This integer holds the amount of correct letters of the word that the user has guessed
|
||||
@@ -189,17 +189,17 @@ public class HangmanController : AbstractMinigameController
|
||||
/// <summary>
|
||||
/// Score obtained when guessing a correct letter
|
||||
/// </summary>
|
||||
private int correctLetterScore = 10;
|
||||
public const int CORRECT_LETTER_SCORE = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when guessing an incorrect letter
|
||||
/// </summary>
|
||||
private int incorrectLetterScore = -5;
|
||||
public const int INCORRECT_LETTER_SCORE = -5;
|
||||
|
||||
/// <summary>
|
||||
/// Score obtained when guessing the entire word
|
||||
/// </summary>
|
||||
private int winScore = 25;
|
||||
public const int WIN_SCORE = 25;
|
||||
|
||||
/// <summary>
|
||||
/// Set the AbstractMinigameController variable to inform it of the theme for the signPredictor
|
||||
@@ -296,7 +296,6 @@ public class HangmanController : AbstractMinigameController
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Randomly select a word from a randomly selected theme, use this word for the hangman game for singleplayer.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update is called once per frame
|
||||
/// </summary>
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Functionality to be called when the backspace-key is pressed during input-mode
|
||||
/// </summary>
|
||||
public void BackSpacePressed()
|
||||
{
|
||||
// Remove the last letter from the currentword
|
||||
if (0 < currentWord.Length)
|
||||
{
|
||||
currentWord = currentWord[0..^1];
|
||||
inputTextField.text = currentWord;
|
||||
}
|
||||
Input.ResetInputAxes();
|
||||
}
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
public void ConfirmAccept()
|
||||
{
|
||||
string letter = currentSign;
|
||||
@@ -462,7 +469,9 @@ public class HangmanController : AbstractMinigameController
|
||||
SwitchMode(1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The letter got rejected, start the letter-fetching process again
|
||||
/// </summary>
|
||||
public void ConfirmDeny()
|
||||
{
|
||||
confirmPanel.SetActive(false);
|
||||
@@ -473,7 +482,10 @@ public class HangmanController : AbstractMinigameController
|
||||
else if (mode == 4)
|
||||
SwitchMode(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Outside function to switch the modes this allows the gameIsactive-logic to be properly attached to the modes
|
||||
/// </summary>
|
||||
/// <param name="mode"></param>
|
||||
public void SwitchMode(int mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
@@ -487,7 +499,6 @@ public class HangmanController : AbstractMinigameController
|
||||
gameIsActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change the image that is being displayed
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In this function, the letters of the word selected in DisplayWord are updated after a correct guess.
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function returns the score that the user currently has
|
||||
/// </summary>
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Delete all letter objects
|
||||
/// </summary>
|
||||
@@ -557,7 +562,6 @@ public class HangmanController : AbstractMinigameController
|
||||
}
|
||||
letters.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the word that needs to be spelled
|
||||
/// </summary>
|
||||
@@ -577,7 +581,6 @@ public class HangmanController : AbstractMinigameController
|
||||
txt.text = c == ' ' ? "" : Char.ToString('_');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logic to process the signs sent by the signPredictor
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logic to set the scoreboard of hangman
|
||||
/// </summary>
|
||||
@@ -692,7 +693,6 @@ public class HangmanController : AbstractMinigameController
|
||||
score: CalculateScore()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The hangman-specific logic that needs to be called at the start of the game
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,7 +4,14 @@
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"HangmanScripts"
|
||||
"AccountsScripts",
|
||||
"HangmanScripts",
|
||||
"SignPredictor",
|
||||
"MinigameScripts",
|
||||
"Unity.TextMeshPro",
|
||||
"CommonScripts",
|
||||
"InterfacesScripts",
|
||||
"ArchitectureScripts"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
373
Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs
Normal file
373
Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs
Normal file
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// SetupFunction to reach the hangman-game
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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<UserAvatarList>("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<ListMinigamesScreen>();
|
||||
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<HangmanController>();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
// Fetch the SignPredictor and deactivate it, this stops the basic game-loop from happening
|
||||
var signPredictor = GameObject.FindObjectOfType<SignPredictor>();
|
||||
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<Score> latestScores = progress.latestScores;
|
||||
List<Score> 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();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the singleplayer functionality, only the winning side as losing is easier when the word is chosen beforehand.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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<PanelHangmanGame>();
|
||||
|
||||
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<char>() { '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<string, int> correctLetters = new Dictionary<string, int>();
|
||||
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<HangmanGameEndedPanel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the multiplayer-code
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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<string>() { "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<HangmanGameEndedPanel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests some remaning functionality regarding the feedback that isn't contained in the previous tests
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test the functionality of the scoreboard to display multiple games
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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<HangmanGameEndedPanel>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup after testing
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public void TearDown_HangmanTests()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private function to input a letter in multiplayer input-mode
|
||||
/// </summary>
|
||||
/// <param name="letter"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerator InputLetter(string letter)
|
||||
{
|
||||
while (hangmanController.getCurrentMode() != multiplayerConfirmInput)
|
||||
{
|
||||
hangmanController.ProcessSignForTests(1, letter);
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
hangmanController.ConfirmAccept();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private function to input a letter in game-mode
|
||||
/// </summary>
|
||||
/// <param name="letter"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerator ChooseLetter(string letter)
|
||||
{
|
||||
while (!hangmanController.getUsedLetters().Contains(letter))
|
||||
{
|
||||
hangmanController.ProcessSignForTests(1, letter);
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta
Normal file
11
Assets/Hangman/Tests/PlayMode/HangmanPlaymodeTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb27dbfd228c60c4084daf09571d85e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
|
||||
8
Assets/NMLBuildCache.meta
Normal file
8
Assets/NMLBuildCache.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0fcd1404d38ac94aace1c5b3564cc04
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/NMLBuildCache/NatMLHub.asset
Normal file
20
Assets/NMLBuildCache/NatMLHub.asset
Normal file
@@ -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:
|
||||
8
Assets/NMLBuildCache/NatMLHub.asset.meta
Normal file
8
Assets/NMLBuildCache/NatMLHub.asset.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 327974eea6e413e418ae0fddd61a0e00
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,6 +16,13 @@ public class SpellingBeeGameEndedPanelTests
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("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);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ public class SpellingBeeControllerTests
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("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);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
"AccountsScripts",
|
||||
"SignPredictor",
|
||||
"MinigameScripts",
|
||||
"CommonScripts",
|
||||
"ArchitectureScripts"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user