Add formatting rules

This commit is contained in:
Dries Van Schuylenbergh
2023-03-10 09:21:11 +00:00
parent 6d762a63f7
commit 26f3322e4e
30 changed files with 975 additions and 160 deletions

View File

@@ -3,24 +3,34 @@ using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
/// <summary>
/// Test the Progress class
/// </summary>
public class TestProgress : MonoBehaviour
{
/// <summary>
/// A dummy serializable struct to perform test operations on
/// </summary>
[Serializable]
// Dummy struct
private struct SerializableStruct
{
public int r, g, b;
public float x, y, z;
}
/// <summary>
/// A dummy non-serializable struct to perform test operations on
/// </summary>
private struct NonSerializableStruct
{
public int r, g, b;
public float x, y, z;
}
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.AddOrUpdate(...)</c> throws a <c>SerializationException</c></returns>
private bool AddNonSerializableStruct()
{
Progress progress = new Progress();
@@ -30,7 +40,10 @@ public class TestProgress : MonoBehaviour
return false;
}
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>KeyNotFoundException</c></returns>
private bool AccessInvalidKey()
{
Progress progress = new Progress();
@@ -39,7 +52,10 @@ public class TestProgress : MonoBehaviour
return false;
}
// Helper method, returns true if `Progress.Get(...)` throws a `InvalidCastException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>InvalidCastException</c></returns>
private bool AccessInvalidType()
{
Progress progress = new Progress();
@@ -49,6 +65,9 @@ public class TestProgress : MonoBehaviour
return false;
}
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestNewProgress();
@@ -68,18 +87,27 @@ public class TestProgress : MonoBehaviour
TestProgressGetStruct();
}
/// <summary>
/// Test for creation of a new progress
/// </summary>
public void TestNewProgress()
{
Progress progress = new Progress();
Debug.Assert(progress != null);
}
/// <summary>
/// Test whether invalid data will not be added
/// </summary>
public void TestProgressAddInvalidData()
{
Progress progress = new Progress();
Debug.Assert(!progress.AddOrUpdate<GameObject>("key", null));
}
/// <summary>
/// Test whether a duplicated key will be added
/// </summary>
public void TestProgressAddDuplicateKey()
{
Progress progress = new Progress();
@@ -87,45 +115,69 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.AddOrUpdate<int>("key 1", 1));
}
/// <summary>
/// Test whether a <c>int</c> value can be added
/// </summary>
public void TestProgressAddInt()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<int>("key", 1));
}
/// <summary>
/// Test whether a <c>double</c> value can be added
/// </summary>
public void TestProgressAddDouble()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<double>("key", 1.0));
}
/// <summary>
/// Test whether a <c>string</c> value can be added
/// </summary>
public void TestProgressAddString()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<string>("key", "Hello World!"));
}
/// <summary>
/// Test whether a serializable struct can be added
/// </summary>
public void TestProgressAddSerializableStruct()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
}
/// <summary>
/// Test whether a non-serializable struct will throw an error
/// </summary>
public void TestProgressAddNonSerializableStruct()
{
Debug.Assert(AddNonSerializableStruct());
}
/// <summary>
/// Test whether an invalid key will throw an error
/// </summary>
public void TestProgressGetInvalidKey()
{
Debug.Assert(AccessInvalidKey());
}
/// <summary>
/// Test whether an invalid type will throw an error
/// </summary>
public void TestProgressGetInvalidType()
{
Debug.Assert(AccessInvalidType());
}
/// <summary>
/// Test whether a value is correctly updated
/// </summary>
public void TestProgressUpdate()
{
Progress progress = new Progress();
@@ -135,6 +187,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<int>("key") == 2);
}
/// <summary>
/// Test whether a <c>int</c> value can be read
/// </summary>
public void TestProgressGetInt()
{
Progress progress = new Progress();
@@ -142,6 +197,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<int>("key") == 1);
}
/// <summary>
/// Test whether a <c>double</c> value can be read
/// </summary>
public void TestProgressGetDouble()
{
Progress progress = new Progress();
@@ -149,6 +207,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<double>("key") == 1.0);
}
/// <summary>
/// Test whether a <c>string</c> value can be read
/// </summary>
public void TestProgressGetString()
{
Progress progress = new Progress();
@@ -156,6 +217,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<string>("key") == "Hello World!");
}
/// <summary>
/// Test whether a serializable struct can be read
/// </summary>
public void TestProgressGetStruct()
{
Progress progress = new Progress();

View File

@@ -0,0 +1,168 @@
using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Test the User class
/// </summary>
public class TestUser : MonoBehaviour
{
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestNewUser();
TestUserAddCourse();
TestUserAddMinigame();
TestGetRecentCoursesEmpty();
TestGetRecentCoursesAll();
TestGetRecommendedCoursesEmpty();
TestGetRecommendedCoursesAll();
TestGetCourseProgressNull();
TestGetCourseProgressValid();
TestGetMinigameProgressNull();
TestGetMinigameProgressValid();
}
/// <summary>
/// Test for the creation of a new user
/// </summary>
public void TestNewUser()
{
User user = new User();
Debug.Assert(user != null);
Debug.Assert(user.courses.Count == 0);
Debug.Assert(user.minigames.Count == 0);
}
/// <summary>
/// Test whether progress on a new course can be added
/// </summary>
public void TestUserAddCourse()
{
User user = new User();
Progress p = new Progress();
user.courses.Add(p);
Debug.Assert(user.courses.Count == 1);
Debug.Assert(user.minigames.Count == 0);
}
/// <summary>
/// Test whether progress on a new minigame can be added
/// </summary>
public void TestUserAddMinigame()
{
User user = new User();
Progress p = new Progress();
user.minigames.Add(p);
Debug.Assert(user.courses.Count == 0);
Debug.Assert(user.minigames.Count == 1);
}
/// <summary>
/// Test GetRecentCourses will return empty when no progress is stored
/// </summary>
public void TestGetRecentCoursesEmpty()
{
User user = new User();
Debug.Assert(user.GetRecentCourses().Count == 0);
}
/// <summary>
/// Temporary test for GetRecentCourses will return all progress that is stored
/// </summary>
public void TestGetRecentCoursesAll()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
p.AddOrUpdate<float>("courseProgress", 0.5f);
user.courses.Add(p);
List<Tuple<CourseIndex, float>> list = user.GetRecentCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.5f);
}
/// <summary>
/// Test GetRecommendedCourses will return <c>Tuple<CourseIndex.FINGERSPELLING, 0.0></c> when no progress is stored
/// </summary>
public void TestGetRecommendedCoursesEmpty()
{
User user = new User();
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.0f);
}
/// <summary>
/// Temporary test for GetRecommenedCourses will return all progress that is stored
/// </summary>
public void TestGetRecommendedCoursesAll()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
p.AddOrUpdate<float>("courseProgress", 0.5f);
user.courses.Add(p);
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.5f);
}
/// <summary>
/// Test GetCourseProgress returns null when course cannot be found
/// </summary>
public void TestGetCourseProgressNull()
{
User user = new User();
Debug.Assert(user.GetCourseProgress(CourseIndex.FINGERSPELLING) == null);
Debug.Assert(user.GetCourseProgress((CourseIndex)100) == null);
}
/// <summary>
/// Test GetCourseProgress returns correct progress object
/// </summary>
public void TestGetCourseProgressValid()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
p.AddOrUpdate<float>("courseProgress", 3.14159265f);
user.courses.Add(p);
Progress q = user.GetCourseProgress(CourseIndex.FINGERSPELLING);
Debug.Assert(q.Get<CourseIndex>("courseIndex") == CourseIndex.FINGERSPELLING);
Debug.Assert(q.Get<float>("courseProgress") == 3.14159265f);
}
/// <summary>
/// Test GetMinigameProgress returns null when minigame cannot be found
/// </summary>
public void TestGetMinigameProgressNull()
{
User user = new User();
Debug.Assert(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE) == null);
Debug.Assert(user.GetMinigameProgress((MinigameIndex)100) == null);
Progress p = new Progress();
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
user.minigames.Add(p);
Debug.Assert(user.GetMinigameProgress(MinigameIndex.HANGMAN) == null);
}
/// <summary>
/// Test GetMinigameProgress returns correct progress object
/// </summary>
public void TestGetMinigameProgressValid()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
user.minigames.Add(p);
Progress q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
Debug.Assert(q.Get<CourseIndex>("minigameIndex") == CourseIndex.FINGERSPELLING);
}
}

View File

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

View File

@@ -1,13 +1,22 @@
using UnityEngine;
/// <summary>
/// Test the UserCreationScreen class
/// </summary>
public class TestUserCreationScreen : MonoBehaviour
{
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestIsValidUsernameTrue();
TestIsValidUsernameFalse();
}
/// <summary>
/// Tets IsValidUsername will return <c>true</c> for an valid username
/// </summary>
public void TestIsValidUsernameTrue()
{
foreach (char c in "abcdefghijklmnopqrstuvwxyz")
@@ -16,6 +25,9 @@ public class TestUserCreationScreen : MonoBehaviour
Debug.Assert(UserCreationScreen.IsValidUsername("abcdefghijkl"));
}
/// <summary>
/// Tets IsValidUsername will return <c>false</c> for an invalid username
/// </summary>
public void TestIsValidUsernameFalse()
{
Debug.Assert(!UserCreationScreen.IsValidUsername(string.Empty));