Resolve WES-113 "Write tests"

This commit is contained in:
Louis Adriaens
2023-03-16 12:36:46 +00:00
committed by Dries Van Schuylenbergh
parent 96fb3c89c3
commit f6e6afe340
78 changed files with 184 additions and 5598 deletions

View File

@@ -0,0 +1,17 @@
{
"name": "AccountsScripts",
"rootNamespace": "",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:df9d7b70293a2e14d9d3a018c3956f7a"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1631ed2680c61245b8211d943c1639a8
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// SystemController singleton
/// </summary>
public class SystemController
{
/// <summary>
/// The instance controlling the singleton
/// </summary>
private static SystemController instance = null;
/// <summary>
/// Stack of the loaded scenes, used to easily go back to previous scenes
/// </summary>
private Stack<int> sceneStack = new Stack<int>();
/// <summary>
/// Get the instance loaded by the singleton
/// </summary>
/// <returns>SystemController instance</returns>
public static SystemController GetInstance()
{
// Create a new instance if non exists
if (instance == null)
{
instance = new SystemController();
instance.sceneStack.Push(SceneManager.GetActiveScene().buildIndex);
}
return instance;
}
/// <summary>
/// Load the scene and push on the stack
/// </summary>
/// <param name="scenePath">Path of the scene</param>
public void LoadNextScene(string scenePath)
{
LoadNextScene(SceneUtility.GetBuildIndexByScenePath(scenePath));
}
/// <summary>
/// Load the scene and push on the stack
/// </summary>
/// <param name="sceneIndex">Buildindex of the scene</param>
public void LoadNextScene(int sceneIndex)
{
sceneStack.Push(sceneIndex);
SceneManager.LoadScene(sceneIndex);
}
/// <summary>
/// Swap the current scene with the new scene on the stack
/// </summary>
/// <param name="scenePath">Path of the scene</param>
public void SwapScene(string scenePath)
{
SwapScene(SceneUtility.GetBuildIndexByScenePath(scenePath));
}
/// <summary>
/// Swap the current scene with the new scene on the stack
/// </summary>
/// <param name="sceneIndex">Buildindex of the scene</param>
public void SwapScene(int sceneIndex)
{
sceneStack.Pop();
LoadNextScene(sceneIndex);
}
/// <summary>
/// Go back to the previous scene and unload the current scene
/// </summary>
public void BackToPreviousScene()
{
sceneStack.Pop();
if (sceneStack.Count > 0) SceneManager.LoadScene(sceneStack.Peek());
else Application.Quit();
}
/// <summary>
/// Go back to a specific scene, unloading all the scenes on the way
/// </summary>
/// <param name="scenePath">Path of the scene</param>
public void BackToScene(string scenePath)
{
BackToScene(SceneUtility.GetBuildIndexByScenePath(scenePath));
}
/// <summary>
/// Go back to a specific scene, unloading all the scene on the way
/// </summary>
/// <param name="sceneIndex">Buildindex of the scene</param>
public void BackToScene(int sceneIndex)
{
while (0 < sceneStack.Count && sceneStack.Peek() != sceneIndex) sceneStack.Pop();
if (sceneStack.Count > 0) SceneManager.LoadScene(sceneStack.Peek());
else Application.Quit();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bf5ea73aa43049e45a0ad926db15f315
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
{
"name": "AccountsTests",
"rootNamespace": "",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"AccountsScripts",
"InterfacesScripts"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll",
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS",
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8500f5aede7627729bd8c97b15e541c4
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,3 +1,4 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
@@ -90,6 +91,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test for creation of a new progress
/// </summary>
[Test]
public void TestNewProgress()
{
Progress progress = new Progress();
@@ -99,6 +101,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether invalid data will not be added
/// </summary>
[Test]
public void TestProgressAddInvalidData()
{
Progress progress = new Progress();
@@ -108,6 +111,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a duplicated key will be added
/// </summary>
[Test]
public void TestProgressAddDuplicateKey()
{
Progress progress = new Progress();
@@ -118,6 +122,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>int</c> value can be added
/// </summary>
[Test]
public void TestProgressAddInt()
{
Progress progress = new Progress();
@@ -127,6 +132,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>double</c> value can be added
/// </summary>
[Test]
public void TestProgressAddDouble()
{
Progress progress = new Progress();
@@ -136,6 +142,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>string</c> value can be added
/// </summary>
[Test]
public void TestProgressAddString()
{
Progress progress = new Progress();
@@ -145,6 +152,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a serializable struct can be added
/// </summary>
[Test]
public void TestProgressAddSerializableStruct()
{
Progress progress = new Progress();
@@ -154,6 +162,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a non-serializable struct will throw an error
/// </summary>
[Test]
public void TestProgressAddNonSerializableStruct()
{
Debug.Assert(AddNonSerializableStruct());
@@ -162,6 +171,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether an invalid key will throw an error
/// </summary>
[Test]
public void TestProgressGetInvalidKey()
{
Debug.Assert(AccessInvalidKey());
@@ -170,6 +180,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether an invalid type will throw an error
/// </summary>
[Test]
public void TestProgressGetInvalidType()
{
Debug.Assert(AccessInvalidType());
@@ -178,6 +189,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a value is correctly updated
/// </summary>
[Test]
public void TestProgressUpdate()
{
Progress progress = new Progress();
@@ -190,6 +202,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>int</c> value can be read
/// </summary>
[Test]
public void TestProgressGetInt()
{
Progress progress = new Progress();
@@ -200,6 +213,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>double</c> value can be read
/// </summary>
[Test]
public void TestProgressGetDouble()
{
Progress progress = new Progress();
@@ -210,6 +224,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a <c>string</c> value can be read
/// </summary>
[Test]
public void TestProgressGetString()
{
Progress progress = new Progress();
@@ -220,6 +235,7 @@ public class TestProgress : MonoBehaviour
/// <summary>
/// Test whether a serializable struct can be read
/// </summary>
[Test]
public void TestProgressGetStruct()
{
Progress progress = new Progress();