Resolve WES-187 "Unit tests justsign and spellingbee"
This commit is contained in:
committed by
Dries Van Schuylenbergh
parent
1e09f09dae
commit
53fc361af4
@@ -7,6 +7,10 @@ using UnityEngine.TestTools;
|
||||
|
||||
public class SpellingBeeGameEndedPanelTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Setup for testing scoreboard of Spelling Bee
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
@@ -27,6 +31,10 @@ public class SpellingBeeGameEndedPanelTests
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the scoreboard for Spelling Bee
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator ScoreTest()
|
||||
{
|
||||
@@ -40,6 +48,9 @@ public class SpellingBeeGameEndedPanelTests
|
||||
|
||||
spellingBeeController.ActivateEnd(true);
|
||||
|
||||
// Fetch the panel with the info for the fields and check if the controller has implemented them
|
||||
var script = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
|
||||
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||
Assert.AreEqual("Score: 0", SpellingBeeGameEndedPanel.scoreText.text);
|
||||
@@ -49,4 +60,13 @@ public class SpellingBeeGameEndedPanelTests
|
||||
Assert.AreEqual("00:01", SpellingBeeGameEndedPanel.timeText.text);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup after testing
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public void TearDown_SpellingBeeScoreTests()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,15 @@ using UnityEngine.TestTools;
|
||||
|
||||
public class SpellingBeeControllerTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Setup for testing Spelling Bee
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
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.GetInstance().Load();
|
||||
@@ -20,17 +24,27 @@ public class SpellingBeeControllerTests
|
||||
// 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));
|
||||
ListMinigamesScreen minigameScreen = GameObject.FindObjectOfType<ListMinigamesScreen>();
|
||||
minigameScreen.minigameList.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
|
||||
|
||||
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the calculations of the score
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator CheckScoreTest()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
Assert.AreEqual(0, spellingBeeController.CalculateScore());
|
||||
spellingBeeController.NextWord();
|
||||
@@ -39,40 +53,167 @@ public class SpellingBeeControllerTests
|
||||
Assert.AreEqual(10, spellingBeeController.CalculateScore());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the ending panel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator ActivateGameOverTest()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
spellingBeeController.ActivateEnd(false);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
|
||||
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the scoreboard in case of completion
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator ActivateWinTests()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
spellingBeeController.ActivateEnd(true);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
|
||||
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||
Assert.AreEqual("GEWONNEN", SpellingBeeGameEndedPanel.endText.text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the scoreboard when timer goes off
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator CheckGameOverTest()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = (SpellingBeeController)GameObject.FindObjectOfType(typeof(SpellingBeeController));
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
spellingBeeController.AddSeconds(-60);
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = (SpellingBeeGameEndedPanel)GameObject.FindObjectOfType(typeof(SpellingBeeGameEndedPanel));
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
|
||||
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||
Assert.AreEqual("VERLOREN", SpellingBeeGameEndedPanel.endText.text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the completion from a word and from the entire theme + scoreboard
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator CheckGoToNextWord()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
string word = spellingBeeController.SkipToEnd();
|
||||
|
||||
spellingBeeController.PredictSign(spellingBeeController.GetSign());
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
Assert.IsTrue(spellingBeeController.bonusTimeText.activeSelf);
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
Assert.IsFalse(spellingBeeController.bonusTimeText.activeSelf);
|
||||
|
||||
for (int i = 1; i < word.Length; i++)
|
||||
{
|
||||
spellingBeeController.NextLetter(false);
|
||||
}
|
||||
spellingBeeController.NextWord();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
SpellingBeeGameEndedPanel SpellingBeeGameEndedPanel = GameObject.FindObjectOfType<SpellingBeeGameEndedPanel>();
|
||||
Assert.NotNull(SpellingBeeGameEndedPanel);
|
||||
Assert.AreEqual("GEWONNEN", SpellingBeeGameEndedPanel.endText.text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests the feedback in the game
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator FeedbackTest()
|
||||
{
|
||||
SpellingBeeController spellingBeeController = GameObject.FindObjectOfType<SpellingBeeController>();
|
||||
|
||||
string sign = spellingBeeController.GetSign();
|
||||
float threshold = spellingBeeController.GetThreshold(sign);
|
||||
spellingBeeController.ProcessCurrentAndPredicted(0.9f * threshold, sign, 0.9f * threshold, sign);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
Assert.AreEqual("Goed", spellingBeeController.feedbackText.text);
|
||||
Assert.AreEqual(new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f), spellingBeeController.feedbackText.color);
|
||||
Assert.AreEqual(new Color(0x8b / 255.0f, 0xd4 / 255.0f, 0x5e / 255.0f), spellingBeeController.scoreBonus.color);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
if (sign != spellingBeeController.GetSign())
|
||||
{
|
||||
string expected = spellingBeeController.GetSign();
|
||||
float distance = 3.0f * spellingBeeController.GetThreshold(expected);
|
||||
|
||||
spellingBeeController.ProcessCurrentAndPredicted(0.9f * threshold, sign, distance, expected);
|
||||
|
||||
yield return new WaitForSeconds(2.5f);
|
||||
|
||||
Assert.AreEqual($"Verkeerde gebaar: '{sign}'", spellingBeeController.feedbackText.text);
|
||||
Assert.AreEqual(new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f), spellingBeeController.feedbackText.color);
|
||||
|
||||
spellingBeeController.ProcessCurrentAndPredicted(0.9f * threshold, sign, distance, expected);
|
||||
|
||||
Assert.AreEqual(new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f), spellingBeeController.scoreBonus.color);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
sign = spellingBeeController.GetSign();
|
||||
threshold = spellingBeeController.GetThreshold(sign);
|
||||
spellingBeeController.ProcessCurrentAndPredicted(1.2f * threshold, sign, 1.2f * threshold, sign);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
Assert.AreEqual("Bijna...", spellingBeeController.feedbackText.text);
|
||||
Assert.AreEqual(new Color(0xf2 / 255.0f, 0x7f / 255.0f, 0x0c / 255.0f), spellingBeeController.feedbackText.color);
|
||||
|
||||
spellingBeeController.ProcessCurrentAndPredicted(3.0f * threshold, sign, 3.0f * threshold, sign);
|
||||
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
Assert.AreEqual("Detecteren...", spellingBeeController.feedbackText.text);
|
||||
Assert.AreEqual(new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f), spellingBeeController.feedbackText.color);
|
||||
|
||||
if (sign != spellingBeeController.GetSign())
|
||||
{
|
||||
string expected = spellingBeeController.GetSign();
|
||||
float distance = 3.0f * spellingBeeController.GetThreshold(expected);
|
||||
|
||||
spellingBeeController.ProcessCurrentAndPredicted(0.9f * threshold, sign, distance, expected);
|
||||
|
||||
yield return new WaitForSeconds(2.5f);
|
||||
|
||||
Assert.AreEqual($"Verkeerde gebaar: '{sign}'", spellingBeeController.feedbackText.text);
|
||||
Assert.AreEqual(new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f), spellingBeeController.feedbackText.color);
|
||||
|
||||
spellingBeeController.ProcessCurrentAndPredicted(0.9f * threshold, sign, distance, expected);
|
||||
|
||||
Assert.AreEqual(new Color(0xf5 / 255.0f, 0x49 / 255.0f, 0x3d / 255.0f), spellingBeeController.scoreBonus.color);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup after testing
|
||||
/// </summary>
|
||||
[TearDown]
|
||||
public void TearDown_SpellingBeeTests()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user