Skip to content

Commit

Permalink
Asserts to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
vpenades committed Jul 12, 2019
1 parent a0f03cd commit de4ff51
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 98 deletions.
203 changes: 203 additions & 0 deletions tests/SharpGLTF.Tests/NumericsAssert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;

using NUnit.Framework;

namespace SharpGLTF
{
static class NumericsAssert
{
public static void IsFinite(Vector2 vector)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
}

public static void IsFinite(Vector3 vector)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
Assert.IsTrue(float.IsFinite(vector.Z), "Z");
}

public static void IsFinite(Vector4 vector)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
Assert.IsTrue(float.IsFinite(vector.Z), "Z");
Assert.IsTrue(float.IsFinite(vector.W), "W");
}

public static void IsFinite(Quaternion quaternion)
{
Assert.IsTrue(float.IsFinite(quaternion.X), "X");
Assert.IsTrue(float.IsFinite(quaternion.Y), "Y");
Assert.IsTrue(float.IsFinite(quaternion.Z), "Z");
Assert.IsTrue(float.IsFinite(quaternion.W), "W");
}

public static void AreEqual(Vector2 expected, Vector2 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
}

public static void AreEqual(Vector3 expected, Vector3 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
}

public static void AreEqual(Vector4 expected, Vector4 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
Assert.AreEqual(expected.W, actual.W, delta, "W");
}

public static void AreEqual(Quaternion expected, Quaternion actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
Assert.AreEqual(expected.W, actual.W, delta, "W");
}

public static void LengthIsOne(Vector2 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void LengthIsOne(Vector3 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void LengthIsOne(Vector4 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void LengthIsOne(Quaternion vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void Less(Vector2 arg1, Vector2 arg2)
{
Assert.Less(arg1.X, arg2.X, "X");
Assert.Less(arg1.Y, arg2.Y, "Y");
}

public static void Less(Vector3 arg1, Vector3 arg2)
{
Assert.Less(arg1.X, arg2.X, "X");
Assert.Less(arg1.Y, arg2.Y, "Y");
Assert.Less(arg1.Z, arg2.Z, "Z");
}

public static void Less(Vector4 arg1, Vector4 arg2)
{
Assert.Less(arg1.X, arg2.X, "X");
Assert.Less(arg1.Y, arg2.Y, "Y");
Assert.Less(arg1.Z, arg2.Z, "Z");
Assert.Less(arg1.W, arg2.W, "W");
}

public static void LessOrEqual(Vector2 arg1, Vector2 arg2)
{
Assert.LessOrEqual(arg1.X, arg2.X, "X");
Assert.LessOrEqual(arg1.Y, arg2.Y, "Y");
}

public static void LessOrEqual(Vector3 arg1, Vector3 arg2)
{
Assert.LessOrEqual(arg1.X, arg2.X, "X");
Assert.LessOrEqual(arg1.Y, arg2.Y, "Y");
Assert.LessOrEqual(arg1.Z, arg2.Z, "Z");
}

public static void LessOrEqual(Vector4 arg1, Vector4 arg2)
{
Assert.LessOrEqual(arg1.X, arg2.X, "X");
Assert.LessOrEqual(arg1.Y, arg2.Y, "Y");
Assert.LessOrEqual(arg1.Z, arg2.Z, "Z");
Assert.LessOrEqual(arg1.W, arg2.W, "W");
}

public static void Greater(Vector2 arg1, Vector2 arg2)
{
Assert.Greater(arg1.X, arg2.X, "X");
Assert.Greater(arg1.Y, arg2.Y, "Y");
}

public static void Greater(Vector3 arg1, Vector3 arg2)
{
Assert.Greater(arg1.X, arg2.X, "X");
Assert.Greater(arg1.Y, arg2.Y, "Y");
Assert.Greater(arg1.Z, arg2.Z, "Z");
}

public static void Greater(Vector4 arg1, Vector4 arg2)
{
Assert.Greater(arg1.X, arg2.X, "X");
Assert.Greater(arg1.Y, arg2.Y, "Y");
Assert.Greater(arg1.Z, arg2.Z, "Z");
Assert.Greater(arg1.W, arg2.W, "W");
}

public static void GreaterOrEqual(Vector2 arg1, Vector2 arg2)
{
Assert.GreaterOrEqual(arg1.X, arg2.X, "X");
Assert.GreaterOrEqual(arg1.Y, arg2.Y, "Y");
}

public static void GreaterOrEqual(Vector3 arg1, Vector3 arg2)
{
Assert.GreaterOrEqual(arg1.X, arg2.X, "X");
Assert.GreaterOrEqual(arg1.Y, arg2.Y, "Y");
Assert.GreaterOrEqual(arg1.Z, arg2.Z, "Z");
}

public static void GreaterOrEqual(Vector4 arg1, Vector4 arg2)
{
Assert.GreaterOrEqual(arg1.X, arg2.X, "X");
Assert.GreaterOrEqual(arg1.Y, arg2.Y, "Y");
Assert.GreaterOrEqual(arg1.Z, arg2.Z, "Z");
Assert.GreaterOrEqual(arg1.W, arg2.W, "W");
}

public static void AngleLessOrEqual(Vector2 a, Vector2 b, float radians)
{
var angle = VectorsUtils.GetAngle(a, b);

Assert.LessOrEqual(angle, radians, "Angle");
}

public static void AngleLessOrEqual(Vector3 a, Vector3 b, float radians)
{
var angle = VectorsUtils.GetAngle(a, b);

Assert.LessOrEqual(angle, radians, "Angle");
}

public static void AngleLessOrEqual(Quaternion a, Quaternion b, float radians)
{
var angle = VectorsUtils.GetAngle(a, b);

Assert.LessOrEqual(angle, radians, "Angle");
}
}
}
107 changes: 9 additions & 98 deletions tests/SharpGLTF.Tests/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,108 +279,19 @@ public static float GetAngle(Vector3 a, Vector3 b)

return (float)Math.Acos(c);
}
}

