Test accounts
This commit is contained in:
committed by
Jelle De Geest
parent
fee989006c
commit
7b6eb4db69
@@ -7,8 +7,14 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// Test the Progress class
|
||||
/// </summary>
|
||||
public class TestProgress
|
||||
[TestFixture]
|
||||
public class ProgressTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the progress object to be tested
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
@@ -29,205 +35,179 @@ public class TestProgress
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method
|
||||
/// Setup the tests
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if <c>Progress.AddOrUpdate(...)</c> throws a <c>SerializationException</c></returns>
|
||||
private bool AddNonSerializableStruct()
|
||||
[SetUp]
|
||||
public void Setup_Progress()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
NonSerializableStruct nss = new NonSerializableStruct();
|
||||
try { progress.AddOrUpdate<NonSerializableStruct>("key", nss); }
|
||||
catch (SerializationException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <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();
|
||||
try { progress.Get<int>("non-existing key"); }
|
||||
catch (KeyNotFoundException) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <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();
|
||||
progress.AddOrUpdate<int>("key", 123456789);
|
||||
try { progress.Get<double>("key"); }
|
||||
catch (InvalidCastException) { return true; }
|
||||
return false;
|
||||
progress = new Progress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for creation of a new progress
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestNewProgress()
|
||||
public void Test_New_Progress()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress != null);
|
||||
Assert.IsNotNull(progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether invalid data will not be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddInvalidData()
|
||||
public void Test_Progress_Add_InvalidData()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(!progress.AddOrUpdate<GameObject>("key", null));
|
||||
Assert.IsFalse(progress.AddOrUpdate<GameObject>("key", null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a duplicated key will be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddDuplicateKey()
|
||||
public void Test_Progress_Add_DuplicateKey()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key 1", 0);
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key 1", 1));
|
||||
Assert.IsTrue(progress.AddOrUpdate<int>("key 1", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddInt()
|
||||
public void Test_Progress_Add_Int()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<int>("key", 1));
|
||||
Assert.IsTrue(progress.AddOrUpdate<int>("key", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddDouble()
|
||||
public void Test_Progress_Add_Double()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<double>("key", 1.0));
|
||||
Assert.IsTrue(progress.AddOrUpdate<double>("key", 1.0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddString()
|
||||
public void Test_Progress_Add_String()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<string>("key", "Hello World!"));
|
||||
Assert.IsTrue(progress.AddOrUpdate<string>("key", "Hello World!"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddSerializableStruct()
|
||||
public void Test_Progress_Add_SerializableStruct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
Debug.Assert(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
|
||||
Assert.IsTrue(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a non-serializable struct will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressAddNonSerializableStruct()
|
||||
public void Test_Progress_Add_NonSerializableStruct()
|
||||
{
|
||||
Debug.Assert(AddNonSerializableStruct());
|
||||
NonSerializableStruct nss = new NonSerializableStruct();
|
||||
Assert.Throws<SerializationException>(delegate { progress.AddOrUpdate<NonSerializableStruct>("key", nss); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a key is present
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Has_ValidKey()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Assert.IsTrue(progress.Has("key"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a key is not present
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Has_InvalidKey()
|
||||
{
|
||||
Assert.IsFalse(progress.Has("non-existing key"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid key will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetInvalidKey()
|
||||
public void Test_Progress_Get_InvalidKey()
|
||||
{
|
||||
Debug.Assert(AccessInvalidKey());
|
||||
Assert.Throws<KeyNotFoundException>(delegate { progress.Get<int>("non-existing key"); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid type will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetInvalidType()
|
||||
public void Test_Progress_Get_InvalidType()
|
||||
{
|
||||
Debug.Assert(AccessInvalidType());
|
||||
progress.AddOrUpdate<int>("key", 123456789);
|
||||
Assert.Throws<InvalidCastException>(delegate { progress.Get<double>("key"); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a value is correctly updated
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressUpdate()
|
||||
public void Test_Progress_Update()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Debug.Assert(progress.Get<int>("key") == 1);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 1);
|
||||
progress.AddOrUpdate<int>("key", 2);
|
||||
Debug.Assert(progress.Get<int>("key") == 2);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetInt()
|
||||
public void Test_Progress_Get_Int()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Debug.Assert(progress.Get<int>("key") == 1);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetDouble()
|
||||
public void Test_Progress_Get_Double()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<double>("key", 1.0);
|
||||
Debug.Assert(progress.Get<double>("key") == 1.0);
|
||||
Assert.AreEqual(progress.Get<double>("key"), 1.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetString()
|
||||
public void Test_Progress_Get_String()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
progress.AddOrUpdate<string>("key", "Hello World!");
|
||||
Debug.Assert(progress.Get<string>("key") == "Hello World!");
|
||||
Assert.AreEqual(progress.Get<string>("key"), "Hello World!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void TestProgressGetStruct()
|
||||
public void Test_Progress_Get_Struct()
|
||||
{
|
||||
Progress progress = new Progress();
|
||||
|
||||
int R = 1, G = 10, B = 100;
|
||||
float X = 0.1f, Y = 0.01f, Z = 0.001f;
|
||||
SerializableStruct data = new SerializableStruct { r = R, g = G, b = B, x = X, y = Y, z = Z };
|
||||
progress.AddOrUpdate<SerializableStruct>("key", data);
|
||||
SerializableStruct result = progress.Get<SerializableStruct>("key");
|
||||
Debug.Assert(result.r == R);
|
||||
Debug.Assert(result.g == G);
|
||||
Debug.Assert(result.b == B);
|
||||
Debug.Assert(result.x == X);
|
||||
Debug.Assert(result.y == Y);
|
||||
Debug.Assert(result.z == Z);
|
||||
Assert.AreEqual(result, data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user