Sprint 6
This commit is contained in:
@@ -7,21 +7,30 @@ using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
/// <summary>
|
||||
/// Test the HangmanController class
|
||||
/// </summary>
|
||||
public class HangmanPlaymodeTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the HangmanController so we can access it quickly
|
||||
/// </summary>
|
||||
private HangmanController hangmanController;
|
||||
|
||||
/// <summary>
|
||||
/// The mode of the multiple choice panel that when the confirm button needs to be clicked
|
||||
/// </summary>
|
||||
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}}";
|
||||
string oneUser = $"{{\"version\":1537,\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0,\"useGPU\":false}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
@@ -87,13 +96,11 @@ public class HangmanPlaymodeTests
|
||||
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()
|
||||
{
|
||||
@@ -188,7 +195,6 @@ public class HangmanPlaymodeTests
|
||||
/// <summary>
|
||||
/// Tests the multiplayer-code
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator MultiPlayerTests()
|
||||
{
|
||||
@@ -215,7 +221,7 @@ public class HangmanPlaymodeTests
|
||||
// Wrong letter, but this one will be rejected
|
||||
while (hangmanController.getCurrentMode() != multiplayerConfirmInput)
|
||||
{
|
||||
hangmanController.ProcessSignForTests(1, "Q");
|
||||
hangmanController.ProcessMostProbableSign(0.0001f, "Q");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -259,23 +265,22 @@ public class HangmanPlaymodeTests
|
||||
/// <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(0.001f, "A");
|
||||
hangmanController.ProcessMostProbableSign(0.001f, "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(0.001f, "B");
|
||||
hangmanController.ProcessMostProbableSign(0.001f, "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(1000, "B");
|
||||
hangmanController.ProcessMostProbableSign(1000, "B");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
// The sign changed is way above the threshold, time is no longer tracked and is reset
|
||||
Assert.IsTrue(hangmanController.getCurrentTime() == 0.0);
|
||||
@@ -285,13 +290,13 @@ public class HangmanPlaymodeTests
|
||||
float threshold = C.thresholdDistance;
|
||||
for (float i = 2 * threshold; i > threshold; i -= threshold / 6)
|
||||
{
|
||||
hangmanController.ProcessSignForTests(i, "C");
|
||||
hangmanController.ProcessMostProbableSign(i, "C");
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
Assert.IsTrue(hangmanController.getCurrentTime() == 0.0);
|
||||
}
|
||||
|
||||
// Check that the time rises above zero when you dip just below the threshold
|
||||
hangmanController.ProcessSignForTests(threshold - 0.01f, "C");
|
||||
hangmanController.ProcessMostProbableSign(threshold - 0.01f, "C");
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
Assert.IsTrue(hangmanController.getCurrentTime() > 0.0);
|
||||
|
||||
@@ -301,7 +306,6 @@ public class HangmanPlaymodeTests
|
||||
/// <summary>
|
||||
/// Test the functionality of the scoreboard to display multiple games
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[UnityTest]
|
||||
public IEnumerator ScoreBoardTest()
|
||||
{
|
||||
@@ -360,7 +364,7 @@ public class HangmanPlaymodeTests
|
||||
while (hangmanController.getCurrentMode() != multiplayerConfirmInput)
|
||||
{
|
||||
// Choose the letter by giving it a very small distance
|
||||
hangmanController.ProcessSignForTests(0.001f, letter);
|
||||
hangmanController.ProcessMostProbableSign(0.001f, letter);
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -377,7 +381,7 @@ public class HangmanPlaymodeTests
|
||||
while (!hangmanController.getUsedLetters().Contains(letter))
|
||||
{
|
||||
// Choose the letter by giving it a very small distance
|
||||
hangmanController.ProcessSignForTests(0.001f, letter);
|
||||
hangmanController.ProcessMostProbableSign(0.001f, letter);
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user