Add final tests

This commit is contained in:
Daniel Cronqvist 2024-08-13 23:18:42 +02:00
parent 292dc9b1b9
commit 653e5b5326
16 changed files with 549 additions and 17 deletions

View file

@ -1,3 +1,6 @@
using System.Collections;
using System.Numerics;
namespace DotTiled.Tests;
public static partial class DotTiledAssert
@ -10,6 +13,29 @@ public static partial class DotTiledAssert
return;
}
if (typeof(T) == typeof(float))
{
var expectedFloat = (float)(object)expected;
var actualFloat = (float)(object)actual!;
var expecRounded = MathF.Round(expectedFloat, 3);
var actRounded = MathF.Round(actualFloat, 3);
Assert.True(expecRounded == actRounded, $"Expected {nameof} '{expecRounded}' but got '{actRounded}'");
return;
}
if (expected is Vector2)
{
var expectedVector = (Vector2)(object)expected;
var actualVector = (Vector2)(object)actual!;
AssertEqual(expectedVector.X, actualVector.X, $"{nameof}.X");
AssertEqual(expectedVector.Y, actualVector.Y, $"{nameof}.Y");
return;
}
if (typeof(T).IsArray)
{
var expectedArray = (Array)(object)expected;
@ -24,6 +50,20 @@ public static partial class DotTiledAssert
return;
}
if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(List<>))
{
var expectedList = (IList)(object)expected;
var actualList = (IList)(object)actual!;
Assert.NotNull(actualList);
AssertEqual(expectedList.Count, actualList.Count, $"{nameof}.Count");
for (var i = 0; i < expectedList.Count; i++)
AssertEqual(expectedList[i], actualList[i], $"{nameof}[{i}]");
return;
}
Assert.True(expected.Equals(actual), $"Expected {nameof} '{expected}' but got '{actual}'");
}