diff --git a/tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs b/tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs new file mode 100644 index 00000000..19dd76ef --- /dev/null +++ b/tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; + +namespace OpenTK.Tests.Math.DataProviders +{ + /// + /// Generates/Provides Quaternion test data. + /// + public class QuaternionTestDataGenerator + { + /// + /// Returns the single axis test cases. + /// 1. param: rotation in euler angles + /// 2. param: expected result of xyz-component of quaternion + /// 3. param: test name (Don't found a working way how to pass this to xUnit runner). I let it here for test documentation + /// + /// The single axis test cases. + public static IEnumerable SingleAxisTestCases() + { + yield return new object[] { new Vector3(1, 0, 0), Vector3.UnitX, "Rotate around x axis" }; + yield return new object[] { new Vector3(0, 1, 0), Vector3.UnitY, "Rotate around y axis" }; + yield return new object[] { new Vector3(0, 0, 1), Vector3.UnitZ, "Rotate around z axis" }; + } + + /// + /// Returns the single ToAxisAngle test cases. + /// 1. param: Quaternion which a definied value of xyz-component. + /// 2. param: expected result of xyz-component of quaternion + /// 3. param: test name (Don't found a working way how to pass this to xUnit runner). I let it here for test documentation + /// + /// The single axis test cases. + public static IEnumerable ToAxisAngleTestCases() + { + yield return new object[] { new Quaternion(Vector3.UnitX, 0), Vector3.UnitX, "Rotate around x axis" }; + yield return new object[] { new Quaternion(Vector3.UnitY, 0), Vector3.UnitY, "Rotate around y axis" }; + yield return new object[] { new Quaternion(Vector3.UnitZ, 0), Vector3.UnitZ, "Rotate around z axis" }; + } + } + +} diff --git a/tests/OpenTK.Tests.Math/Helpers/QuaternionTestHelper.cs b/tests/OpenTK.Tests.Math/Helpers/QuaternionTestHelper.cs new file mode 100644 index 00000000..d3d35dc8 --- /dev/null +++ b/tests/OpenTK.Tests.Math/Helpers/QuaternionTestHelper.cs @@ -0,0 +1,61 @@ +using Xunit; +using System; +using System.Collections.Generic; + +namespace OpenTK.Tests.Math.Helpers +{ + + /// + /// Provides some methods which helps to verify test results + /// + internal static class QuaternionTestHelper + { + /// + /// Verifies the direction of an given . + /// + /// false: When does contain xyz values, when it should be 0, + /// or does not contain 0 when it should be + /// To test + /// Expected directions. Values getting only 0 checked + public static bool VerifyEqualSingleDirection(Vector3 toTest, Vector3 expected) + { + //To verify the direction of an vector, just respect the 0 values and check against these. + //The length of the vectors are ignored. + if (expected.X == 0) + { + if (toTest.X != 0) + return false; + } + else + { + if (toTest.X == 0) + return false; + } + + if (expected.Y == 0) + { + if (toTest.Y != 0) + return false; + } + else + { + if (toTest.Y == 0) + return false; + } + + if (expected.Z == 0) + { + if (toTest.Z != 0) + return false; + } + else + { + if (toTest.Z == 0) + return false; + } + + return true; + } + } + +} diff --git a/tests/OpenTK.Tests.Math/OpenTK.Tests.Math.csproj b/tests/OpenTK.Tests.Math/OpenTK.Tests.Math.csproj index 07882b1d..71cd5cd6 100644 --- a/tests/OpenTK.Tests.Math/OpenTK.Tests.Math.csproj +++ b/tests/OpenTK.Tests.Math/OpenTK.Tests.Math.csproj @@ -48,10 +48,16 @@ + + + + + +