Merge branch 'WES-110-spelling-bee-tests' into 'development'
Spelling bee tests See merge request wesign/unity-application!58
This commit was merged in pull request #58.
This commit is contained in:
8
Assets/SpellingBee/PlayModeTests.meta
Normal file
8
Assets/SpellingBee/PlayModeTests.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2fd5cdf8e7f70bf4882b352aaaa8a2bf
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
78
Assets/SpellingBee/PlayModeTests/GameControllerTests.cs
Normal file
78
Assets/SpellingBee/PlayModeTests/GameControllerTests.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/SpellingBee/PlayModeTests/GameControllerTests.cs.meta
Normal file
11
Assets/SpellingBee/PlayModeTests/GameControllerTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b8e6983596a4a49488dc71c4980b53c7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
52
Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs
Normal file
52
Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs
Normal file
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs.meta
Normal file
11
Assets/SpellingBee/PlayModeTests/GameEndedPanelTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c8161cc9db422724cbfe7634320ecad4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8024acb9574451c40ba558529a3ef51c
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -241,7 +241,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Randomly shuffle the list of words
|
/// Randomly shuffle the list of words
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ShuffleWords()
|
public void ShuffleWords()
|
||||||
{
|
{
|
||||||
for (int i = words.Count - 1; i > 0; i--)
|
for (int i = words.Count - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
@@ -257,7 +257,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// Calculate the score
|
/// Calculate the score
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The calculated score</returns>
|
/// <returns>The calculated score</returns>
|
||||||
private int CalculateScore()
|
public int CalculateScore()
|
||||||
{
|
{
|
||||||
return spelledWords * 5 + correctLetters;
|
return spelledWords * 5 + correctLetters;
|
||||||
}
|
}
|
||||||
@@ -265,7 +265,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Displays the game over panel and score values
|
/// Displays the game over panel and score values
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ActivateGameOver()
|
public void ActivateGameOver()
|
||||||
{
|
{
|
||||||
gameEnded = true;
|
gameEnded = true;
|
||||||
DeleteWord();
|
DeleteWord();
|
||||||
@@ -287,7 +287,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Display win screen
|
/// Display win screen
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ActivateWin()
|
public void ActivateWin()
|
||||||
{
|
{
|
||||||
gameEnded = true;
|
gameEnded = true;
|
||||||
DeleteWord();
|
DeleteWord();
|
||||||
@@ -309,7 +309,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update and save the scores
|
/// Update and save the scores
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void SaveScores()
|
public void SaveScores()
|
||||||
{
|
{
|
||||||
// Calculate new score
|
// Calculate new score
|
||||||
int newScore = CalculateScore();
|
int newScore = CalculateScore();
|
||||||
@@ -344,7 +344,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete all letter objects
|
/// Delete all letter objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void DeleteWord()
|
public void DeleteWord()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < letters.Count; i++)
|
for (int i = 0; i < letters.Count; i++)
|
||||||
{
|
{
|
||||||
@@ -357,7 +357,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// Adds seconds to timer
|
/// Adds seconds to timer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="seconds"></param>
|
/// <param name="seconds"></param>
|
||||||
private void AddSeconds(int seconds)
|
public void AddSeconds(int seconds)
|
||||||
{
|
{
|
||||||
timerValue += (float)seconds;
|
timerValue += (float)seconds;
|
||||||
bonusTimeText.SetActive(true);
|
bonusTimeText.SetActive(true);
|
||||||
@@ -368,7 +368,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// Display the next letter
|
/// Display the next letter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
|
/// <param name="successful">true if the letter was correctly signed, false otherwise</param>
|
||||||
private void NextLetter(bool successful)
|
public void NextLetter(bool successful)
|
||||||
{
|
{
|
||||||
// Change color of current letter (skip spaces)
|
// Change color of current letter (skip spaces)
|
||||||
if (successful)
|
if (successful)
|
||||||
@@ -402,7 +402,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Display next word in the series
|
/// Display next word in the series
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void NextWord()
|
public void NextWord()
|
||||||
{
|
{
|
||||||
DeleteWord();
|
DeleteWord();
|
||||||
spelledWords++;
|
spelledWords++;
|
||||||
@@ -425,7 +425,7 @@ public partial class GameController : MonoBehaviour
|
|||||||
/// Displays the word that needs to be spelled
|
/// Displays the word that needs to be spelled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="word">The word to display</param>
|
/// <param name="word">The word to display</param>
|
||||||
private void DisplayWord(string word)
|
public void DisplayWord(string word)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < word.Length; i++)
|
for (int i = 0; i < word.Length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user