Resolve WES-133 "Multiple choice"
This commit is contained in:
committed by
Jelle De Geest
parent
04d9a4bf2b
commit
4e9d801e61
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
public class PersistentDataTests
|
||||
{
|
||||
@@ -145,7 +146,7 @@ public class PersistentDataTests
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Version()
|
||||
{
|
||||
const int VERSION = 0x04_01;
|
||||
const int VERSION = 0x04_03;
|
||||
Assert.AreEqual(VERSION, PersistentDataController.VERSION);
|
||||
}
|
||||
|
||||
@@ -611,4 +612,158 @@ public class PersistentDataTests
|
||||
c.Set<int>("key", 123);
|
||||
Assert.IsFalse(c.Has("KEY"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_AddLearnable_AddsLearnable()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
bool added = progress.AddLearnable("test learnable", 0);
|
||||
|
||||
Assert.IsTrue(added);
|
||||
Assert.AreEqual(progress.learnables.Count, 1);
|
||||
Assert.AreEqual(progress.learnables[0].name, "test learnable");
|
||||
Assert.AreEqual(progress.learnables[0].index, 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_AddLearnable_FailsWithDuplicateName()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("test learnable", 0);
|
||||
|
||||
bool added = progress.AddLearnable("test learnable", 1);
|
||||
|
||||
Assert.IsFalse(added);
|
||||
Assert.AreEqual(progress.learnables.Count, 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_AddLearnable_FailsWithDuplicateIndex()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("test learnable", 0);
|
||||
|
||||
bool added = progress.AddLearnable("test learnable 2", 0);
|
||||
|
||||
Assert.IsFalse(added);
|
||||
Assert.AreEqual(progress.learnables.Count, 1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Test_UpdateLearnable_UpdatesProgress()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("test learnable", 0);
|
||||
|
||||
progress.UpdateLearnable("test learnable", 3.0f);
|
||||
|
||||
Assert.AreEqual(progress.learnables[0].progress, 3.0f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_UpdateLearnable_CropsProgressAtFive()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("test learnable", 0);
|
||||
|
||||
progress.UpdateLearnable("test learnable", 10.0f);
|
||||
|
||||
Assert.AreEqual(progress.learnables[0].progress, 5.0f);
|
||||
Assert.AreEqual(progress.completedLearnables, 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_UpdateLearnable_CropsProgressAtNegativeFive()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
progress.AddLearnable("test learnable", 0);
|
||||
|
||||
progress.UpdateLearnable("test learnable", -10.0f);
|
||||
|
||||
Assert.AreEqual(progress.learnables[0].progress, -5.0f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_FindLearnable_ReturnsNullWhenNotFound()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("test learnable 1", 0);
|
||||
progress.AddLearnable("test learnable 2", 1);
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.FindLearnable("not found");
|
||||
|
||||
Assert.IsNull(learnable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_FindLearnable_ReturnsLearnableByName()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("test learnable 1", 0);
|
||||
progress.AddLearnable("test learnable 2", 1);
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.FindLearnable("test learnable 2");
|
||||
|
||||
Assert.AreEqual(learnable.index, 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_AddNewLearnable_ReturnsFalseWhenNoUnusedLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("test learnable 1", 0);
|
||||
progress.learnables[0].inUse = true;
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.AddNewLearnable();
|
||||
|
||||
Assert.IsNull(learnable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_AddNewLearnable_ReturnsTrueWhenUnusedLearnableFound()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("test learnable 1", 0);
|
||||
progress.AddLearnable("test learnable 2", 1);
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.AddNewLearnable();
|
||||
|
||||
Assert.IsNotNull(learnable);
|
||||
Assert.AreEqual(progress.inUseLearnables, 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_GetRandomLearnable_ReturnsNullWhenNoLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.GetRandomLearnable();
|
||||
|
||||
Assert.IsNull(learnable);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_GetRandomLearnable_ReturnsNullWhenOnlyCompletedLearnables()
|
||||
{
|
||||
PersistentDataController.SavedCourseProgress progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.AddLearnable("test learnable 1", 0);
|
||||
progress.AddLearnable("test learnable 2", 1);
|
||||
progress.learnables[0].progress = 4.0f;
|
||||
progress.learnables[0].inUse = true;
|
||||
progress.learnables[1].progress = 4.0f;
|
||||
progress.learnables[1].inUse = true;
|
||||
progress.completedLearnables = 2;
|
||||
progress.inUseLearnables = 0;
|
||||
|
||||
PersistentDataController.SavedLearnableProgress learnable = progress.GetRandomLearnable();
|
||||
|
||||
Assert.IsNull(learnable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user