static class NumericsAssert
{
public static void IsFinite(Vector2 vector)
public static float GetAngle(Vector2 a, Vector2 b)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
}
a = Vector2.Normalize(a);
b = Vector2.Normalize(b);

public static void IsFinite(Vector3 vector)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
Assert.IsTrue(float.IsFinite(vector.Z), "Z");
}

public static void IsFinite(Vector4 vector)
{
Assert.IsTrue(float.IsFinite(vector.X), "X");
Assert.IsTrue(float.IsFinite(vector.Y), "Y");
Assert.IsTrue(float.IsFinite(vector.Z), "Z");
Assert.IsTrue(float.IsFinite(vector.W), "W");
}

public static void IsFinite(Quaternion quaternion)
{
Assert.IsTrue(float.IsFinite(quaternion.X), "X");
Assert.IsTrue(float.IsFinite(quaternion.Y), "Y");
Assert.IsTrue(float.IsFinite(quaternion.Z), "Z");
Assert.IsTrue(float.IsFinite(quaternion.W), "W");
}

public static void AreEqual(Vector2 expected, Vector2 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
}

public static void AreEqual(Vector3 expected, Vector3 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
}

public static void AreEqual(Vector4 expected, Vector4 actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
Assert.AreEqual(expected.W, actual.W, delta, "W");
}

public static void AreEqual(Quaternion expected, Quaternion actual, double delta = 0)
{
Assert.AreEqual(expected.X, actual.X, delta, "X");
Assert.AreEqual(expected.Y, actual.Y, delta, "Y");
Assert.AreEqual(expected.Z, actual.Z, delta, "Z");
Assert.AreEqual(expected.W, actual.W, delta, "W");
}

public static void IsNormal(Vector2 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void IsNormal(Vector3 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void IsNormal(Vector4 vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void IsNormal(Quaternion vector, double delta = 0)
{
var lenSquared = vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W;

Assert.AreEqual(1, lenSquared, delta * delta, "Length");
}

public static void AngleLessOrEqual(Vector3 a, Vector3 b, float radians)
{
var angle = VectorsUtils.GetAngle(a, b);

Assert.LessOrEqual(angle, radians, "Angle");
}

public static void AngleLessOrEqual(Quaternion a, Quaternion b, float radians)
{
var angle = VectorsUtils.GetAngle(a, b);
var c = Vector2.Dot(a, b);
if (c > 1) c = 1;
if (c < -1) c = -1;

Assert.LessOrEqual(angle, radians, "Angle");
return (float)Math.Acos(c);
}
}


}

0 comments on commit de4ff51

Please sign in to comment.