Resolve WES-192 "Fix progress screen"
This commit is contained in:
128
Assets/Accounts/Tests/PlayMode/ProgressGraphTests.cs
Normal file
128
Assets/Accounts/Tests/PlayMode/ProgressGraphTests.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
/// <summary>
|
||||
/// Test the ProgressGraph class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ProgressGraphTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Wait time between scene transitions
|
||||
/// </summary>
|
||||
private const float WAIT_TIME = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// Setup the ProgressGraph tests
|
||||
/// </summary>
|
||||
private IEnumerator Setup_ProgressGraph(int amount, Func<int, int> f)
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||
string score = "";
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
score += $"{{\"scoreValue\":{f(i)},\"time\":\"19/04/2023 22:32:39\"}}";
|
||||
if (i < amount - 1)
|
||||
score += ",";
|
||||
}
|
||||
|
||||
string minigame = $"{{\"entries\":[],\"minigameIndex\":1,\"latestScores\":[{score}],\"highestScores\":[{score}]}}";
|
||||
string oneUser = $"{{\"version\":1027,\"users\":[{{\"entries\":[],\"username\":\"Tester0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[{minigame}],\"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();
|
||||
|
||||
SystemController.GetInstance().SwapScene("Accounts/Scenes/UserProgressScreen");
|
||||
yield return new WaitForSeconds(WAIT_TIME);
|
||||
|
||||
GameObject.FindObjectOfType<UserProgressScreen>().DisplayMinigames();
|
||||
yield return new WaitForSeconds(WAIT_TIME);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||
/// </summary>
|
||||
[UnityTest]
|
||||
public IEnumerator Test_EditorAssignments()
|
||||
{
|
||||
yield return Setup_ProgressGraph(1, (i) => i);
|
||||
|
||||
var graph = GameObject.FindObjectOfType<ProgressGraph>();
|
||||
Assert.IsNotNull(graph);
|
||||
Assert.IsNotNull(graph.progressGraph);
|
||||
Assert.IsNotNull(graph.highscoreMarker);
|
||||
Assert.IsNotNull(graph.axesTickMarker);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_Negative()
|
||||
{
|
||||
yield return Setup_ProgressGraph(4, (i) => -5 * (i + 1));
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_SmallerThen1()
|
||||
{
|
||||
yield return Setup_ProgressGraph(4, (i) => (3 * i + 20) / 100);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_AroundZero()
|
||||
{
|
||||
yield return Setup_ProgressGraph(4, (i) => 5 * i - 10);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_AllZeros()
|
||||
{
|
||||
yield return Setup_ProgressGraph(4, (i) => 0);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_BetweenPos1AndNeg1()
|
||||
{
|
||||
yield return Setup_ProgressGraph(10, (i) => (i % 3) - 1);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_Single()
|
||||
{
|
||||
yield return Setup_ProgressGraph(1, (i) => i + 500);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_Multiple()
|
||||
{
|
||||
yield return Setup_ProgressGraph(5, (i) => 5 * i);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test_PlotGraph_TooMany()
|
||||
{
|
||||
yield return Setup_ProgressGraph(10, (i) => 5 * i);
|
||||
yield return new WaitForSeconds(5.0f);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user