From 5aed63e396daf6a1b83a3fbf4d3b2b8d40e07cca Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 3 Jan 2018 19:40:11 +0100 Subject: [PATCH] Refactored helper unit test classes Extracted classes which provides data and verify test results into seperate files. Replaced String with string and removed the System namespace. --- .../QuaternionTestDataGenerator.cs | 39 +++++++ .../Helpers/QuaternionTestHelper.cs | 61 ++++++++++ .../OpenTK.Tests.Math.csproj | 6 + tests/OpenTK.Tests.Math/QuaternionTests.cs | 105 ++---------------- 4 files changed, 115 insertions(+), 96 deletions(-) create mode 100644 tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs create mode 100644 tests/OpenTK.Tests.Math/Helpers/QuaternionTestHelper.cs 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 @@ + + + + + +