200 lines
6.5 KiB
C#
200 lines
6.5 KiB
C#
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
/// <summary>
|
|
/// Test the User class
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class UserTest
|
|
{
|
|
/// <summary>
|
|
/// Reference to the user to be tested
|
|
/// </summary>
|
|
private User user;
|
|
|
|
/// <summary>
|
|
/// Setup the tests
|
|
/// </summary>
|
|
[SetUp]
|
|
public void Setup_User()
|
|
{
|
|
PersistentDataController.SavedUserData data = new PersistentDataController.SavedUserData();
|
|
data.username = "username";
|
|
data.avatarIndex = 0;
|
|
user = new User(data);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Test for the creation of a new user
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_New_User()
|
|
{
|
|
Assert.NotNull(user);
|
|
Assert.Zero(user.GetCourses().Count);
|
|
Assert.Zero(user.GetMinigames().Count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test whether progress on a new course can be added
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_AddCourse()
|
|
{
|
|
var p = new PersistentDataController.SavedCourseProgress();
|
|
user.AddCourseProgress(p);
|
|
Assert.AreEqual(user.GetCourses().Count, 1);
|
|
Assert.Zero(user.GetMinigames().Count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test whether progress on a new minigame can be added
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_AddMinigame()
|
|
{
|
|
var p = new PersistentDataController.SavedMinigameProgress();
|
|
user.AddMinigameProgress(p);
|
|
Assert.Zero(user.GetCourses().Count);
|
|
Assert.AreEqual(user.GetMinigames().Count, 1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetRecentCourses will return empty when no progress is stored
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetRecentCourses_Empty()
|
|
{
|
|
Assert.Zero(user.GetRecentCourses().Count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// TEMPORARY test for GetRecentCourses will return all progress that is stored
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetRecentCourses_All()
|
|
{
|
|
var p = new PersistentDataController.SavedCourseProgress();
|
|
p.courseIndex = CourseIndex.FINGERSPELLING;
|
|
p.progress = 0.5f;
|
|
user.AddCourseProgress(p);
|
|
List<Tuple<CourseIndex, float>> list = user.GetRecentCourses();
|
|
Assert.AreEqual(list.Count, 1);
|
|
Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING);
|
|
Assert.AreEqual(list[0].Item2, 0.5f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetRecommendedCourses will return <c>Tuple<CourseIndex.FINGERSPELLING, 0.0></c> when no progress is stored
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetRecommendedCourses_Empty()
|
|
{
|
|
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
|
|
Assert.AreEqual(list.Count, 1);
|
|
Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING);
|
|
Assert.AreEqual(list[0].Item2, 0.0f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// TEMPORARY test for GetRecommenedCourses will return all progress that is stored
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetRecommendedCourses_All()
|
|
{
|
|
var p = new PersistentDataController.SavedCourseProgress();
|
|
p.courseIndex = CourseIndex.FINGERSPELLING;
|
|
p.progress = 0.5f;
|
|
user.AddCourseProgress(p);
|
|
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
|
|
Assert.AreEqual(list.Count, 1);
|
|
Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING);
|
|
Assert.AreEqual(list[0].Item2, 0.5f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetCourseProgress returns null when course cannot be found
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetCourseProgress_Null()
|
|
{
|
|
Assert.Null(user.GetCourseProgress(CourseIndex.FINGERSPELLING));
|
|
Assert.Null(user.GetCourseProgress((CourseIndex)100));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetCourseProgress returns correct progress object
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetCourseProgress_Valid()
|
|
{
|
|
var p = new PersistentDataController.SavedCourseProgress();
|
|
p.courseIndex = CourseIndex.FINGERSPELLING;
|
|
p.progress = 3.14159265f;
|
|
user.AddCourseProgress(p);
|
|
var q = user.GetCourseProgress(CourseIndex.FINGERSPELLING);
|
|
Assert.AreEqual(q.courseIndex, CourseIndex.FINGERSPELLING);
|
|
Assert.AreEqual(q.progress, 3.14159265f);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test progress of a course is correctly reset (aka removed)
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_ResetCourseProgres()
|
|
{
|
|
var p = new PersistentDataController.SavedCourseProgress();
|
|
p.courseIndex = CourseIndex.FINGERSPELLING;
|
|
user.AddCourseProgress(p);
|
|
Assert.IsNotNull(user.GetCourseProgress(CourseIndex.FINGERSPELLING));
|
|
user.ResetCourseProgress(CourseIndex.FINGERSPELLING);
|
|
Assert.IsNull(user.GetCourseProgress(CourseIndex.FINGERSPELLING));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetMinigameProgress returns null when minigame cannot be found
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetMinigameProgress_Null()
|
|
{
|
|
Assert.Null(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE));
|
|
Assert.Null(user.GetMinigameProgress((MinigameIndex)100));
|
|
|
|
var p = new PersistentDataController.SavedMinigameProgress();
|
|
p.minigameIndex = MinigameIndex.SPELLING_BEE;
|
|
user.AddMinigameProgress(p);
|
|
Assert.Null(user.GetMinigameProgress(MinigameIndex.HANGMAN));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test GetMinigameProgress returns correct progress object
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_GetMinigameProgress_Valid()
|
|
{
|
|
var p = new PersistentDataController.SavedMinigameProgress();
|
|
p.minigameIndex = MinigameIndex.SPELLING_BEE;
|
|
user.AddMinigameProgress(p);
|
|
var q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
|
Assert.AreEqual(q.minigameIndex, MinigameIndex.SPELLING_BEE);
|
|
Assert.Zero(q.latestScores.Count);
|
|
Assert.Zero(q.highestScores.Count);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test progress of a minigame is correctly reset (aka removed)
|
|
/// </summary>
|
|
[Test]
|
|
public void Test_User_ResetMinigameProgres()
|
|
{
|
|
var p = new PersistentDataController.SavedMinigameProgress();
|
|
p.minigameIndex = MinigameIndex.SPELLING_BEE;
|
|
user.AddMinigameProgress(p);
|
|
Assert.IsNotNull(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE));
|
|
user.ResetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
|
Assert.IsNull(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE));
|
|
}
|
|
}
|