Refactored helper unit test classes
authorUnknown <thomas.dorsch@gmx.org>
Wed, 3 Jan 2018 18:40:11 +0000 (19:40 +0100)
committerUnknown <thomas.dorsch@gmx.org>
Wed, 3 Jan 2018 18:46:04 +0000 (19:46 +0100)
Extracted classes which provides data and verify test results into seperate files.

Replaced String with string and removed the System namespace.

tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs [new file with mode: 0644]
tests/OpenTK.Tests.Math/Helpers/QuaternionTestHelper.cs [new file with mode: 0644]
tests/OpenTK.Tests.Math/OpenTK.Tests.Math.csproj
tests/OpenTK.Tests.Math/QuaternionTests.cs

diff --git a/tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs b/tests/OpenTK.Tests.Math/DataProviders/QuaternionTestDataGenerator.cs
new file mode 100644 (file)
index 0000000..19dd76e
--- /dev/null
@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+
+namespace OpenTK.Tests.Math.DataProviders
+{
+       /// <summary>
+       /// Generates/Provides Quaternion test data.
+       /// </summary>
+       public class QuaternionTestDataGenerator
+       {
+               /// <summary>
+               /// 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
+               /// </summary>
+               /// <value>The single axis test cases.</value>
+               public static IEnumerable<object> 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" };
+               }
+
+               /// <summary>
+               /// 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
+               /// </summary>
+               /// <value>The single axis test cases.</value>
+               public static IEnumerable<object[]> 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 (file)
index 0000000..d3d35dc
--- /dev/null
@@ -0,0 +1,61 @@
+using Xunit;
+using System;
+using System.Collections.Generic;
+
+namespace OpenTK.Tests.Math.Helpers
+{
+
+       /// <summary>
+       /// Provides some methods which helps to verify test results
+       /// </summary>
+       internal static class QuaternionTestHelper
+       {
+               /// <summary>
+               /// Verifies the direction of an given <see cref="Vector3"/>.
+               /// </summary>
+               /// <returns>false: When <paramref name="toTest"/> does contain xyz values, when it should be 0,
+               /// or does not contain 0 when it should be</returns>
+               /// <param name="toTest">To test</param>
+               /// <param name="expected">Expected directions. Values getting only 0 checked</param>
+               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;
+               }
+       }
+       
+}
index 07882b1..71cd5cd 100644 (file)
     <Compile Include="BezierCurveTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="QuaternionTests.cs" />
+    <Compile Include="Helpers\QuaternionTestHelper.cs" />
+    <Compile Include="DataProviders\QuaternionTestDataGenerator.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="paket.references" />
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Helpers\" />
+    <Folder Include="Generators\" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
index d07fa73..3db06f3 100644 (file)
@@ -1,96 +1,9 @@
 using Xunit;
-using System;
-using System.Collections.Generic;
+using OpenTK.Tests.Math.Helpers;
+using OpenTK.Tests.Math.DataProviders;
 
 namespace OpenTK.Tests.Math
 {
-       /// <summary>
-       /// Generates Quaternion test data.
-       /// </summary>
-       public class QuaternionTestDataGenerator
-       {
-               /// <summary>
-               /// 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
-               /// </summary>
-               /// <value>The single axis test cases.</value>
-               public static IEnumerable<object> 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" };
-               }
-
-               /// <summary>
-               /// 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
-               /// </summary>
-               /// <value>The single axis test cases.</value>
-               public static IEnumerable<object[]> 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" };
-               }
-       }
-
-       /// <summary>
-       /// Provides some methods which helps to verify test results
-       /// </summary>
-       internal static class QuaternionTestHelper
-       {
-               /// <summary>
-               /// Verifies the direction of an given <see cref="Vector3"/>.
-               /// </summary>
-               /// <returns>false: When <paramref name="toTest"/> does contain xyz values, when it should be 0,
-               /// or does not contain 0 when it should be</returns>
-               /// <param name="toTest">To test</param>
-               /// <param name="expected">Expected directions. Values getting only 0 checked</param>
-               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;
-               }
-       }
-
        public class Quaternion_Tests
        {
                /// <summary>
@@ -101,7 +14,7 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.SingleAxisTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void CtorEulerAnglesFloat_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, String testName)
+               public void CtorEulerAnglesFloat_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with "pitch/yaw/roll"
                        var cut = new Quaternion(eulerValues.X, eulerValues.Y, eulerValues.Z);
@@ -120,10 +33,10 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.SingleAxisTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void CtorEulerAnglesVector3_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, String testName)
+               public void CtorEulerAnglesVector3_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with "pitch/yaw/roll"
-                       var cut = new Quaternion(eulerValues.X, eulerValues.Y, eulerValues.Z);
+                       var cut = new Quaternion(eulerValues);
 
                        //Assert: Use helper, to check if part of the two correct axis is zero. I just want check the direction
                        Vector3 resultXYZ = cut.Xyz;
@@ -139,7 +52,7 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.SingleAxisTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void FromEulerAnglesFloat_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, String testName)
+               public void FromEulerAnglesFloat_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with "pitch/yaw/roll"
                        var cut = Quaternion.FromEulerAngles(eulerValues.X, eulerValues.Y, eulerValues.Z);
@@ -158,7 +71,7 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.SingleAxisTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void FromEulerAnglesVector3_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, String testName)
+               public void FromEulerAnglesVector3_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with "pitch/yaw/roll"
                        var cut = Quaternion.FromEulerAngles(eulerValues);
@@ -177,7 +90,7 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.SingleAxisTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void FromEulerAnglesOut_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, String testName)
+               public void FromEulerAnglesOut_SingleEulerAngleSet_RotateCorrectAxis(Vector3 eulerValues, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with "pitch/yaw/roll"
                        var cut = Quaternion.Identity;
@@ -197,7 +110,7 @@ namespace OpenTK.Tests.Math
                /// <param name="testName">Taken from nUnit test data. Don't know how to name data driven tests for xUnit which actually works.</param>
                [Theory]
                [MemberData(nameof(QuaternionTestDataGenerator.ToAxisAngleTestCases), MemberType = typeof(QuaternionTestDataGenerator))]
-               public void ToAxisAngle_SingleAxisSetAndAngleIgnored_RotateCorrectAxis(Quaternion cut, Vector3 expectedResult, String testName)
+               public void ToAxisAngle_SingleAxisSetAndAngleIgnored_RotateCorrectAxis(Quaternion cut, Vector3 expectedResult, string testName)
                {
                        //Arrange + Act: Create Quaternion with rotation about X/Y/Z axis
                        Vector3 resultXYZ;