Resolve WES-187 "Unit tests account and system"
This commit is contained in:
committed by
Jerome Coudron
parent
c4b6c60288
commit
b9bbef8dcf
1
.gitignore
vendored
1
.gitignore
vendored
@@ -74,3 +74,4 @@ crashlytics-build.properties
|
|||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json
|
/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json
|
||||||
|
CodeCoverage/
|
||||||
|
|||||||
@@ -26,19 +26,16 @@ public class User
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the username
|
/// Get the username
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
|
||||||
public string GetUsername() { return storedUserData.username; }
|
public string GetUsername() { return storedUserData.username; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the total playtime
|
/// Get the total playtime
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
|
||||||
public double GetPlaytime() { return storedUserData.playtime; }
|
public double GetPlaytime() { return storedUserData.playtime; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the avatar
|
/// Get the avatar
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
|
||||||
public Sprite GetAvatar() { return UserList.AVATARS[storedUserData.avatarIndex]; }
|
public Sprite GetAvatar() { return UserList.AVATARS[storedUserData.avatarIndex]; }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@@ -70,26 +69,6 @@ public class UserProgressScreen : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public RawImage progressGraph;
|
public RawImage progressGraph;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Left and right padding of the graph
|
|
||||||
/// </summary>
|
|
||||||
private const int GRAPH_PADDING_X_PX = 50;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Top and bottom padding of the graph
|
|
||||||
/// </summary>
|
|
||||||
private const int GRAPH_PADDING_Y_PX = 50;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Radius of the point on the graph
|
|
||||||
/// </summary>
|
|
||||||
private const int GRAPH_POINT_RADIUS = 10;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Size of the line on the graph
|
|
||||||
/// </summary>
|
|
||||||
private const int GRAPH_LINE_SIZE = 4;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current selected activity draw to the graph
|
/// Current selected activity draw to the graph
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -113,8 +92,7 @@ public class UserProgressScreen : MonoBehaviour
|
|||||||
// Set correct displayed items
|
// Set correct displayed items
|
||||||
username.text = user.GetUsername();
|
username.text = user.GetUsername();
|
||||||
avatar.sprite = user.GetAvatar();
|
avatar.sprite = user.GetAvatar();
|
||||||
// TODO: implement total playtime
|
playtime.text = $"Totale speeltijd: {user.GetPlaytime().ToString("0.00")}";
|
||||||
//playtime.text = $"Totale speeltijd: {user.playtime.ToString("0.00")}";
|
|
||||||
|
|
||||||
// Set graph inactive
|
// Set graph inactive
|
||||||
progressGraph.gameObject.SetActive(false);
|
progressGraph.gameObject.SetActive(false);
|
||||||
@@ -206,170 +184,6 @@ public class UserProgressScreen : MonoBehaviour
|
|||||||
/// Plot the graph of a minigame
|
/// Plot the graph of a minigame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="minigameIndex">Index of the minigame</param>
|
/// <param name="minigameIndex">Index of the minigame</param>
|
||||||
private void DisplayMinigameGraph(MinigameIndex minigameIndex)
|
/// <remarks>TODO: reworking </remarks>
|
||||||
{
|
private void DisplayMinigameGraph(MinigameIndex minigameIndex) { }
|
||||||
var progress = user.GetMinigameProgress(minigameIndex);
|
|
||||||
List<Score> latestScores = progress.latestScores;
|
|
||||||
List<Score> highestScores = progress.highestScores;
|
|
||||||
if (0 < highestScores.Count)
|
|
||||||
{
|
|
||||||
PlotGraph(latestScores.ConvertAll<double>((s) => (double)s.scoreValue), highestScores[0].scoreValue);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
progressGraph.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Plot points and a highscore on the graph
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scores">List of score values to plot</param>
|
|
||||||
/// <param name="highscore">Highscore value (this will be plotted in a fancy color)</param>
|
|
||||||
private void PlotGraph(List<double> scores, double highscore)
|
|
||||||
{
|
|
||||||
// Remove previous marker(s)
|
|
||||||
foreach (Transform child in progressGraph.gameObject.transform)
|
|
||||||
{
|
|
||||||
Destroy(child.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get texture reference
|
|
||||||
Texture2D tex = progressGraph.texture as Texture2D;
|
|
||||||
if (tex == null)
|
|
||||||
{
|
|
||||||
RectTransform rt = progressGraph.gameObject.transform as RectTransform;
|
|
||||||
tex = new Texture2D(
|
|
||||||
width: (int)rt.sizeDelta.x,
|
|
||||||
height: (int)rt.sizeDelta.y,
|
|
||||||
textureFormat: TextureFormat.ARGB32,
|
|
||||||
mipCount: 3,
|
|
||||||
linear: true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
tex.filterMode = FilterMode.Point;
|
|
||||||
|
|
||||||
// calculate positions and offsets
|
|
||||||
int x0 = GRAPH_PADDING_X_PX, x1 = tex.width - GRAPH_PADDING_X_PX;
|
|
||||||
int y0 = GRAPH_PADDING_Y_PX, y1 = tex.height - GRAPH_PADDING_Y_PX;
|
|
||||||
double min = scores.Min();
|
|
||||||
double max = scores.Max();
|
|
||||||
|
|
||||||
List<Tuple<int, int>> points = new List<Tuple<int, int>>();
|
|
||||||
for (int i = 0; i < scores.Count; i++)
|
|
||||||
{
|
|
||||||
int x = x0 + (scores.Count > 1 ? i * ((x1 - x0) / (scores.Count - 1)) : (x1 - x0) / 2);
|
|
||||||
int y = y0 + (int)((y1 - y0) * (min != max ? (scores[i] - min) / (max - min) : 0.5));
|
|
||||||
points.Add(Tuple.Create(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate scaling
|
|
||||||
int mag = (int)Math.Round(Math.Log10(max));
|
|
||||||
int MAG = (int)Math.Pow(10, mag);
|
|
||||||
double c = max / MAG;
|
|
||||||
|
|
||||||
// Draw axes
|
|
||||||
if (min != max)
|
|
||||||
{
|
|
||||||
for (double d = c / 5.0; d < c; d += 0.2 * c)
|
|
||||||
{
|
|
||||||
int y = y0 + (int)((y1 - y0) * (MAG * d - min) / (max - min));
|
|
||||||
DrawLine(tex, x0, y, x1, y, 2, Color.gray);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int y = y0 + (int)((y1 - y0) * 0.5);
|
|
||||||
DrawLine(tex, x0, y0, x1, y0, 2, Color.gray);
|
|
||||||
DrawLine(tex, x0, y, x1, y, 2, Color.gray);
|
|
||||||
DrawLine(tex, x0, y1, x1, y1, 2, Color.gray);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw highscore
|
|
||||||
if (min <= highscore && highscore <= max)
|
|
||||||
{
|
|
||||||
int y = y0 + (int)((y1 - y0) * (min != max ? (highscore - min) / (max - min) : 0.5));
|
|
||||||
DrawLine(tex, x0, y, x1, y, 3, new Color(255, 192, 0));
|
|
||||||
GameObject marker = GameObject.Instantiate(highscoreMarker, progressGraph.gameObject.transform);
|
|
||||||
RectTransform rect = marker.GetComponent<RectTransform>();
|
|
||||||
rect.localPosition = new Vector3(0, y - 25, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw points
|
|
||||||
for (int i = 0; i < points.Count; i++)
|
|
||||||
{
|
|
||||||
Tuple<int, int> p = points[i];
|
|
||||||
if (0 < i)
|
|
||||||
{
|
|
||||||
Tuple<int, int> q = points[i - 1];
|
|
||||||
DrawLine(tex, p.Item1, p.Item2, q.Item1, q.Item2, GRAPH_LINE_SIZE, Color.blue);
|
|
||||||
}
|
|
||||||
DrawPoint(tex, p.Item1, p.Item2, GRAPH_POINT_RADIUS, Color.blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply to graph GameObject
|
|
||||||
tex.Apply();
|
|
||||||
progressGraph.texture = tex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draw a point to a texture
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tex">Texture2D to plot point on</param>
|
|
||||||
/// <param name="xc">Center x-pos</param>
|
|
||||||
/// <param name="yc">Center y-pos</param>
|
|
||||||
/// <param name="r">Radius (aka width and height)</param>
|
|
||||||
/// <param name="color">Color of the point</param>
|
|
||||||
private void DrawPoint(Texture2D tex, int xc, int yc, int r, Color color)
|
|
||||||
{
|
|
||||||
for (int y = yc - r; y < yc + r; y++)
|
|
||||||
{
|
|
||||||
for (int x = xc - r; x < xc + r; x++)
|
|
||||||
{
|
|
||||||
tex.SetPixel(x, y, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draw a line to a texture
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tex">Texture2D to plot line on</param>
|
|
||||||
/// <param name="x0">Starting x-pos</param>
|
|
||||||
/// <param name="y0">Strating y-pos</param>
|
|
||||||
/// <param name="x1">Ending x-pos</param>
|
|
||||||
/// <param name="y1">Ending y-pos</param>
|
|
||||||
/// <param name="size">Size of the line (width)</param>
|
|
||||||
/// <param name="color">Color of the line</param>
|
|
||||||
private void DrawLine(Texture2D tex, int x0, int y0, int x1, int y1, int size, Color color)
|
|
||||||
{
|
|
||||||
int w = x1 - x0;
|
|
||||||
int h = y1 - y0;
|
|
||||||
|
|
||||||
int length = Mathf.Abs(x1 - x0);
|
|
||||||
if (Mathf.Abs(y1 - y0) > length)
|
|
||||||
{
|
|
||||||
length = Mathf.Abs(h);
|
|
||||||
}
|
|
||||||
|
|
||||||
double dx = w / (double)length;
|
|
||||||
double dy = h / (double)length;
|
|
||||||
|
|
||||||
double x = x0;
|
|
||||||
double y = y0;
|
|
||||||
double r = size / 2;
|
|
||||||
for (int i = 0; i <= length; i++)
|
|
||||||
{
|
|
||||||
for (int j = (int)(y - r); j < y + r; j++)
|
|
||||||
{
|
|
||||||
for (int k = (int)(x - r); k < x + r; k++)
|
|
||||||
{
|
|
||||||
tex.SetPixel(k, j, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
x += dx;
|
|
||||||
y += dy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: d322616d16e32135eb3735e3bb704d05
|
guid: fa6a54c35531563408befe54af56be0f
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "AccountsTests",
|
"name": "AccountEditMode",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
27
Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs
Normal file
27
Assets/Accounts/Tests/EditMode/UserAvatarListTests.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the UserAvatarList class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class UserAvatarListTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test the UserAvatarList class correctly initializes the UserList class
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_Awake()
|
||||||
|
{
|
||||||
|
UserList.AVATARS = new List<Sprite>();
|
||||||
|
|
||||||
|
var scriptableObject = AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset");
|
||||||
|
scriptableObject.Awake();
|
||||||
|
|
||||||
|
for (int i = 0; i < scriptableObject.avatars.Count; i++)
|
||||||
|
Assert.AreEqual(scriptableObject.avatars[i], UserList.AVATARS[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: b3a4277e90159fa578bf998923333834
|
guid: 6c26e155ab597954a8c65fafe61a8e22
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -4,7 +4,7 @@ using NUnit.Framework;
|
|||||||
/// Test the UserCreationScreen class
|
/// Test the UserCreationScreen class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class UserCreationScreenTest
|
public class UserCreationScreenTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tets IsValidUsername will return <c>true</c> for an valid username
|
/// Tets IsValidUsername will return <c>true</c> for an valid username
|
||||||
@@ -9,12 +9,12 @@ using UnityEngine;
|
|||||||
/// Test the UserList class
|
/// Test the UserList class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class UserListTest
|
public class UserListTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new path so the existing .json file will not be overwritten
|
/// Create a new path so the existing .json file will not be overwritten
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static string PATH = $"{Application.persistentDataPath}/unit_test_users.json";
|
private static string PATH = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper variable for quick user creation
|
/// Helper variable for quick user creation
|
||||||
@@ -26,13 +26,15 @@ public class UserListTest
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private Sprite avatar = null;
|
private Sprite avatar = null;
|
||||||
|
|
||||||
|
private string cachedPath;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Setup the tests
|
/// Setup the tests
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup_UserList()
|
public void Setup_UserList()
|
||||||
{
|
{
|
||||||
PersistentDataController.PATH = UserListTest.PATH;
|
PersistentDataController.PATH = UserListTests.PATH;
|
||||||
|
|
||||||
if (File.Exists(PATH))
|
if (File.Exists(PATH))
|
||||||
File.Delete(PATH);
|
File.Delete(PATH);
|
||||||
@@ -42,6 +44,15 @@ public class UserListTest
|
|||||||
avatar = UserList.AVATARS[0];
|
avatar = UserList.AVATARS[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_UserList()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test for creation of a new UserList
|
/// Test for creation of a new UserList
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -271,7 +282,7 @@ public class UserListTest
|
|||||||
/// Test whether deleting a non-existing user (referenced by wrong index) will fail
|
/// Test whether deleting a non-existing user (referenced by wrong index) will fail
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_UserList_DeleteUser_InValidIndex()
|
public void Test_UserList_DeleteUser_InvalidIndex()
|
||||||
{
|
{
|
||||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||||||
/// Test the User class
|
/// Test the User class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class UserTest
|
public class UserTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reference to the user to be tested
|
/// Reference to the user to be tested
|
||||||
@@ -37,6 +37,33 @@ public class UserTest
|
|||||||
Assert.Zero(user.GetMinigames().Count);
|
Assert.Zero(user.GetMinigames().Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the correct username is returned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_User_GetUsername()
|
||||||
|
{
|
||||||
|
Assert.AreEqual("username", user.GetUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the correct avatar is returned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_User_GetAvatar()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(UserList.AVATARS[0], user.GetAvatar());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the correct total playtime is returned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_User_GetPlaytime()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(0.0, user.GetPlaytime());
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test whether progress on a new course can be added
|
/// Test whether progress on a new course can be added
|
||||||
/// </summary>
|
/// </summary>
|
||||||
8
Assets/Accounts/Tests/PlayMode.meta
Normal file
8
Assets/Accounts/Tests/PlayMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03b891ac179161f4b99b84a2205edffa
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
26
Assets/Accounts/Tests/PlayMode/AccountPlayMode.asmdef
Normal file
26
Assets/Accounts/Tests/PlayMode/AccountPlayMode.asmdef
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"name": "AccountPlayMode",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"UnityEngine.TestRunner",
|
||||||
|
"UnityEditor.TestRunner",
|
||||||
|
"AccountsScripts",
|
||||||
|
"InterfacesScripts",
|
||||||
|
"Unity.TextMeshPro",
|
||||||
|
"CommonScripts",
|
||||||
|
"ArchitectureScripts"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": true,
|
||||||
|
"precompiledReferences": [
|
||||||
|
"nunit.framework.dll"
|
||||||
|
],
|
||||||
|
"autoReferenced": false,
|
||||||
|
"defineConstraints": [
|
||||||
|
"UNITY_INCLUDE_TESTS"
|
||||||
|
],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 1606ac91cab3333be8c7e7281c392595
|
guid: 3692a9a813d54b0449b55e372a28697a
|
||||||
AssemblyDefinitionImporter:
|
AssemblyDefinitionImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
378
Assets/Accounts/Tests/PlayMode/ChangeUserScreenTests.cs
Normal file
378
Assets/Accounts/Tests/PlayMode/ChangeUserScreenTests.cs
Normal file
@@ -0,0 +1,378 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the ChangeUserScreen class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class ChangeUserScreenTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The default current user when dealing with multiple users
|
||||||
|
/// </summary>
|
||||||
|
private const int currentUser = 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the tests for a single user
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Setup_ChangeUserScreen_SingleUser(string startScreen = "Accounts/Scenes/ChangeUserScreen")
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string oneUser = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"Tester0\",\"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();
|
||||||
|
|
||||||
|
SystemController.GetInstance().SwapScene(startScreen);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the tests for a multiple users
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Setup_ChangeUserScreen_MultipleUsers(string startScreen = "Accounts/Scenes/ChangeUserScreen")
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string users = "";
|
||||||
|
for (int i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
users += $"{{\"entries\":[],\"username\":\"Tester{i}\",\"avatarIndex\":{i},\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}";
|
||||||
|
if (i < 4) users += ",";
|
||||||
|
}
|
||||||
|
const int currentUser = 2;
|
||||||
|
string fiveUsers = $"{{\"version\":1027,\"users\":[{users}],\"currentUser\":{currentUser},\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
|
File.WriteAllText(path, fiveUsers);
|
||||||
|
PersistentDataController.PATH = path;
|
||||||
|
PersistentDataController.GetInstance().Load();
|
||||||
|
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||||
|
|
||||||
|
SystemController.GetInstance().SwapScene(startScreen);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser();
|
||||||
|
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsNotNull(changeUserController);
|
||||||
|
Assert.IsNotNull(changeUserController.userPrefab);
|
||||||
|
Assert.IsNotNull(changeUserController.usersContainer);
|
||||||
|
Assert.IsNotNull(changeUserController.error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the screen is correctly initialized (one user)
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_Start_SingleUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser();
|
||||||
|
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsFalse(changeUserController.error.activeSelf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the users is correctly displayed (one user)
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_DisplayUsers_SingleUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser();
|
||||||
|
|
||||||
|
// The content of the usercard is tested in the `UserCardTests`-script
|
||||||
|
// Here, we only check the amount of users
|
||||||
|
Assert.AreEqual(1, UserList.GetUsers().Count);
|
||||||
|
var cards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(1, cards.Count);
|
||||||
|
Assert.AreEqual(Color.blue, cards[0].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the users are correctly displayed (mulitple users)
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_DisplayUsers_MultipleUsers()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
// The content of the usercard is tested in the `UserCardTests`-script
|
||||||
|
// Here, we only check the amount of users and whether the correct one is selected
|
||||||
|
Assert.AreEqual(UserList.GetCurrentUser().GetUsername(), UserList.GetUserByIndex(currentUser).GetUsername());
|
||||||
|
var cards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(UserList.GetUsers().Count, cards.Count);
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether selecting a new user before the current one updates the display correctly
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UpdateSelection_BeforeCurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
var cards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
const int newUser = 1;
|
||||||
|
cards[newUser].selectUser.Invoke();
|
||||||
|
|
||||||
|
// After update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == newUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether selecting the current user for update the display will change nothing
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UpdateSelection_CurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
var cards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
cards[currentUser].selectUser.Invoke();
|
||||||
|
|
||||||
|
// After update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether selecting a new user after the current one updates the display correctly
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UpdateSelection_AfterCurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
var cards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
const int newUser = 3;
|
||||||
|
cards[newUser].selectUser.Invoke();
|
||||||
|
|
||||||
|
// After update
|
||||||
|
for (int i = 0; i < cards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == newUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, cards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test IChooseYou callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_IChooseYou()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser("Common/Scenes/MainMenuScreen");
|
||||||
|
|
||||||
|
SystemController.GetInstance().LoadNextScene("Accounts/Scenes/ChangeUserScreen");
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
changeUserController.IChooseYou();
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex("Common/Scenes/MainMenuScreen"), SystemController.GetInstance().currentScene);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the GotoUserCreation callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_GotoUserCreation()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser();
|
||||||
|
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
changeUserController.GotoUserCreation();
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
Assert.IsNotNull(userCreationController);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the user cards DeleteUser callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UserCardDeleteUser_BeforeCurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
var oldCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
for (int i = 0; i < oldCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, oldCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
oldCards[1].DeleteUser();
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsFalse(changeUserController.error.activeSelf);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
// After update
|
||||||
|
var newCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(oldCards.Count - 1, newCards.Count);
|
||||||
|
for (int i = 0; i < newCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == (currentUser - 1) ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, newCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the user cards DeleteUser callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UserCardDeleteUser_CurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
var oldCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
for (int i = 0; i < oldCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, oldCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
oldCards[currentUser].DeleteUser();
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsFalse(changeUserController.error.activeSelf);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
// After update
|
||||||
|
var newCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(oldCards.Count - 1, newCards.Count);
|
||||||
|
for (int i = 0; i < newCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, newCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the user cards DeleteUser callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UserCardDeleteUser_AfterCurrentUser()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_MultipleUsers();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
var oldCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
for (int i = 0; i < oldCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, oldCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
oldCards[3].DeleteUser();
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsFalse(changeUserController.error.activeSelf);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
// After update
|
||||||
|
var newCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(oldCards.Count - 1, newCards.Count);
|
||||||
|
for (int i = 0; i < newCards.Count; i++)
|
||||||
|
{
|
||||||
|
Color expected = i == currentUser ? Color.blue : Color.gray;
|
||||||
|
Assert.AreEqual(expected, newCards[i].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the user cards DeleteUser callback
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UserCardDeleteUser_Invalid()
|
||||||
|
{
|
||||||
|
yield return Setup_ChangeUserScreen_SingleUser();
|
||||||
|
|
||||||
|
// Before update
|
||||||
|
var oldCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(1, oldCards.Count);
|
||||||
|
Assert.AreEqual(Color.blue, oldCards[0].gameObject.GetComponent<Image>().color);
|
||||||
|
|
||||||
|
// Update
|
||||||
|
oldCards[0].DeleteUser();
|
||||||
|
var changeUserController = GameObject.FindObjectOfType<ChangeUserScreen>();
|
||||||
|
Assert.IsTrue(changeUserController.error.activeSelf);
|
||||||
|
|
||||||
|
// After update
|
||||||
|
var newCards = GameObject.FindObjectsOfType<UserCard>().ToList();
|
||||||
|
Assert.AreEqual(1, newCards.Count);
|
||||||
|
Assert.AreEqual(Color.blue, newCards[0].gameObject.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 98c67df90515b0fec8184240768037cd
|
guid: 82964bdf541a6d64bae05c104ef64494
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
77
Assets/Accounts/Tests/PlayMode/CourseProgressCardTests.cs
Normal file
77
Assets/Accounts/Tests/PlayMode/CourseProgressCardTests.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the CourseProgressCard class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class CourseProgressCardTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the CourseProgressCard tests
|
||||||
|
/// </summary>
|
||||||
|
[UnitySetUp]
|
||||||
|
public IEnumerator Setup_CourseProgressCard()
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string course = "{\"entries\":[],\"courseIndex\":0,\"progress\":0.03846153989434242,\"completedLearnables\":1,\"inUseLearnables\":7,\"totalLearnables\":26,\"learnables\":[{\"entries\":[],\"index\":0,\"inUse\":true,\"name\":\"A\",\"progress\":3.0},{\"entries\":[],\"index\":1,\"inUse\":true,\"name\":\"B\",\"progress\":4.5},{\"entries\":[],\"index\":2,\"inUse\":true,\"name\":\"C\",\"progress\":1.5},{\"entries\":[],\"index\":3,\"inUse\":true,\"name\":\"D\",\"progress\":1.5},{\"entries\":[],\"index\":4,\"inUse\":true,\"name\":\"E\",\"progress\":1.5},{\"entries\":[],\"index\":5,\"inUse\":true,\"name\":\"F\",\"progress\":1.5},{\"entries\":[],\"index\":6,\"inUse\":true,\"name\":\"G\",\"progress\":0.0},{\"entries\":[],\"index\":7,\"inUse\":false,\"name\":\"H\",\"progress\":0.0},{\"entries\":[],\"index\":8,\"inUse\":false,\"name\":\"I\",\"progress\":0.0},{\"entries\":[],\"index\":9,\"inUse\":false,\"name\":\"J\",\"progress\":0.0},{\"entries\":[],\"index\":10,\"inUse\":false,\"name\":\"K\",\"progress\":0.0},{\"entries\":[],\"index\":11,\"inUse\":false,\"name\":\"L\",\"progress\":0.0},{\"entries\":[],\"index\":12,\"inUse\":false,\"name\":\"M\",\"progress\":0.0},{\"entries\":[],\"index\":13,\"inUse\":false,\"name\":\"N\",\"progress\":0.0},{\"entries\":[],\"index\":14,\"inUse\":false,\"name\":\"O\",\"progress\":0.0},{\"entries\":[],\"index\":15,\"inUse\":false,\"name\":\"P\",\"progress\":0.0},{\"entries\":[],\"index\":16,\"inUse\":false,\"name\":\"Q\",\"progress\":0.0},{\"entries\":[],\"index\":17,\"inUse\":false,\"name\":\"R\",\"progress\":0.0},{\"entries\":[],\"index\":18,\"inUse\":false,\"name\":\"S\",\"progress\":0.0},{\"entries\":[],\"index\":19,\"inUse\":false,\"name\":\"T\",\"progress\":0.0},{\"entries\":[],\"index\":20,\"inUse\":false,\"name\":\"U\",\"progress\":0.0},{\"entries\":[],\"index\":21,\"inUse\":false,\"name\":\"V\",\"progress\":0.0},{\"entries\":[],\"index\":22,\"inUse\":false,\"name\":\"W\",\"progress\":0.0},{\"entries\":[],\"index\":23,\"inUse\":false,\"name\":\"X\",\"progress\":0.0},{\"entries\":[],\"index\":24,\"inUse\":false,\"name\":\"Y\",\"progress\":0.0},{\"entries\":[],\"index\":25,\"inUse\":false,\"name\":\"Z\",\"progress\":0.0}]}";
|
||||||
|
string oneUser = $"{{\"version\":1027,\"users\":[{{\"entries\":[],\"username\":\"Tester0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[{course}]}}],\"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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<CourseProgressCard>();
|
||||||
|
Assert.IsNotNull(card);
|
||||||
|
Assert.IsNotNull(card.button);
|
||||||
|
Assert.IsNotNull(card.courseProgress);
|
||||||
|
Assert.IsNotNull(card.courseList);
|
||||||
|
Assert.IsNotNull(card.thumbnail);
|
||||||
|
Assert.IsNotNull(card.title);
|
||||||
|
Assert.IsNotNull(card.progressBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the card is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_Start()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<CourseProgressCard>();
|
||||||
|
Course course = card.courseList.GetCourseByIndex(card.courseProgress.courseIndex);
|
||||||
|
|
||||||
|
Assert.AreEqual(course.thumbnail, card.thumbnail.sprite);
|
||||||
|
Assert.AreEqual(course.title, card.title.text);
|
||||||
|
Assert.AreEqual(card.courseProgress.progress, card.progressBar.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 5ce78cb7021f901bc8d26bf7534a92bf
|
guid: 82e22c178ff48c146b6c87a7552e97ed
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
77
Assets/Accounts/Tests/PlayMode/MinigameProgressCardTests.cs
Normal file
77
Assets/Accounts/Tests/PlayMode/MinigameProgressCardTests.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the MinigameProgressCard class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class MinigameProgressCardTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the MinigameProgressCard tests
|
||||||
|
/// </summary>
|
||||||
|
[UnitySetUp]
|
||||||
|
public IEnumerator Setup_MinigameProgressCard()
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string minigame = "{\"entries\":[],\"minigameIndex\":1,\"latestScores\":[{\"scoreValue\":70,\"time\":\"19/04/2023 22:32:39\"},{\"scoreValue\":55,\"time\":\"20/04/2023 11:50:10\"},{\"scoreValue\":55,\"time\":\"20/04/2023 13:27:15\"}],\"highestScores\":[{\"scoreValue\":70,\"time\":\"19/04/2023 22:32:39\"},{\"scoreValue\":55,\"time\":\"20/04/2023 11:50:10\"},{\"scoreValue\":55,\"time\":\"20/04/2023 13:27:15\"}]}";
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<MinigameProgressCard>();
|
||||||
|
Assert.IsNotNull(card);
|
||||||
|
Assert.IsNotNull(card.button);
|
||||||
|
Assert.IsNotNull(card.minigameProgress);
|
||||||
|
Assert.IsNotNull(card.minigameList);
|
||||||
|
Assert.IsNotNull(card.thumbnail);
|
||||||
|
Assert.IsNotNull(card.title);
|
||||||
|
Assert.IsNotNull(card.highscore);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the card is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_Start()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<MinigameProgressCard>();
|
||||||
|
Minigame minigame = card.minigameList.GetMinigameByIndex(card.minigameProgress.minigameIndex);
|
||||||
|
|
||||||
|
Assert.AreEqual(minigame.thumbnail, card.thumbnail.sprite);
|
||||||
|
Assert.AreEqual(minigame.title, card.title.text);
|
||||||
|
Assert.AreEqual(card.highscore.text, $"Topscore: {card.minigameProgress.highestScores[0].scoreValue}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ec3ef897a8a62eee2b7d8822edf923d0
|
guid: 5c4901279eafb874a897edf876b30def
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
71
Assets/Accounts/Tests/PlayMode/UserCardTests.cs
Normal file
71
Assets/Accounts/Tests/PlayMode/UserCardTests.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the UserCard class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class UserCardTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the tests
|
||||||
|
/// </summary>
|
||||||
|
[UnitySetUp]
|
||||||
|
public IEnumerator Setup_UserCard()
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string oneUser = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"Tester0\",\"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();
|
||||||
|
|
||||||
|
SystemController.GetInstance().SwapScene("Accounts/Scenes/ChangeUserScreen");
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<UserCard>();
|
||||||
|
Assert.IsNotNull(card);
|
||||||
|
Assert.IsNotNull(card.user);
|
||||||
|
Assert.IsNotNull(card.button);
|
||||||
|
Assert.IsNotNull(card.avatar);
|
||||||
|
Assert.IsNotNull(card.username);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the card is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_Start()
|
||||||
|
{
|
||||||
|
var card = GameObject.FindObjectOfType<UserCard>();
|
||||||
|
Assert.AreEqual(card.user.GetAvatar(), card.avatar.sprite);
|
||||||
|
Assert.AreEqual(card.user.GetUsername(), card.username.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
11
Assets/Accounts/Tests/PlayMode/UserCardTests.cs.meta
Normal file
11
Assets/Accounts/Tests/PlayMode/UserCardTests.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a9cd2a546e38bc4ba1ba66f5f9c8f71
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
172
Assets/Accounts/Tests/PlayMode/UserCreationScreenTests.cs
Normal file
172
Assets/Accounts/Tests/PlayMode/UserCreationScreenTests.cs
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the UserCreationScreen class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class UserCreationScreenTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the UserCreationScreen tests
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Setup_UserCreationScreen(string startScreen = "Accounts/Scenes/UserCreationScreen")
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string oneUser = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"Tester0\",\"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();
|
||||||
|
|
||||||
|
SystemController.GetInstance().SwapScene(startScreen);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen();
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
Assert.IsNotNull(userCreationController);
|
||||||
|
Assert.IsNotNull(userCreationController.errorMessage);
|
||||||
|
Assert.IsNotNull(userCreationController.inputName);
|
||||||
|
Assert.IsNotNull(userCreationController.avatarsContainer);
|
||||||
|
Assert.IsNotNull(userCreationController.avatarPrefab);
|
||||||
|
Assert.IsNotNull(userCreationController.backButton);
|
||||||
|
Assert.IsTrue(UserCreationScreen.canGoBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the screen is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_Start()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen();
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
Assert.IsFalse(userCreationController.errorMessage.activeSelf);
|
||||||
|
Assert.IsTrue(userCreationController.backButton.activeSelf);
|
||||||
|
|
||||||
|
var avatars = userCreationController.avatarsContainer.GetComponentsInChildren<Button>().ToList()
|
||||||
|
.ConvertAll((b) => b.GetComponentsInChildren<Image>().Except(b.GetComponents<Image>()).First());
|
||||||
|
|
||||||
|
Assert.AreEqual(UserList.AVATARS.Count, avatars.Count);
|
||||||
|
for (int i = 0; i < avatars.Count; i++)
|
||||||
|
Assert.AreEqual(UserList.AVATARS[i], avatars[i].sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the screen is correctly initialized (from invalid savefile)
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_Start_InvalidSavefile()
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
File.Delete(path);
|
||||||
|
PersistentDataController.PATH = path;
|
||||||
|
PersistentDataController.GetInstance().Load();
|
||||||
|
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||||
|
|
||||||
|
SystemController.GetInstance().SwapScene("Common/Scenes/Boot");
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
Assert.IsNotNull(userCreationController);
|
||||||
|
Assert.IsFalse(userCreationController.backButton.activeSelf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a new user can be created
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_CreateUser_Valid()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen("Common/Scenes/MainMenuScreen");
|
||||||
|
|
||||||
|
SystemController.GetInstance().LoadNextScene("Accounts/Scenes/UserCreationScreen");
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
userCreationController.inputName.text = "newTester";
|
||||||
|
userCreationController.CreateUser();
|
||||||
|
Assert.IsFalse(userCreationController.errorMessage.activeSelf);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex("Common/Scenes/MainMenuScreen"), SystemController.GetInstance().currentScene);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether no new user is created when the username is too long
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_CreateUser_UsernameTooLong()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen();
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
userCreationController.inputName.text = "aninvalidsuperduperlongusername";
|
||||||
|
userCreationController.CreateUser();
|
||||||
|
Assert.IsTrue(userCreationController.errorMessage.activeSelf);
|
||||||
|
Assert.AreEqual("Je gebruikersnaam moet bestaan uit minimum 1 en maximum 12 letters (a-z en A-Z) of cijfers (0-9).", userCreationController.errorMessage.GetComponent<TMP_Text>().text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether no new user is created when the username contains invalid characters
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_CreateUser_UsernameInvalidChars()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen();
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
userCreationController.inputName.text = "! an invalid username !";
|
||||||
|
userCreationController.CreateUser();
|
||||||
|
Assert.IsTrue(userCreationController.errorMessage.activeSelf);
|
||||||
|
Assert.AreEqual("Je gebruikersnaam moet bestaan uit minimum 1 en maximum 12 letters (a-z en A-Z) of cijfers (0-9).", userCreationController.errorMessage.GetComponent<TMP_Text>().text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether no new user is created when the username already exists
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_CreateUser_UsernameAlreadyExists()
|
||||||
|
{
|
||||||
|
yield return Setup_UserCreationScreen();
|
||||||
|
|
||||||
|
var userCreationController = GameObject.FindObjectOfType<UserCreationScreen>();
|
||||||
|
userCreationController.inputName.text = "Tester0";
|
||||||
|
userCreationController.CreateUser();
|
||||||
|
Assert.IsTrue(userCreationController.errorMessage.activeSelf);
|
||||||
|
Assert.AreEqual("Deze gebruikersnaam bestaat al! Kies een andere.", userCreationController.errorMessage.GetComponent<TMP_Text>().text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2f151a9a85fa2ce41953b3ad00ebb167
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
194
Assets/Accounts/Tests/PlayMode/UserProgressScreenTests.cs
Normal file
194
Assets/Accounts/Tests/PlayMode/UserProgressScreenTests.cs
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the UserProgressScreen class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class UserProgressScreenTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setup the UserProgressScreen tests
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerator Setup_UserProgressScreen(bool progress = true)
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string course = "{\"entries\":[],\"courseIndex\":0,\"progress\":0.03846153989434242,\"completedLearnables\":1,\"inUseLearnables\":7,\"totalLearnables\":26,\"learnables\":[{\"entries\":[],\"index\":0,\"inUse\":true,\"name\":\"A\",\"progress\":3.0},{\"entries\":[],\"index\":1,\"inUse\":true,\"name\":\"B\",\"progress\":4.5},{\"entries\":[],\"index\":2,\"inUse\":true,\"name\":\"C\",\"progress\":1.5},{\"entries\":[],\"index\":3,\"inUse\":true,\"name\":\"D\",\"progress\":1.5},{\"entries\":[],\"index\":4,\"inUse\":true,\"name\":\"E\",\"progress\":1.5},{\"entries\":[],\"index\":5,\"inUse\":true,\"name\":\"F\",\"progress\":1.5},{\"entries\":[],\"index\":6,\"inUse\":true,\"name\":\"G\",\"progress\":0.0},{\"entries\":[],\"index\":7,\"inUse\":false,\"name\":\"H\",\"progress\":0.0},{\"entries\":[],\"index\":8,\"inUse\":false,\"name\":\"I\",\"progress\":0.0},{\"entries\":[],\"index\":9,\"inUse\":false,\"name\":\"J\",\"progress\":0.0},{\"entries\":[],\"index\":10,\"inUse\":false,\"name\":\"K\",\"progress\":0.0},{\"entries\":[],\"index\":11,\"inUse\":false,\"name\":\"L\",\"progress\":0.0},{\"entries\":[],\"index\":12,\"inUse\":false,\"name\":\"M\",\"progress\":0.0},{\"entries\":[],\"index\":13,\"inUse\":false,\"name\":\"N\",\"progress\":0.0},{\"entries\":[],\"index\":14,\"inUse\":false,\"name\":\"O\",\"progress\":0.0},{\"entries\":[],\"index\":15,\"inUse\":false,\"name\":\"P\",\"progress\":0.0},{\"entries\":[],\"index\":16,\"inUse\":false,\"name\":\"Q\",\"progress\":0.0},{\"entries\":[],\"index\":17,\"inUse\":false,\"name\":\"R\",\"progress\":0.0},{\"entries\":[],\"index\":18,\"inUse\":false,\"name\":\"S\",\"progress\":0.0},{\"entries\":[],\"index\":19,\"inUse\":false,\"name\":\"T\",\"progress\":0.0},{\"entries\":[],\"index\":20,\"inUse\":false,\"name\":\"U\",\"progress\":0.0},{\"entries\":[],\"index\":21,\"inUse\":false,\"name\":\"V\",\"progress\":0.0},{\"entries\":[],\"index\":22,\"inUse\":false,\"name\":\"W\",\"progress\":0.0},{\"entries\":[],\"index\":23,\"inUse\":false,\"name\":\"X\",\"progress\":0.0},{\"entries\":[],\"index\":24,\"inUse\":false,\"name\":\"Y\",\"progress\":0.0},{\"entries\":[],\"index\":25,\"inUse\":false,\"name\":\"Z\",\"progress\":0.0}]}";
|
||||||
|
string minigame = "{\"entries\":[],\"minigameIndex\":1,\"latestScores\":[{\"scoreValue\":70,\"time\":\"19/04/2023 22:32:39\"},{\"scoreValue\":55,\"time\":\"20/04/2023 11:50:10\"},{\"scoreValue\":55,\"time\":\"20/04/2023 13:27:15\"}],\"highestScores\":[{\"scoreValue\":70,\"time\":\"19/04/2023 22:32:39\"},{\"scoreValue\":55,\"time\":\"20/04/2023 11:50:10\"},{\"scoreValue\":55,\"time\":\"20/04/2023 13:27:15\"}]}";
|
||||||
|
if (!progress) course = minigame = "";
|
||||||
|
string oneUser = $"{{\"version\":1027,\"users\":[{{\"entries\":[],\"username\":\"Tester0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[{minigame}],\"courses\":[{course}]}}],\"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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleanup after testing
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_ChangeUserScreen()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether every item that needs to be assign in the editor, is assigned
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_EditorAssignments()
|
||||||
|
{
|
||||||
|
yield return Setup_UserProgressScreen();
|
||||||
|
|
||||||
|
var userProgressController = GameObject.FindObjectOfType<UserProgressScreen>();
|
||||||
|
Assert.IsNotNull(userProgressController.username);
|
||||||
|
Assert.IsNotNull(userProgressController.avatar);
|
||||||
|
Assert.IsNotNull(userProgressController.playtime);
|
||||||
|
Assert.IsNotNull(userProgressController.highscoreMarker);
|
||||||
|
Assert.IsNotNull(userProgressController.courseCardPrefab);
|
||||||
|
Assert.IsNotNull(userProgressController.coursesContainer);
|
||||||
|
Assert.IsNotNull(userProgressController.emptyCourses);
|
||||||
|
Assert.IsNotNull(userProgressController.minigameCardPrefab);
|
||||||
|
Assert.IsNotNull(userProgressController.minigamesContainer);
|
||||||
|
Assert.IsNotNull(userProgressController.emptyMinigames);
|
||||||
|
Assert.IsNotNull(userProgressController.progressGraph);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the screen is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_Start_NoProgress()
|
||||||
|
{
|
||||||
|
yield return Setup_UserProgressScreen(false);
|
||||||
|
|
||||||
|
var userProgressController = GameObject.FindObjectOfType<UserProgressScreen>();
|
||||||
|
var user = UserList.GetCurrentUser();
|
||||||
|
|
||||||
|
Assert.AreEqual(user.GetUsername(), userProgressController.username.text);
|
||||||
|
Assert.AreEqual(user.GetAvatar(), userProgressController.avatar.sprite);
|
||||||
|
Assert.AreEqual($"Totale speeltijd: {user.GetPlaytime().ToString("0.00")}", userProgressController.playtime.text);
|
||||||
|
|
||||||
|
Assert.IsFalse(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
|
||||||
|
Assert.IsTrue(userProgressController.emptyCourses.gameObject.activeSelf);
|
||||||
|
Assert.IsFalse(userProgressController.coursesContainer.gameObject.activeSelf);
|
||||||
|
Assert.Zero(GameObject.FindObjectsOfType<CourseProgressCard>().Length);
|
||||||
|
|
||||||
|
Assert.IsTrue(userProgressController.emptyMinigames.gameObject.activeSelf);
|
||||||
|
Assert.IsFalse(userProgressController.minigamesContainer.gameObject.activeSelf);
|
||||||
|
Assert.Zero(GameObject.FindObjectsOfType<MinigameProgressCard>().Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the screen is correctly initialized
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_Start_WithProgress()
|
||||||
|
{
|
||||||
|
yield return Setup_UserProgressScreen();
|
||||||
|
|
||||||
|
var userProgressController = GameObject.FindObjectOfType<UserProgressScreen>();
|
||||||
|
var user = UserList.GetCurrentUser();
|
||||||
|
|
||||||
|
Assert.AreEqual(user.GetUsername(), userProgressController.username.text);
|
||||||
|
Assert.AreEqual(user.GetAvatar(), userProgressController.avatar.sprite);
|
||||||
|
Assert.AreEqual($"Totale speeltijd: {user.GetPlaytime().ToString("0.00")}", userProgressController.playtime.text);
|
||||||
|
|
||||||
|
Assert.IsFalse(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
|
||||||
|
Assert.IsFalse(userProgressController.emptyCourses.gameObject.activeSelf);
|
||||||
|
Assert.IsTrue(userProgressController.coursesContainer.gameObject.activeSelf);
|
||||||
|
var courses = GameObject.FindObjectsOfType<CourseProgressCard>().ToList();
|
||||||
|
Assert.AreEqual(user.GetCourses().Count, courses.Count);
|
||||||
|
foreach (var course in courses)
|
||||||
|
Assert.AreEqual(Color.gray, course.GetComponent<Image>().color);
|
||||||
|
|
||||||
|
Assert.IsFalse(userProgressController.emptyMinigames.gameObject.activeSelf);
|
||||||
|
Assert.IsTrue(userProgressController.minigamesContainer.gameObject.activeSelf);
|
||||||
|
var minigames = GameObject.FindObjectsOfType<MinigameProgressCard>().ToList();
|
||||||
|
Assert.AreEqual(user.GetMinigames().Count, minigames.Count);
|
||||||
|
foreach (var minigame in minigames)
|
||||||
|
Assert.AreEqual(Color.gray, minigame.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether we can select a course
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UpdateSelection_Course()
|
||||||
|
{
|
||||||
|
yield return Setup_UserProgressScreen();
|
||||||
|
|
||||||
|
var userProgressController = GameObject.FindObjectOfType<UserProgressScreen>();
|
||||||
|
var course = GameObject.FindObjectOfType<CourseProgressCard>();
|
||||||
|
var minigame = GameObject.FindObjectOfType<MinigameProgressCard>();
|
||||||
|
Assert.IsFalse(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
Assert.AreEqual(Color.gray, course.GetComponent<Image>().color);
|
||||||
|
Assert.AreEqual(Color.gray, minigame.GetComponent<Image>().color);
|
||||||
|
|
||||||
|
course.selectActivity.Invoke();
|
||||||
|
Assert.IsFalse(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
Assert.AreEqual(Color.blue, course.GetComponent<Image>().color);
|
||||||
|
Assert.AreEqual(Color.gray, minigame.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether we can select a minigame
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_UpdateSelection_Minigame()
|
||||||
|
{
|
||||||
|
yield return Setup_UserProgressScreen();
|
||||||
|
|
||||||
|
var userProgressController = GameObject.FindObjectOfType<UserProgressScreen>();
|
||||||
|
var course = GameObject.FindObjectOfType<CourseProgressCard>();
|
||||||
|
var minigame = GameObject.FindObjectOfType<MinigameProgressCard>();
|
||||||
|
Assert.IsFalse(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
Assert.AreEqual(Color.gray, course.GetComponent<Image>().color);
|
||||||
|
Assert.AreEqual(Color.gray, minigame.GetComponent<Image>().color);
|
||||||
|
|
||||||
|
minigame.selectActivity.Invoke();
|
||||||
|
Assert.IsTrue(userProgressController.progressGraph.gameObject.activeSelf);
|
||||||
|
Assert.AreEqual(Color.gray, course.GetComponent<Image>().color);
|
||||||
|
Assert.AreEqual(Color.blue, minigame.GetComponent<Image>().color);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the course graph is correctly displayed
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Code is not implemented yet</remarks>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_DisplayCourseGraph()
|
||||||
|
{
|
||||||
|
// TODO: not implemented yet
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the minigame graph is correctly displayed
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Code is not implemented yet</remarks>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_DisplayMinigameGraph()
|
||||||
|
{
|
||||||
|
// TODO: not implemented yet
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2f185e2e48bd67e4587fd36aeb2638fd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -19,7 +19,7 @@ public class PersistentDataController
|
|||||||
/// Current implementation version of the PersistentDataController
|
/// Current implementation version of the PersistentDataController
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>MSB represent sprint version, LSB represent subversion</remarks>
|
/// <remarks>MSB represent sprint version, LSB represent subversion</remarks>
|
||||||
public static readonly int VERSION = 0x04_03;
|
public const int VERSION = 0x04_03;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Path of the <c>.json</c>-file to store all serialized data
|
/// Path of the <c>.json</c>-file to store all serialized data
|
||||||
@@ -194,28 +194,19 @@ public class PersistentDataController
|
|||||||
{
|
{
|
||||||
SavedLearnableProgress learnable = learnables.Find(l => l.name == learnableName);
|
SavedLearnableProgress learnable = learnables.Find(l => l.name == learnableName);
|
||||||
if (learnable == null)
|
if (learnable == null)
|
||||||
{
|
throw new KeyNotFoundException();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the progress value of the SavedLearnableProgress
|
// Update the progress value of the SavedLearnableProgress
|
||||||
learnable.progress += addValue;
|
learnable.progress += addValue;
|
||||||
// crop the learnable progress around -5 and 5
|
// crop the learnable progress around -5 and 5
|
||||||
if (learnable.progress > 5.0f)
|
if (learnable.progress > 5.0f)
|
||||||
{
|
|
||||||
learnable.progress = 5.0f;
|
learnable.progress = 5.0f;
|
||||||
}
|
|
||||||
else if (learnable.progress < -5.0f)
|
else if (learnable.progress < -5.0f)
|
||||||
{
|
|
||||||
learnable.progress = -5.0f;
|
learnable.progress = -5.0f;
|
||||||
}
|
|
||||||
|
|
||||||
// if learnable progress is big enough it is "completed"
|
// if learnable progress is big enough it is "completed"
|
||||||
|
|
||||||
if (learnable.progress > 3)
|
if (learnable.progress > 3)
|
||||||
{
|
|
||||||
completedLearnables++;
|
completedLearnables++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -239,16 +230,15 @@ public class PersistentDataController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// find learnable in learnables which is not yet in use, and set it active
|
/// Find learnable in learnables which is not yet in use, and set it active
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns> bool which indicates the success of the function </returns>
|
/// <returns> SavedLearnableProgress learnable </returns>
|
||||||
public SavedLearnableProgress AddNewLearnable()
|
private SavedLearnableProgress UseUnusedLearnable()
|
||||||
{
|
{
|
||||||
SavedLearnableProgress learnable = learnables.Find(l => !l.inUse);
|
SavedLearnableProgress learnable = learnables.Find(l => !l.inUse);
|
||||||
if (learnable == null)
|
if (learnable == null)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
learnable.inUse = true;
|
learnable.inUse = true;
|
||||||
inUseLearnables++;
|
inUseLearnables++;
|
||||||
return learnable;
|
return learnable;
|
||||||
@@ -261,23 +251,17 @@ public class PersistentDataController
|
|||||||
public SavedLearnableProgress GetRandomLearnable()
|
public SavedLearnableProgress GetRandomLearnable()
|
||||||
{
|
{
|
||||||
if (!EnoughLearnables())
|
if (!EnoughLearnables())
|
||||||
{
|
return UseUnusedLearnable();
|
||||||
return AddNewLearnable();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// only select inUse learnables which are not yet completed (progress < 3.5f)
|
|
||||||
List<SavedLearnableProgress> inUseLearnables = learnables.FindAll(l => l.inUse && l.progress <= 3.5f);
|
|
||||||
|
|
||||||
if (inUseLearnables.Count == 0)
|
// only select inUse learnables which are not yet completed (progress < 3.5f)
|
||||||
{
|
List<SavedLearnableProgress> inUseLearnables = learnables.FindAll(l => l.inUse && l.progress <= 3.5f);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select a random index from the in-use learnables list
|
if (inUseLearnables.Count == 0)
|
||||||
int randomIndex = UnityEngine.Random.Range(0, inUseLearnables.Count);
|
return null;
|
||||||
return inUseLearnables[randomIndex];
|
|
||||||
}
|
// Select a random index from the in-use learnables list
|
||||||
|
int randomIndex = UnityEngine.Random.Range(0, inUseLearnables.Count);
|
||||||
|
return inUseLearnables[randomIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -356,7 +340,7 @@ public class PersistentDataController
|
|||||||
public static PersistentDataController GetInstance()
|
public static PersistentDataController GetInstance()
|
||||||
{
|
{
|
||||||
// Create a new instance if non exists
|
// Create a new instance if non exists
|
||||||
if (instance == null)
|
if (instance == null || PATH == null)
|
||||||
{
|
{
|
||||||
if (PATH == null)
|
if (PATH == null)
|
||||||
PersistentDataController.PATH = $"{Application.persistentDataPath}/wesign_saved_data.json";
|
PersistentDataController.PATH = $"{Application.persistentDataPath}/wesign_saved_data.json";
|
||||||
@@ -43,6 +43,11 @@ public class SystemController
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the number of passively 'active' scenes
|
||||||
|
/// </summary>
|
||||||
|
public int GetSceneStackSize() { return sceneStack.Count; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load the scene and push on the stack
|
/// Load the scene and push on the stack
|
||||||
/// </summary>
|
/// </summary>
|
||||||
8
Assets/Architecture/Tests/EditMode.meta
Normal file
8
Assets/Architecture/Tests/EditMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 05ae9a4f64d7f5049b18346b8277e525
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "ArchitectureEditMode",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"UnityEditor.TestRunner",
|
||||||
|
"UnityEngine.TestRunner",
|
||||||
|
"ArchitectureScripts"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": false,
|
||||||
|
"overrideReferences": true,
|
||||||
|
"precompiledReferences": [
|
||||||
|
"nunit.framework.dll"
|
||||||
|
],
|
||||||
|
"autoReferenced": false,
|
||||||
|
"defineConstraints": [
|
||||||
|
"UNITY_INCLUDE_TESTS"
|
||||||
|
],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NUnit.Framework.Internal;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the PersistentDataController class
|
||||||
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class PersistentDataTests
|
public class PersistentDataControllerTests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new path so the existing .json file will not be overwritten
|
/// Create a new path so the existing .json file will not be overwritten
|
||||||
@@ -41,16 +44,24 @@ public class PersistentDataTests
|
|||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup_PersistentDataController()
|
public void Setup_PersistentDataController()
|
||||||
{
|
{
|
||||||
PersistentDataController.PATH = PersistentDataTests.PATH;
|
Assert.IsNull(PersistentDataController.PATH);
|
||||||
//PersistentDataController.PATH = null;
|
PersistentDataController.PATH = PersistentDataControllerTests.PATH;
|
||||||
pdc = PersistentDataController.GetInstance();
|
pdc = PersistentDataController.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_PersistentDataController()
|
||||||
|
{
|
||||||
|
PersistentDataController.PATH = null;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_PersistentDataController_GetInstance()
|
public void Test_PersistentDataController_GetInstance()
|
||||||
{
|
{
|
||||||
Assert.IsNotNull(pdc);
|
PersistentDataController.PATH = null;
|
||||||
//Assert.AreEqual($"{Application.persistentDataPath}/wesign_saved_data.json", PersistentDataController.PATH);
|
Assert.IsNotNull(PersistentDataController.GetInstance());
|
||||||
|
Assert.AreEqual(0x04_03, PersistentDataController.VERSION);
|
||||||
|
Assert.AreEqual($"{Application.persistentDataPath}/wesign_saved_data.json", PersistentDataController.PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -72,7 +83,7 @@ public class PersistentDataTests
|
|||||||
FileAssert.Exists(PATH);
|
FileAssert.Exists(PATH);
|
||||||
|
|
||||||
string content = File.ReadAllText(PATH);
|
string content = File.ReadAllText(PATH);
|
||||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
Assert.AreEqual(expected, content);
|
Assert.AreEqual(expected, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,14 +99,14 @@ public class PersistentDataTests
|
|||||||
FileAssert.Exists(PATH);
|
FileAssert.Exists(PATH);
|
||||||
|
|
||||||
string content = File.ReadAllText(PATH);
|
string content = File.ReadAllText(PATH);
|
||||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
Assert.AreEqual(expected, content);
|
Assert.AreEqual(expected, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_PersistentDataController_Load_Existing()
|
public void Test_PersistentDataController_Load_Existing()
|
||||||
{
|
{
|
||||||
string content = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string content = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
File.WriteAllText(PATH, content);
|
File.WriteAllText(PATH, content);
|
||||||
Assert.IsTrue(pdc.Load(false));
|
Assert.IsTrue(pdc.Load(false));
|
||||||
}
|
}
|
||||||
@@ -103,7 +114,7 @@ public class PersistentDataTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void Test_PersistentDataController_Load_OlderVersion()
|
public void Test_PersistentDataController_Load_OlderVersion()
|
||||||
{
|
{
|
||||||
string content = $"{{\"version\":{PersistentDataController.VERSION - 1},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string content = "{\"version\":1026,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
File.WriteAllText(PATH, content);
|
File.WriteAllText(PATH, content);
|
||||||
Assert.IsFalse(pdc.Load(false));
|
Assert.IsFalse(pdc.Load(false));
|
||||||
}
|
}
|
||||||
@@ -111,7 +122,7 @@ public class PersistentDataTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void Test_PersistentDataController_Load_NewerVersion()
|
public void Test_PersistentDataController_Load_NewerVersion()
|
||||||
{
|
{
|
||||||
string content = $"{{\"version\":{PersistentDataController.VERSION + 1},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string content = "{\"version\":1028,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
File.WriteAllText(PATH, content);
|
File.WriteAllText(PATH, content);
|
||||||
Assert.IsFalse(pdc.Load(false));
|
Assert.IsFalse(pdc.Load(false));
|
||||||
}
|
}
|
||||||
@@ -139,7 +150,7 @@ public class PersistentDataTests
|
|||||||
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
||||||
Assert.IsFalse(pdc.Load(true));
|
Assert.IsFalse(pdc.Load(true));
|
||||||
string content = File.ReadAllText(PATH);
|
string content = File.ReadAllText(PATH);
|
||||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
Assert.AreEqual(expected, content);
|
Assert.AreEqual(expected, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +174,7 @@ public class PersistentDataTests
|
|||||||
|
|
||||||
pdc.AddUser(d);
|
pdc.AddUser(d);
|
||||||
string content = File.ReadAllText(PATH);
|
string content = File.ReadAllText(PATH);
|
||||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"username\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
string expected = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"username\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||||
Assert.AreEqual(expected, content);
|
Assert.AreEqual(expected, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,156 +625,153 @@ public class PersistentDataTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_AddLearnable_AddsLearnable()
|
public void Test_SavedCourseProgress_AddLearnable_Valid()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
Assert.Zero(progress.learnables.Count);
|
||||||
|
|
||||||
bool added = progress.AddLearnable("test learnable", 0);
|
bool added = progress.AddLearnable("learnable", 0);
|
||||||
|
|
||||||
Assert.IsTrue(added);
|
Assert.IsTrue(added);
|
||||||
Assert.AreEqual(progress.learnables.Count, 1);
|
Assert.AreEqual(1, progress.learnables.Count);
|
||||||
Assert.AreEqual(progress.learnables[0].name, "test learnable");
|
Assert.AreEqual("learnable", progress.learnables[0].name);
|
||||||
Assert.AreEqual(progress.learnables[0].index, 0);
|
Assert.AreEqual(0, progress.FindLearnable("learnable").index);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_AddLearnable_FailsWithDuplicateName()
|
public void Test_SavedCourseProgress_AddLearnable_DuplicateName()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
progress.AddLearnable("test learnable", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
|
|
||||||
bool added = progress.AddLearnable("test learnable", 1);
|
Assert.AreEqual(1, progress.learnables.Count);
|
||||||
|
Assert.IsFalse(progress.AddLearnable("learnable", 1));
|
||||||
Assert.IsFalse(added);
|
Assert.AreEqual(1, progress.learnables.Count);
|
||||||
Assert.AreEqual(progress.learnables.Count, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_AddLearnable_FailsWithDuplicateIndex()
|
public void Test_SavedCourseProgress_AddLearnable_DuplicateIndex()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
progress.AddLearnable("test learnable", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
|
|
||||||
bool added = progress.AddLearnable("test learnable 2", 0);
|
Assert.AreEqual(1, progress.learnables.Count);
|
||||||
|
Assert.IsFalse(progress.AddLearnable("LEARNABLE", 0));
|
||||||
Assert.IsFalse(added);
|
Assert.AreEqual(1, progress.learnables.Count);
|
||||||
Assert.AreEqual(progress.learnables.Count, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_UpdateLearnable_UpdatesProgress()
|
public void Test_SavedCourseProgress_UpdateLearnable_InvalidName()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
progress.AddLearnable("test learnable", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
|
Assert.AreEqual(0.0f, progress.FindLearnable("learnable").progress);
|
||||||
|
Assert.Throws<KeyNotFoundException>(delegate { progress.UpdateLearnable("LEARNABLE", 3.0f); });
|
||||||
|
Assert.AreEqual(0.0f, progress.FindLearnable("learnable").progress);
|
||||||
|
}
|
||||||
|
|
||||||
progress.UpdateLearnable("test learnable", 3.0f);
|
|
||||||
|
|
||||||
Assert.AreEqual(progress.learnables[0].progress, 3.0f);
|
[Test]
|
||||||
|
public void Test_SavedCourseProgress_UpdateLearnable_UpdatesProgress()
|
||||||
|
{
|
||||||
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
|
progress.AddLearnable("learnable", 0);
|
||||||
|
Assert.AreEqual(0.0f, progress.FindLearnable("learnable").progress);
|
||||||
|
progress.UpdateLearnable("learnable", 3.0f);
|
||||||
|
Assert.AreEqual(3.0f, progress.FindLearnable("learnable").progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_UpdateLearnable_CropsProgressAtFive()
|
public void Test_SavedCourseProgress_UpdateLearnable_CropsProgressAtFive()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
progress.AddLearnable("test learnable", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
|
Assert.AreEqual(0, progress.completedLearnables);
|
||||||
progress.UpdateLearnable("test learnable", 10.0f);
|
progress.UpdateLearnable("learnable", 10.0f);
|
||||||
|
Assert.AreEqual(5.0f, progress.FindLearnable("learnable").progress);
|
||||||
Assert.AreEqual(progress.learnables[0].progress, 5.0f);
|
Assert.AreEqual(1, progress.completedLearnables);
|
||||||
Assert.AreEqual(progress.completedLearnables, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_UpdateLearnable_CropsProgressAtNegativeFive()
|
public void Test_SavedCourseProgress_UpdateLearnable_CropsProgressAtNegativeFive()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
|
||||||
progress.AddLearnable("test learnable", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
|
Assert.AreEqual(0, progress.completedLearnables);
|
||||||
progress.UpdateLearnable("test learnable", -10.0f);
|
progress.UpdateLearnable("learnable", -10.0f);
|
||||||
|
Assert.AreEqual(-5.0f, progress.FindLearnable("learnable").progress);
|
||||||
Assert.AreEqual(progress.learnables[0].progress, -5.0f);
|
Assert.AreEqual(0, progress.completedLearnables);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_FindLearnable_ReturnsNullWhenNotFound()
|
public void Test_SavedCourseProgress_FindLearnable()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
progress.AddLearnable("test learnable 1", 0);
|
progress.AddLearnable("learnable 1", 0);
|
||||||
progress.AddLearnable("test learnable 2", 1);
|
|
||||||
|
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.FindLearnable("not found");
|
Assert.IsNull(progress.FindLearnable("learnable 2"));
|
||||||
|
progress.AddLearnable("learnable 2", 1);
|
||||||
Assert.IsNull(learnable);
|
Assert.IsNotNull(progress.FindLearnable("learnable 2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_FindLearnable_ReturnsLearnableByName()
|
public void Test_SavedCourseProgress_GetRandomLearnable_NoLearnables()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
progress.AddLearnable("test learnable 1", 0);
|
Assert.IsNull(progress.GetRandomLearnable());
|
||||||
progress.AddLearnable("test learnable 2", 1);
|
|
||||||
|
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.FindLearnable("test learnable 2");
|
|
||||||
|
|
||||||
Assert.AreEqual(learnable.index, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_AddNewLearnable_ReturnsFalseWhenNoUnusedLearnables()
|
public void Test_SavedCourseProgress_GetRandomLearnable_NoUnusedLearnables()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
progress.AddLearnable("test learnable 1", 0);
|
progress.AddLearnable("learnable", 0);
|
||||||
progress.learnables[0].inUse = true;
|
progress.FindLearnable("learnable").inUse = true;
|
||||||
|
progress.completedLearnables = 1;
|
||||||
|
progress.inUseLearnables = 0;
|
||||||
|
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.AddNewLearnable();
|
Assert.IsNull(progress.GetRandomLearnable());
|
||||||
|
|
||||||
Assert.IsNull(learnable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Test_AddNewLearnable_ReturnsTrueWhenUnusedLearnableFound()
|
public void Test_SavedCourseProgress_GetRandomLearnable_OnlyCompletedLearnables()
|
||||||
{
|
{
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
progress.AddLearnable("test learnable 1", 0);
|
for (int i = 0; i < 2; i++)
|
||||||
progress.AddLearnable("test learnable 2", 1);
|
{
|
||||||
|
progress.AddLearnable($"learnable {i}", i);
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.AddNewLearnable();
|
var learnable = progress.FindLearnable($"learnable {i}");
|
||||||
|
learnable.progress = 4.0f;
|
||||||
Assert.IsNotNull(learnable);
|
learnable.inUse = true;
|
||||||
Assert.AreEqual(progress.inUseLearnables, 1);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Test_GetRandomLearnable_ReturnsNullWhenNoLearnables()
|
|
||||||
{
|
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
|
||||||
|
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.GetRandomLearnable();
|
|
||||||
|
|
||||||
Assert.IsNull(learnable);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Test_GetRandomLearnable_ReturnsNullWhenOnlyCompletedLearnables()
|
|
||||||
{
|
|
||||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
|
||||||
progress.AddLearnable("test learnable 1", 0);
|
|
||||||
progress.AddLearnable("test learnable 2", 1);
|
|
||||||
progress.learnables[0].progress = 4.0f;
|
|
||||||
progress.learnables[0].inUse = true;
|
|
||||||
progress.learnables[1].progress = 4.0f;
|
|
||||||
progress.learnables[1].inUse = true;
|
|
||||||
progress.completedLearnables = 2;
|
progress.completedLearnables = 2;
|
||||||
progress.inUseLearnables = 0;
|
progress.inUseLearnables = 0;
|
||||||
|
|
||||||
PersistentDataController.SavedLearnableProgress learnable = progress.GetRandomLearnable();
|
Assert.IsNull(progress.GetRandomLearnable());
|
||||||
|
}
|
||||||
|
|
||||||
Assert.IsNull(learnable);
|
[Test]
|
||||||
|
public void Test_SavedCourseProgress_GetRandomLearnable_Valid()
|
||||||
|
{
|
||||||
|
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
progress.AddLearnable($"learnable {i}", i);
|
||||||
|
progress.FindLearnable($"learnable {i}").inUse = true;
|
||||||
|
}
|
||||||
|
progress.completedLearnables = 0;
|
||||||
|
progress.inUseLearnables = 10;
|
||||||
|
|
||||||
|
Assert.AreEqual(10, progress.inUseLearnables);
|
||||||
|
Assert.AreEqual(0, progress.completedLearnables);
|
||||||
|
Assert.IsNotNull(progress.GetRandomLearnable());
|
||||||
|
Assert.AreEqual(10, progress.inUseLearnables);
|
||||||
|
Assert.AreEqual(0, progress.completedLearnables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
48
Assets/Architecture/Tests/EditMode/SystemControllerTests.cs
Normal file
48
Assets/Architecture/Tests/EditMode/SystemControllerTests.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the SystemController class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class SystemControllerTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Test_SystemController_GetInstance()
|
||||||
|
{
|
||||||
|
Assert.IsNotNull(SystemController.GetInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_GetSceneIndex_InvalidScene()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(-1, SystemController.GetSceneIndex("a/non/existing/scene"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_GetSceneIndex_ValidScene()
|
||||||
|
{
|
||||||
|
List<string> scenes = new List<string>()
|
||||||
|
{
|
||||||
|
"Common/Scenes/Boot",
|
||||||
|
"Common/Scenes/MainMenuScreen",
|
||||||
|
"Common/Scenes/CoursesMenuScreen",
|
||||||
|
"Common/Scenes/ListCoursesScreen",
|
||||||
|
"Common/Scenes/ListMinigamesScreen",
|
||||||
|
"Common/Scenes/CourseActivityScreen",
|
||||||
|
"Common/Scenes/MinigameActivityScreen",
|
||||||
|
"Common/Scenes/ThemeSelectionScreen",
|
||||||
|
"Common/Scenes/SettingsScreen",
|
||||||
|
"Accounts/Scenes/UserCreationScreen",
|
||||||
|
"Accounts/Scenes/ChangeUserScreen",
|
||||||
|
"Accounts/Scenes/UserProgressScreen",
|
||||||
|
"Courses/Scenes/CourseScreen",
|
||||||
|
"SpellingBee/Scenes/SpellingBeeGame",
|
||||||
|
"Hangman/Scenes/HangmanGame",
|
||||||
|
"JustSign/Scenes/JustSignGame",
|
||||||
|
};
|
||||||
|
Assert.AreEqual(SceneManager.sceneCountInBuildSettings, scenes.Count);
|
||||||
|
// Testing wether the names and indices are correct needs to be done in PlayMode
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 17b5c320c11ddd6439fc5823fc1aaca6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Architecture/Tests/PlayMode.meta
Normal file
8
Assets/Architecture/Tests/PlayMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 865ee232b6fa1184084ab1d58aaba61e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "ArchitecturePlayMode",
|
||||||
|
"rootNamespace": "",
|
||||||
|
"references": [
|
||||||
|
"UnityEditor.TestRunner",
|
||||||
|
"UnityEngine.TestRunner",
|
||||||
|
"ArchitectureScripts",
|
||||||
|
"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: f8ed003d51e12ca44a9b41f98a4f9f3d
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
304
Assets/Architecture/Tests/PlayMode/SystemControllerTests.cs
Normal file
304
Assets/Architecture/Tests/PlayMode/SystemControllerTests.cs
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the SystemController class
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class SystemControllerTests
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wait time between scene transitions
|
||||||
|
/// </summary>
|
||||||
|
private const float WAIT_TIME = 0.2f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reference to the SystemController instance
|
||||||
|
/// </summary>
|
||||||
|
private SystemController controller;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setting up the tests
|
||||||
|
/// </summary>
|
||||||
|
[UnitySetUp]
|
||||||
|
public IEnumerator Setup_SystemController()
|
||||||
|
{
|
||||||
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
|
string oneUser = "{\"version\":1027,\"users\":[{\"entries\":[],\"username\":\"Tester0\",\"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();
|
||||||
|
|
||||||
|
controller = SystemController.GetInstance();
|
||||||
|
controller.LoadNextScene("Common/Scenes/MainMenuScreen");
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleaning up the tests
|
||||||
|
/// </summary>
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown_SystemController()
|
||||||
|
{
|
||||||
|
controller.BackToScene(SceneManager.sceneCountInBuildSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether all scenes are correctly inserted to the build path
|
||||||
|
/// </summary>
|
||||||
|
[Test]
|
||||||
|
public void Test_GetSceneIndex_ValidScene()
|
||||||
|
{
|
||||||
|
List<string> scenes = new List<string>()
|
||||||
|
{
|
||||||
|
"Common/Scenes/Boot",
|
||||||
|
"Common/Scenes/MainMenuScreen",
|
||||||
|
"Common/Scenes/CoursesMenuScreen",
|
||||||
|
"Common/Scenes/ListCoursesScreen",
|
||||||
|
"Common/Scenes/ListMinigamesScreen",
|
||||||
|
"Common/Scenes/CourseActivityScreen",
|
||||||
|
"Common/Scenes/MinigameActivityScreen",
|
||||||
|
"Common/Scenes/ThemeSelectionScreen",
|
||||||
|
"Common/Scenes/SettingsScreen",
|
||||||
|
"Accounts/Scenes/UserCreationScreen",
|
||||||
|
"Accounts/Scenes/ChangeUserScreen",
|
||||||
|
"Accounts/Scenes/UserProgressScreen",
|
||||||
|
"Courses/Scenes/CourseScreen",
|
||||||
|
"SpellingBee/Scenes/SpellingBeeGame",
|
||||||
|
"Hangman/Scenes/HangmanGame",
|
||||||
|
"JustSign/Scenes/JustSignGame",
|
||||||
|
};
|
||||||
|
for (var i = 0; i < scenes.Count; i++)
|
||||||
|
Assert.AreEqual(i, SystemController.GetSceneIndex(scenes[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a next scene can be loaded
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_LoadNextScene_String()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
string previous = "Common/Scenes/MainMenuScreen";
|
||||||
|
string next = "Common/Scenes/CoursesMenuScreen";
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 1, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a next scene can be loaded
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_LoadNextScene_Int()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
int previous = 1;
|
||||||
|
int next = 2;
|
||||||
|
Assert.AreEqual(previous, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(previous, controller.previousScene);
|
||||||
|
Assert.AreEqual(next, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 1, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a scene can be swapped with the current one
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_SwapScene_String()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
string previous = "Common/Scenes/MainMenuScreen";
|
||||||
|
string next = "Common/Scenes/CoursesMenuScreen";
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
controller.SwapScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a scene can be swapped with the current one
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_SwapScene_Int()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
int previous = 1;
|
||||||
|
int next = 2;
|
||||||
|
Assert.AreEqual(previous, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
controller.SwapScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(previous, controller.previousScene);
|
||||||
|
Assert.AreEqual(next, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether the previous scene can be loaded
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToPreviousScene_LoadScene()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
string previous = "Common/Scenes/MainMenuScreen";
|
||||||
|
string current = "Common/Scenes/CoursesMenuScreen";
|
||||||
|
string next = "Common/Scenes/ListCoursesScreen";
|
||||||
|
controller.LoadNextScene(current);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(current), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 2, controller.GetSceneStackSize());
|
||||||
|
controller.BackToPreviousScene();
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(stackSize + 1, controller.GetSceneStackSize());
|
||||||
|
controller.BackToPreviousScene();
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(current), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether when requesting to go back on the ast scene, will close the application
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToPreviousScene_QuitApplication()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
|
||||||
|
controller.BackToPreviousScene();
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
Assert.AreEqual(stackSize - 1, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a previous scene can be loaded
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToScene_String_LoadScene()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
string previous = "Common/Scenes/MainMenuScreen";
|
||||||
|
string current = "Common/Scenes/CoursesMenuScreen";
|
||||||
|
string next = "Common/Scenes/ListCoursesScreen";
|
||||||
|
controller.LoadNextScene(current);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(current), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 2, controller.GetSceneStackSize());
|
||||||
|
controller.BackToScene(previous);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(previous), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether when requesting to go back to scene that is no longer loaded, will close the application
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToScene_String_QuitApplication()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
|
||||||
|
string previous = "Common/Scenes/MainMenuScreen";
|
||||||
|
string current = "Common/Scenes/CoursesMenuScreen";
|
||||||
|
string next = "Common/Scenes/ListCoursesScreen";
|
||||||
|
controller.SwapScene(current);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(current), controller.previousScene);
|
||||||
|
Assert.AreEqual(SystemController.GetSceneIndex(next), controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 1, controller.GetSceneStackSize());
|
||||||
|
controller.BackToScene(previous);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
Assert.AreEqual(stackSize - 1, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether a previous scene can be loaded
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToScene_Int_LoadScene()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
int previous = 1;
|
||||||
|
int current = 2;
|
||||||
|
int next = 3;
|
||||||
|
controller.LoadNextScene(current);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(current, controller.previousScene);
|
||||||
|
Assert.AreEqual(next, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 2, controller.GetSceneStackSize());
|
||||||
|
controller.BackToScene(previous);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(next, controller.previousScene);
|
||||||
|
Assert.AreEqual(previous, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test whether when requesting to go back to scene that is no longer loaded, will close the application
|
||||||
|
/// </summary>
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Test_BackToScene_Int_QuitApplication()
|
||||||
|
{
|
||||||
|
int stackSize = controller.GetSceneStackSize();
|
||||||
|
|
||||||
|
int previous = 1;
|
||||||
|
int current = 2;
|
||||||
|
int next = 3;
|
||||||
|
controller.SwapScene(current);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
controller.LoadNextScene(next);
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
|
||||||
|
Assert.AreEqual(current, controller.previousScene);
|
||||||
|
Assert.AreEqual(next, controller.currentScene);
|
||||||
|
Assert.AreEqual(stackSize + 1, controller.GetSceneStackSize());
|
||||||
|
controller.BackToScene(previous);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(WAIT_TIME);
|
||||||
|
Assert.AreEqual(stackSize - 1, controller.GetSceneStackSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8ede8e90b1ef6144ca9b5e54493894fd
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
8
Assets/Common/Tests/EditMode.meta
Normal file
8
Assets/Common/Tests/EditMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7efafb99e31fdd243b9470c45ec5da7d
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "CommonTests",
|
"name": "CommonEditMode",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// Test the CourseList class
|
/// Test the CourseList class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class CourseListTest
|
public class CourseListTests
|
||||||
{
|
{
|
||||||
private CourseList courseList;
|
private CourseList courseList;
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// Test the MinigameList class
|
/// Test the MinigameList class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class MinigameListTest
|
public class MinigameListTests
|
||||||
{
|
{
|
||||||
private MinigameList minigameList;
|
private MinigameList minigameList;
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// Test the ModelList class
|
/// Test the ModelList class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ModelListTest
|
public class ModelListTests
|
||||||
{
|
{
|
||||||
private ModelList modelList;
|
private ModelList modelList;
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
/// Test the ThemeList class
|
/// Test the ThemeList class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ThemeListTest
|
public class ThemeListTests
|
||||||
{
|
{
|
||||||
private ThemeList themeList;
|
private ThemeList themeList;
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ using UnityEngine;
|
|||||||
/// Test the Theme class
|
/// Test the Theme class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ThemeTest
|
public class ThemeTests
|
||||||
{
|
{
|
||||||
private Theme theme;
|
private Theme theme;
|
||||||
private List<string> names = new List<string>() { "appel", "peer", "banaan" };
|
private List<string> names = new List<string>() { "appel", "peer", "banaan" };
|
||||||
@@ -11,7 +11,7 @@ public class BackButtonTests
|
|||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "CommonPlayModeTests",
|
"name": "CommonPlayMode",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
@@ -11,7 +11,7 @@ public class CourseActivityTests
|
|||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -5,13 +5,13 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.TestTools;
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
public class CourseMenuScreenTest
|
public class CourseMenuScreenTests
|
||||||
{
|
{
|
||||||
|
|
||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -5,13 +5,13 @@ using UnityEditor;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.TestTools;
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
public class ListCoursesScreenTest
|
public class ListCoursesScreenTests
|
||||||
{
|
{
|
||||||
|
|
||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -13,7 +13,7 @@ public class MainMenuScreenTests
|
|||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -12,7 +12,7 @@ public class MiniGameActivityScreenTests
|
|||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -12,7 +12,7 @@ public class StartGamesTests
|
|||||||
[UnityTest]
|
[UnityTest]
|
||||||
public IEnumerator BootWithUsersTest()
|
public IEnumerator BootWithUsersTest()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -54,7 +54,7 @@ public class StartGamesTests
|
|||||||
[UnityTest]
|
[UnityTest]
|
||||||
public IEnumerator BootWithoutUsersTest()
|
public IEnumerator BootWithoutUsersTest()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
string path = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||||
string noUsers = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
string noUsers = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
||||||
|
|
||||||
File.WriteAllText(path, noUsers);
|
File.WriteAllText(path, noUsers);
|
||||||
@@ -12,7 +12,7 @@ public class UserButtonTests
|
|||||||
[UnitySetUp]
|
[UnitySetUp]
|
||||||
public IEnumerator SetupFunction()
|
public IEnumerator SetupFunction()
|
||||||
{
|
{
|
||||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
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\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||||
|
|
||||||
File.WriteAllText(path, oneUser);
|
File.WriteAllText(path, oneUser);
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.TestTools;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
|
|
||||||
public class BasicTests
|
|
||||||
{
|
|
||||||
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
|
||||||
// `yield return null;` to skip a frame.
|
|
||||||
[UnityTest]
|
|
||||||
public IEnumerator BasicTestsWithEnumeratorPasses()
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("CourseScreen");
|
|
||||||
// Use the Assert class to test conditions.
|
|
||||||
// Use yield to skip a frame.
|
|
||||||
yield return null;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var courseObject = GameObject.findGameObjectWithTag("Course");
|
|
||||||
// Assert.IsNotNull(courseObject);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.TestTools;
|
|
||||||
|
|
||||||
public class BasicTests
|
|
||||||
{
|
|
||||||
// A Test behaves as an ordinary method
|
|
||||||
[Test]
|
|
||||||
public void BasicTestsSimplePasses()
|
|
||||||
{
|
|
||||||
// Use the Assert class to test conditions
|
|
||||||
}
|
|
||||||
|
|
||||||
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
|
||||||
// `yield return null;` to skip a frame.
|
|
||||||
[UnityTest]
|
|
||||||
public IEnumerator BasicTestsWithEnumeratorPasses()
|
|
||||||
{
|
|
||||||
// Use the Assert class to test conditions.
|
|
||||||
// Use yield to skip a frame.
|
|
||||||
yield return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8
Assets/Courses/Tests/EditMode.meta
Normal file
8
Assets/Courses/Tests/EditMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7b612bda41dae86458d68ba90d0130d3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "CoursesTests",
|
"name": "CoursesEditMode",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
8
Assets/Courses/Tests/PlayMode.meta
Normal file
8
Assets/Courses/Tests/PlayMode.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 25fe0e709e59ccf45af2c8588d777727
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "PlayModeTests",
|
"name": "CoursesPlayMode",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
"UnityEditor.TestRunner",
|
"UnityEditor.TestRunner",
|
||||||
"ArchitectureScripts"
|
"CourseScripts"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user