Resolve WES-187 "Unit tests account and system"
This commit is contained in:
committed by
Jerome Coudron
parent
c4b6c60288
commit
b9bbef8dcf
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
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a4ef95cbacdca459433eb2ddc05755
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,777 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the PersistentDataController class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class PersistentDataControllerTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new path so the existing .json file will not be overwritten
|
||||
/// </summary>
|
||||
private static string PATH = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the pdc to perform tests on
|
||||
/// </summary>
|
||||
private PersistentDataController pdc = null;
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private struct Struct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable enum to perform test operations on
|
||||
/// </summary>
|
||||
private enum Enum
|
||||
{
|
||||
SQUARE,
|
||||
TRIANBLE,
|
||||
CIRCLE
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup_PersistentDataController()
|
||||
{
|
||||
Assert.IsNull(PersistentDataController.PATH);
|
||||
PersistentDataController.PATH = PersistentDataControllerTests.PATH;
|
||||
pdc = PersistentDataController.GetInstance();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown_PersistentDataController()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetInstance()
|
||||
{
|
||||
PersistentDataController.PATH = null;
|
||||
Assert.IsNotNull(PersistentDataController.GetInstance());
|
||||
Assert.AreEqual(0x04_03, PersistentDataController.VERSION);
|
||||
Assert.AreEqual($"{Application.persistentDataPath}/wesign_saved_data.json", PersistentDataController.PATH);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Clear()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Zero(pdc.GetUsers().Count);
|
||||
Assert.AreEqual(-1, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Save_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Save_New()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
if (File.Exists(PATH))
|
||||
File.Delete(PATH);
|
||||
pdc.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Existing()
|
||||
{
|
||||
string content = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
File.WriteAllText(PATH, content);
|
||||
Assert.IsTrue(pdc.Load(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_OlderVersion()
|
||||
{
|
||||
string content = "{\"version\":1026,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
File.WriteAllText(PATH, content);
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_NewerVersion()
|
||||
{
|
||||
string content = "{\"version\":1028,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
File.WriteAllText(PATH, content);
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_New()
|
||||
{
|
||||
if (File.Exists(PATH))
|
||||
File.Delete(PATH);
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
FileAssert.DoesNotExist(PATH);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Exception()
|
||||
{
|
||||
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
Assert.AreEqual("https://www.youtube.com/watch?v=dQw4w9WgXcQ", File.ReadAllText(PATH));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Override()
|
||||
{
|
||||
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
||||
Assert.IsFalse(pdc.Load(true));
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = "{\"version\":1027,\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Version()
|
||||
{
|
||||
const int VERSION = 0x04_03;
|
||||
Assert.AreEqual(VERSION, PersistentDataController.VERSION);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_AddUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
};
|
||||
|
||||
pdc.AddUser(d);
|
||||
string content = File.ReadAllText(PATH);
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetUsers()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
};
|
||||
|
||||
pdc.AddUser(d);
|
||||
var users = pdc.GetUsers();
|
||||
Assert.AreEqual(1, users.Count);
|
||||
Assert.AreEqual("username", users[0].username);
|
||||
Assert.AreEqual(0, users[0].avatarIndex);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetCurrentUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
Assert.AreEqual(-1, pdc.GetCurrentUser());
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.AreEqual(0, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
});
|
||||
pdc.SetCurrentUser(3);
|
||||
Assert.AreEqual(3, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser_Invalid()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(3); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(0); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_BeforeCurrent()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
}
|
||||
pdc.SetCurrentUser(0);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(0, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Current()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
}
|
||||
pdc.SetCurrentUser(2);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(1, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_AfterCurrent()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
|
||||
}
|
||||
pdc.SetCurrentUser(4);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(3, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Invalid()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(3); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.DeleteUser(0); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentCourse()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentCourse(CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(CourseIndex.FINGERSPELLING, pdc.GetCurrentCourse());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentMinigame()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
|
||||
Assert.AreEqual(MinigameIndex.SPELLING_BEE, pdc.GetCurrentMinigame());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentTheme()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentTheme(ThemeIndex.SIGN_ALPHABET);
|
||||
Assert.AreEqual(ThemeIndex.SIGN_ALPHABET, pdc.GetCurrentTheme());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_New_PersistentDataContainer()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsNotNull(c);
|
||||
Assert.Zero(c.entries.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Set<object>("key", null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_DuplicateKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<int>("key", 123));
|
||||
Assert.IsTrue(c.Set<int>("key", 321));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<int>("key", 123));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<string>("key", "abc"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<Struct>("key", new Struct()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<Enum>("key", new Enum()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_InvalidType()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Struct>("key", new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 });
|
||||
Assert.Throws<InvalidCastException>(delegate { c.Get<int>("key"); });
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<InvalidCastException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_KeyNotFound()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.AreEqual(123, c.Get<int>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
Assert.AreEqual("value", c.Get<string>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
Assert.AreEqual(s, c.Get<Struct>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var e = Enum.CIRCLE;
|
||||
c.Set<Enum>("key", e);
|
||||
Assert.AreEqual(e, c.Get<Enum>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<string>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Enum>("key", Enum.CIRCLE);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Enum>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.AreEqual(123, c.Pop<int>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
Assert.AreEqual("value", c.Pop<string>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<string>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
Assert.AreEqual(s, c.Pop<Struct>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Enum>("key", Enum.CIRCLE);
|
||||
Assert.AreEqual(Enum.CIRCLE, c.Pop<Enum>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Enum>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Has_ValidKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Has("key"));
|
||||
c.Set<int>("key", 123);
|
||||
Assert.IsTrue(c.Has("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Has_InvalidKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Has("KEY"));
|
||||
c.Set<int>("key", 123);
|
||||
Assert.IsFalse(c.Has("KEY"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_AddLearnable_Valid()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
Assert.Zero(progress.learnables.Count);
|
||||
|
||||
bool added = progress.AddLearnable("learnable", 0);
|
||||
Assert.IsTrue(added);
|
||||
Assert.AreEqual(1, progress.learnables.Count);
|
||||
Assert.AreEqual("learnable", progress.learnables[0].name);
|
||||
Assert.AreEqual(0, progress.FindLearnable("learnable").index);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_AddLearnable_DuplicateName()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("learnable", 0);
|
||||
|
||||
Assert.AreEqual(1, progress.learnables.Count);
|
||||
Assert.IsFalse(progress.AddLearnable("learnable", 1));
|
||||
Assert.AreEqual(1, progress.learnables.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_AddLearnable_DuplicateIndex()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("learnable", 0);
|
||||
|
||||
Assert.AreEqual(1, progress.learnables.Count);
|
||||
Assert.IsFalse(progress.AddLearnable("LEARNABLE", 0));
|
||||
Assert.AreEqual(1, progress.learnables.Count);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_UpdateLearnable_InvalidName()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
[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]
|
||||
public void Test_SavedCourseProgress_UpdateLearnable_CropsProgressAtFive()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("learnable", 0);
|
||||
Assert.AreEqual(0, progress.completedLearnables);
|
||||
progress.UpdateLearnable("learnable", 10.0f);
|
||||
Assert.AreEqual(5.0f, progress.FindLearnable("learnable").progress);
|
||||
Assert.AreEqual(1, progress.completedLearnables);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_UpdateLearnable_CropsProgressAtNegativeFive()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("learnable", 0);
|
||||
Assert.AreEqual(0, progress.completedLearnables);
|
||||
progress.UpdateLearnable("learnable", -10.0f);
|
||||
Assert.AreEqual(-5.0f, progress.FindLearnable("learnable").progress);
|
||||
Assert.AreEqual(0, progress.completedLearnables);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_FindLearnable()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("learnable 1", 0);
|
||||
|
||||
Assert.IsNull(progress.FindLearnable("learnable 2"));
|
||||
progress.AddLearnable("learnable 2", 1);
|
||||
Assert.IsNotNull(progress.FindLearnable("learnable 2"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_GetRandomLearnable_NoLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
Assert.IsNull(progress.GetRandomLearnable());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_GetRandomLearnable_NoUnusedLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("learnable", 0);
|
||||
progress.FindLearnable("learnable").inUse = true;
|
||||
progress.completedLearnables = 1;
|
||||
progress.inUseLearnables = 0;
|
||||
|
||||
Assert.IsNull(progress.GetRandomLearnable());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_SavedCourseProgress_GetRandomLearnable_OnlyCompletedLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
progress.AddLearnable($"learnable {i}", i);
|
||||
var learnable = progress.FindLearnable($"learnable {i}");
|
||||
learnable.progress = 4.0f;
|
||||
learnable.inUse = true;
|
||||
}
|
||||
progress.completedLearnables = 2;
|
||||
progress.inUseLearnables = 0;
|
||||
|
||||
Assert.IsNull(progress.GetRandomLearnable());
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56873c5649b881846a54e2a2aa5ce499
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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:
|
||||
Reference in New Issue
Block a user