using NUnit.Framework; using System; using System.Collections.Generic; /// /// Test the User class /// [TestFixture] public class UserTest { /// /// Reference to the user to be tested /// private User user; /// /// Setup the tests /// [SetUp] public void Setup_User() { PersistentDataController.SavedUserData data = new PersistentDataController.SavedUserData(); data.username = "username"; data.avatarIndex = 0; user = new User(data); } /// /// Test for the creation of a new user /// [Test] public void Test_New_User() { Assert.NotNull(user); Assert.Zero(user.GetCourses().Count); Assert.Zero(user.GetMinigames().Count); } /// /// Test whether progress on a new course can be added /// [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); } /// /// Test whether progress on a new minigame can be added /// [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); } /// /// Test GetRecentCourses will return empty when no progress is stored /// [Test] public void Test_User_GetRecentCourses_Empty() { Assert.Zero(user.GetRecentCourses().Count); } /// /// TEMPORARY test for GetRecentCourses will return all progress that is stored /// [Test] public void Test_User_GetRecentCourses_All() { var p = new PersistentDataController.SavedCourseProgress(); p.courseIndex = CourseIndex.FINGERSPELLING; p.progress = 0.5f; user.AddCourseProgress(p); List> list = user.GetRecentCourses(); Assert.AreEqual(list.Count, 1); Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING); Assert.AreEqual(list[0].Item2, 0.5f); } /// /// Test GetRecommendedCourses will return Tuple when no progress is stored /// [Test] public void Test_User_GetRecommendedCourses_Empty() { List> list = user.GetRecommendedCourses(); Assert.AreEqual(list.Count, 1); Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING); Assert.AreEqual(list[0].Item2, 0.0f); } /// /// TEMPORARY test for GetRecommenedCourses will return all progress that is stored /// [Test] public void Test_User_GetRecommendedCourses_All() { var p = new PersistentDataController.SavedCourseProgress(); p.courseIndex = CourseIndex.FINGERSPELLING; p.progress = 0.5f; user.AddCourseProgress(p); List> list = user.GetRecommendedCourses(); Assert.AreEqual(list.Count, 1); Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING); Assert.AreEqual(list[0].Item2, 0.5f); } /// /// Test GetCourseProgress returns null when course cannot be found /// [Test] public void Test_User_GetCourseProgress_Null() { Assert.Null(user.GetCourseProgress(CourseIndex.FINGERSPELLING)); Assert.Null(user.GetCourseProgress((CourseIndex)100)); } /// /// Test GetCourseProgress returns correct progress object /// [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); } /// /// Test progress of a course is correctly reset (aka removed) /// [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)); } /// /// Test GetMinigameProgress returns null when minigame cannot be found /// [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)); } /// /// Test GetMinigameProgress returns correct progress object /// [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); } /// /// Test progress of a minigame is correctly reset (aka removed) /// [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)); } }