From c17b66c6fcbfb71820c793ba4d952d039b4fa032 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 12:50:11 +0200 Subject: [PATCH 01/66] Removed old tests --- OpenTK.sln | 7 - tests/OpenTK.Tests/Matrix4Test.cs | 289 ------------ tests/OpenTK.Tests/OpenTK.Tests.csproj | 87 ---- tests/OpenTK.Tests/Properties/AssemblyInfo.cs | 36 -- tests/OpenTK.Tests/Vector3Tests.cs | 439 ------------------ tests/OpenTK.Tests/packages.config | 5 - 6 files changed, 863 deletions(-) delete mode 100644 tests/OpenTK.Tests/Matrix4Test.cs delete mode 100644 tests/OpenTK.Tests/OpenTK.Tests.csproj delete mode 100644 tests/OpenTK.Tests/Properties/AssemblyInfo.cs delete mode 100644 tests/OpenTK.Tests/Vector3Tests.cs delete mode 100644 tests/OpenTK.Tests/packages.config diff --git a/OpenTK.sln b/OpenTK.sln index a33d8dd6..f8a9c184 100644 --- a/OpenTK.sln +++ b/OpenTK.sln @@ -21,8 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.GLWidget", "src\Open EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1857BB8E-1A35-4EBF-9F6D-685F11DC025B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Tests", "tests\OpenTK.Tests\OpenTK.Tests.csproj", "{930A780C-A67C-422F-9EED-DB38DAA47AB0}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.API.Desktop", "tests\Test.API.Desktop\Test.API.Desktop.csproj", "{C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{F1A57014-71CE-4032-A652-01B7E35E14DB}" @@ -76,10 +74,6 @@ Global {A625BE87-0000-0000-0000-000000000000}.Debug|Any CPU.Build.0 = Debug|Any CPU {A625BE87-0000-0000-0000-000000000000}.Release|Any CPU.ActiveCfg = Release|Any CPU {A625BE87-0000-0000-0000-000000000000}.Release|Any CPU.Build.0 = Release|Any CPU - {930A780C-A67C-422F-9EED-DB38DAA47AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {930A780C-A67C-422F-9EED-DB38DAA47AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {930A780C-A67C-422F-9EED-DB38DAA47AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {930A780C-A67C-422F-9EED-DB38DAA47AB0}.Release|Any CPU.Build.0 = Release|Any CPU {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Debug|Any CPU.Build.0 = Debug|Any CPU {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -89,7 +83,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {930A780C-A67C-422F-9EED-DB38DAA47AB0} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B} {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution diff --git a/tests/OpenTK.Tests/Matrix4Test.cs b/tests/OpenTK.Tests/Matrix4Test.cs deleted file mode 100644 index 97cc8862..00000000 --- a/tests/OpenTK.Tests/Matrix4Test.cs +++ /dev/null @@ -1,289 +0,0 @@ -using System; -using NUnit.Framework; -using OpenTK; - -namespace OpenTK.Tests -{ - [TestFixture] - public class Matrix4Test - { - [Test] - public void Matrix4_SixteenValueConstructor() - { - Matrix4 A = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Assert.AreEqual(0, A.M11); - Assert.AreEqual(1, A.M12); - Assert.AreEqual(2, A.M13); - Assert.AreEqual(3, A.M14); - - Assert.AreEqual(4, A.M21); - Assert.AreEqual(5, A.M22); - Assert.AreEqual(6, A.M23); - Assert.AreEqual(7, A.M24); - - Assert.AreEqual(8, A.M31); - Assert.AreEqual(9, A.M32); - Assert.AreEqual(10, A.M33); - Assert.AreEqual(11, A.M34); - - Assert.AreEqual(12, A.M41); - Assert.AreEqual(13, A.M42); - Assert.AreEqual(14, A.M43); - Assert.AreEqual(15, A.M44); - } - - [Test] - public void Matrix4_Matrix3Constructor() - { - Matrix3 B = new Matrix3( 1, 2, 3, - 4, 5, 6, - 7, 8, 9); - - Matrix4 A = new Matrix4(B); - - Assert.AreEqual(B.M11, A.M11); - Assert.AreEqual(B.M12, A.M12); - Assert.AreEqual(B.M13, A.M13); - - Assert.AreEqual(B.M21, A.M21); - Assert.AreEqual(B.M22, A.M22); - Assert.AreEqual(B.M23, A.M23); - - Assert.AreEqual(B.M31, A.M31); - Assert.AreEqual(B.M32, A.M32); - Assert.AreEqual(B.M33, A.M33); - } - - [Test] - public void Matrix4_FourVector4Constructor() - { - Vector4 V = new Vector4(1, 2, 3, 4); - Vector4 U = new Vector4(5, 6, 7, 8); - Vector4 S = new Vector4(9, 10, 11, 12); - Vector4 T = new Vector4(13, 14, 15, 16); - - Matrix4 A = new Matrix4(V, U, S, T); - - Assert.AreEqual(V.X, A.M11); - Assert.AreEqual(V.Y, A.M12); - Assert.AreEqual(V.Z, A.M13); - Assert.AreEqual(V.W, A.M14); - - Assert.AreEqual(U.X, A.M21); - Assert.AreEqual(U.Y, A.M22); - Assert.AreEqual(U.Z, A.M23); - Assert.AreEqual(U.W, A.M24); - - Assert.AreEqual(S.X, A.M31); - Assert.AreEqual(S.Y, A.M32); - Assert.AreEqual(S.Z, A.M33); - Assert.AreEqual(S.W, A.M34); - - Assert.AreEqual(T.X, A.M41); - Assert.AreEqual(T.Y, A.M42); - Assert.AreEqual(T.Z, A.M43); - Assert.AreEqual(T.W, A.M44); - - } - - [Test] - public void Matrix4_Equal_operator() - { - Matrix4 A = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 B = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Assert.IsTrue(A == B); - } - - [Test] - public void Matrix4_Matrix4TimesMatrix4_operator() - { - Matrix4 A = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 B = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 expected = new Matrix4( 56, 62, 68, 74, - 152, 174, 196, 218, - 248, 286, 324, 362, - 344, 398, 452, 506); - - Matrix4 result = A * B; - Assert.IsTrue(expected == result); - } - - [Test] - public void Matrix4_Matrix4PlusMatrix4_operator() - { - Matrix4 A = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 B = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 expected = new Matrix4( 0, 2, 4, 6, - 8, 10, 12, 14, - 16, 18, 20, 22, - 24, 26, 28, 30); - - Matrix4 result = A + B; - Assert.IsTrue(expected == result); - } - - [Test] - public void Matrix4_Matrix4MinusMatrix4_operator() - { - Matrix4 A = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 B = new Matrix4( 0, 1, 2, 3, - 4, 5, 6, 7, - 8, 9, 10, 11, - 12, 13, 14, 15); - - Matrix4 expected = new Matrix4( 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0, - 0, 0, 0, 0); - - Matrix4 result = A - B; - Assert.IsTrue(expected == result); - } - - [Test] - public void Matrix4_Index_Operator() - { - Matrix4 A = new Matrix4(); - A[0, 0] = 0; - A[0, 1] = 1; - A[0, 2] = 2; - A[0, 3] = 3; - A[1, 0] = 4; - A[1, 1] = 5; - A[1, 2] = 6; - A[1, 3] = 7; - A[2, 0] = 8; - A[2, 1] = 9; - A[2, 2] = 10; - A[2, 3] = 11; - A[3, 0] = 12; - A[3, 1] = 13; - A[3, 2] = 14; - A[3, 3] = 15; - Assert.AreEqual(0, A[0, 0]); - Assert.AreEqual(1, A[0, 1]); - Assert.AreEqual(2, A[0, 2]); - Assert.AreEqual(3, A[0, 3]); - Assert.AreEqual(4, A[1, 0]); - Assert.AreEqual(5, A[1, 1]); - Assert.AreEqual(6, A[1, 2]); - Assert.AreEqual(7, A[1, 3]); - Assert.AreEqual(8, A[2, 0]); - Assert.AreEqual(9, A[2, 1]); - Assert.AreEqual(10, A[2, 2]); - Assert.AreEqual(11, A[2, 3]); - Assert.AreEqual(12, A[3, 0]); - Assert.AreEqual(13, A[3, 1]); - Assert.AreEqual(14, A[3, 2]); - Assert.AreEqual(15, A[3, 3]); - } - - [Test] - public void Matrix4_Index_NegativeIndexException() - { - Matrix4 A = new Matrix4(); - bool negativeIndexException = false; - try - { - A[-1, 2] = 0; - } - catch(Exception) - { - negativeIndexException = true; - } - Assert.IsTrue(negativeIndexException); - - negativeIndexException = false; - try - { - A[1, -2] = 0; - } - catch (Exception) - { - negativeIndexException = true; - } - Assert.IsTrue(negativeIndexException); - - negativeIndexException = false; - try - { - A[-1, -2] = 0; - } - catch (Exception) - { - negativeIndexException = true; - } - Assert.IsTrue(negativeIndexException); - } - - [Test] - public void Matrix4_Index_LargeIndexException() - { - Matrix4 A = new Matrix4(); - bool largeIndexException = false; - try - { - A[5, 2] = 0; - } - catch (Exception) - { - largeIndexException = true; - } - Assert.IsTrue(largeIndexException); - - largeIndexException = false; - try - { - A[1, 6] = 0; - } - catch (Exception) - { - largeIndexException = true; - } - Assert.IsTrue(largeIndexException); - - largeIndexException = false; - try - { - A[7, 12] = 0; - } - catch (Exception) - { - largeIndexException = true; - } - Assert.IsTrue(largeIndexException); - } - } -} diff --git a/tests/OpenTK.Tests/OpenTK.Tests.csproj b/tests/OpenTK.Tests/OpenTK.Tests.csproj deleted file mode 100644 index f4d82e04..00000000 --- a/tests/OpenTK.Tests/OpenTK.Tests.csproj +++ /dev/null @@ -1,87 +0,0 @@ - - - - - Debug - AnyCPU - {930A780C-A67C-422F-9EED-DB38DAA47AB0} - Library - Properties - OpenTK.Tests - OpenTK.Tests - v4.0 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll - False - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.interfaces.dll - False - - - ..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll - True - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\nunit.util.dll - False - - - ..\..\packages\NUnitTestAdapter.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll - False - - - - - - - - - - - - - - - - - - - - {a37a7e14-0000-0000-0000-000000000000} - OpenTK - - - - - - - - \ No newline at end of file diff --git a/tests/OpenTK.Tests/Properties/AssemblyInfo.cs b/tests/OpenTK.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index fac1b001..00000000 --- a/tests/OpenTK.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("OpenTK.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("OpenTK.Tests")] -[assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("8a03c40d-007c-4a15-ab0c-2111969ea6df")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/tests/OpenTK.Tests/Vector3Tests.cs b/tests/OpenTK.Tests/Vector3Tests.cs deleted file mode 100644 index 16db4735..00000000 --- a/tests/OpenTK.Tests/Vector3Tests.cs +++ /dev/null @@ -1,439 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NUnit.Framework; -using OpenTK; - -namespace OpenTK.Tests -{ - [TestFixture] - public class Vector3Tests - { - [Test] - public void Vector3_SingleValueConstructor() - { - Vector3 V = new Vector3(1); - Assert.AreEqual(1, V.X); - Assert.AreEqual(1, V.Y); - Assert.AreEqual(1, V.Z); - } - - [Test] - public void Vector3_ThreeValueConstructor() - { - Vector3 V = new Vector3(1,2,3); - Assert.AreEqual(1, V.X); - Assert.AreEqual(2, V.Y); - Assert.AreEqual(3, V.Z); - } - - [Test] - public void Vector3_Vector2Constructor() - { - Vector2 T = new Vector2(1, 2); - Vector3 V = new Vector3(T); - Assert.AreEqual(T.X, V.X); - Assert.AreEqual(T.Y, V.Y); - Assert.AreEqual(0, V.Z); - } - - [Test] - public void Vector3_Vector3Constructor() - { - Vector3 U = new Vector3(1, 2, 3); - Vector3 V = new Vector3(U); - Assert.IsTrue(U == V); - } - - [Test] - public void Vector3_Vector4Constructor() - { - Vector4 T = new Vector4(1, 2, 3, 0); - Vector3 V = new Vector3(T); - Assert.AreEqual(T.X, V.X); - Assert.AreEqual(T.Y, V.Y); - Assert.AreEqual(T.Z, V.Z); - } - - [Test] - public void Vector3_Index_operator() - { - Vector3 V = new Vector3(); - V[0] = 1; V[1] = 2; V[2] = 3; - Assert.AreEqual(1, V[0]); - Assert.AreEqual(2, V[1]); - Assert.AreEqual(3, V[2]); - } - - [Test] - public void Vector3_Index_NegativeExceptin() - { - //the syntax for an expected exception changes from - //NUnit 2.6.4 / Microsoft Unit Test to NUnit 3+ - //but a try-catch block is always guaranteed to work - Vector3 V = new Vector3(); - bool negativeIndexExceptionFound = false; - try - { - V[-1] = 5; - } - catch (Exception) - { - negativeIndexExceptionFound = true; - } - Assert.IsTrue(negativeIndexExceptionFound); - } - - [Test] - public void Vector3_Index_LargeIndexExceptin() - { - //the syntax for an expected exception changes from - //NUnit 2.6.4 / Microsoft Unit Test to NUnit 3+ - //but a try-catch block is always guaranteed to work - Vector3 V = new Vector3(); - bool largeIndexExceptionFound = false; - try - { - V[3] = 6; - } - catch (Exception) - { - largeIndexExceptionFound = true; - } - Assert.IsTrue(largeIndexExceptionFound); - } - - [Test] - public void Vector3_Length() - { - float X = 1, Y = 2, Z = 2; - Vector3 U = new Vector3(X, Y, Z); - Assert.AreEqual((float)System.Math.Sqrt(X * X + Y * Y + Z * Z), U.Length); - } - - [Test] - public void Vector3_LengthFast() - { - float X = 1, Y = 2, Z = 2; - Vector3 U = new Vector3(X, Y, Z); - Assert.AreEqual(1.0f / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z), U.LengthFast); - } - - [Test] - public void Vector3_Normalized() - { - float X = 2, Y = 4, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - float length = U.Length; - Vector3 V = U.Normalized(); - Assert.AreEqual(U.X / length, V.X); - Assert.AreEqual(U.Y / length, V.Y); - Assert.AreEqual(U.Z / length, V.Z); - } - - [Test] - public void Vector3_NormalizeFast_Instance() - { - float X = 2, Y = 4, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - Vector3 V = U; - V.NormalizeFast(); - float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z); - Assert.AreEqual(U.X * scale, V.X); - Assert.AreEqual(U.Y * scale, V.Y); - Assert.AreEqual(U.Z * scale, V.Z); - } - - [Test] - public void Vector3_Add() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - Vector3 V = Vector3.Add(T, U); - Assert.AreEqual(T.X + U.X, V.X); - Assert.AreEqual(T.Y + U.Y, V.Y); - Assert.AreEqual(T.Z + U.Z, V.Z); - } - - [Test] - public void Vector3_Subtract() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - Vector3 V = Vector3.Subtract(T, U); - Assert.AreEqual(T.X - U.X, V.X); - Assert.AreEqual(T.Y - U.Y, V.Y); - Assert.AreEqual(T.Z - U.Z, V.Z); - } - - [Test] - public void Vector3_Multiply_Scalar() - { - float scalar = 5.5f; - Vector3 U = new Vector3(23, 89, -34); - Vector3 V = Vector3.Multiply(U, scalar); - Assert.AreEqual(U.X * scalar, V.X); - Assert.AreEqual(U.Y * scalar, V.Y); - Assert.AreEqual(U.Z * scalar, V.Z); - } - - [Test] - public void Vector3_Multiply_Componentwise() - { - Vector3 T = new Vector3(7, 8, 0.5f); - Vector3 U = new Vector3(23, 89, -34); - Vector3 V = Vector3.Multiply(T, U); - Assert.AreEqual(T.X * U.X, V.X); - Assert.AreEqual(T.Y * U.Y, V.Y); - Assert.AreEqual(T.Z * U.Z, V.Z); - } - - [Test] - public void Vector3_Divide_Scalar() - { - float scalar = 5.5f; - Vector3 U = new Vector3(23, 89, -34); - Vector3 V = Vector3.Divide(U, scalar); - //we have to account for a small amount of round off error - //in this division test - Assert.IsTrue(Math.Abs((U.X / scalar) - V.X) < 1e-5); - Assert.IsTrue(Math.Abs((U.Y / scalar) - V.Y) < 1e-5); - Assert.IsTrue(Math.Abs((U.Z / scalar) - V.Z) < 1e-5); - } - - [Test] - public void Vector3_ComponentMin() - { - Vector3 T = new Vector3(1, 55, -100); - Vector3 U = new Vector3(24, 3, 1); - Vector3 V = Vector3.ComponentMin(T, U); - Assert.AreEqual(1, V.X); - Assert.AreEqual(3, V.Y); - Assert.AreEqual(-100, V.Z); - } - - [Test] - public void Vector3_ComponentMinOut() - { - Vector3 T = new Vector3(1, 55, -100); - Vector3 U = new Vector3(24, 3, 1); - Vector3 V; - Vector3.ComponentMin(ref T, ref U, out V); - Assert.AreEqual(1, V.X); - Assert.AreEqual(3, V.Y); - Assert.AreEqual(-100, V.Z); - } - - [Test] - public void Vector3_ComponentMax() - { - Vector3 T = new Vector3(1, 55, -100); - Vector3 U = new Vector3(24, 3, 1); - Vector3 V = Vector3.ComponentMax(T, U); - Assert.AreEqual(24, V.X); - Assert.AreEqual(55, V.Y); - Assert.AreEqual(1, V.Z); - } - - [Test] - public void Vector3_ComponentMaxOut() - { - Vector3 T = new Vector3(1, 55, -100); - Vector3 U = new Vector3(24, 3, 1); - Vector3 V; - Vector3.ComponentMax(ref T, ref U, out V); - Assert.AreEqual(24, V.X); - Assert.AreEqual(55, V.Y); - Assert.AreEqual(1, V.Z); - } - - [Test] - public void Vector3_Min() - { - Vector3 T = new Vector3(1, 2, 3); - Vector3 U = new Vector3(24, 300, 88); - Vector3 result = Vector3.Min(T, U); - Assert.IsTrue(result == T); - } - - [Test] - public void Vector3_Max() - { - Vector3 T = new Vector3(1, 2, 3); - Vector3 U = new Vector3(24, 300, 88); - Vector3 result = Vector3.Max(T, U); - Assert.IsTrue(result == U); - } - - [Test] - public void Vector3_Clamp() - { - Vector3 V = new Vector3(-6, 302, -22); - Vector3 min = new Vector3(-5, -10, -20); - Vector3 max = new Vector3(24, 300, 55); - Vector3 result = Vector3.Clamp(V, min, max); - Assert.AreEqual(result.X, -5); - Assert.AreEqual(result.Y, 300); - Assert.AreEqual(result.Z, -20); - } - - [Test] - public void Vector3_ClampOut() - { - Vector3 V = new Vector3(-6, 302, -22); - Vector3 min = new Vector3(-5, -10, -20); - Vector3 max = new Vector3(24, 300, 55); - Vector3 result; - Vector3.Clamp(ref V, ref min, ref max, out result); - Assert.AreEqual(result.X, -5); - Assert.AreEqual(result.Y, 300); - Assert.AreEqual(result.Z, -20); - } - - [Test] - public void Vector3_Normalize() - { - float X = 64, Y = 144, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - Vector3 V = Vector3.Normalize(U); - float length = U.Length; - Assert.IsTrue(Math.Abs((U.X / length) - V.X) < 1e-5); - Assert.IsTrue(Math.Abs((U.Y / length) - V.Y) < 1e-5); - Assert.IsTrue(Math.Abs((U.Z / length) - V.Z) < 1e-5); - } - - [Test] - public void Vector3_NormalizeOut() - { - float X = 64, Y = 144, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - Vector3 V; - Vector3.Normalize(ref U, out V); - float length = U.Length; - Assert.IsTrue(Math.Abs((U.X / length) - V.X) < 1e-5); - Assert.IsTrue(Math.Abs((U.Y / length) - V.Y) < 1e-5); - Assert.IsTrue(Math.Abs((U.Z / length) - V.Z) < 1e-5); - } - - [Test] - public void Vector3_NormalizeFast_Static() - { - float X = 64, Y = 144, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - Vector3 V = Vector3.NormalizeFast(U); - float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z); - Assert.AreEqual(U.X * scale, V.X); - Assert.AreEqual(U.Y * scale, V.Y); - Assert.AreEqual(U.Z * scale, V.Z); - } - - [Test] - public void Vector3_NormalizeFast() - { - float X = 64, Y = 144, Z = 16; - Vector3 U = new Vector3(X, Y, Z); - Vector3 V; - Vector3.NormalizeFast(ref U, out V); - float scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z); - Assert.AreEqual(U.X * scale, V.X); - Assert.AreEqual(U.Y * scale, V.Y); - Assert.AreEqual(U.Z * scale, V.Z); - } - - [Test] - public void Vector3_Dot() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - float dot = Vector3.Dot(T, U); - float expected = T.X * U.X + T.Y * U.Y + T.Z * U.Z; - Assert.AreEqual(expected, dot); - } - - [Test] - public void Vector3_Cross() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - Vector3 expected = new Vector3(-1073, 445, 439); - Vector3 result = Vector3.Cross(T, U); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_Lerp() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - float blend = 0.25f; - Vector3 expected = blend * (U - T) + T; - Vector3 result = Vector3.Lerp(T, U, blend); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_LerpOut() - { - Vector3 T = new Vector3(7, 8, 9); - Vector3 U = new Vector3(23, 89, -34); - float blend = 0.25f; - Vector3 expected = blend * (U - T) + T; - Vector3 result; - Vector3.Lerp(ref T, ref U, blend, out result); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_BaryCentric() - { - Vector3 a = new Vector3(7, 8, 9); - Vector3 b = new Vector3(23, 89, -34); - Vector3 c = new Vector3(88, -42, 39); - float u = 0.25f; - float v = 0.75f; - Vector3 expected = a + u * (b - a) + v * (c - a); - Vector3 result = Vector3.BaryCentric(a, b, c, u, v); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_BaryCentricOut() - { - Vector3 a = new Vector3(7, 8, 9); - Vector3 b = new Vector3(23, 89, -34); - Vector3 c = new Vector3(88, -42, 39); - float u = 0.25f; - float v = 0.75f; - Vector3 expected = a + u * (b - a) + v * (c - a); - Vector3 result; - Vector3.BaryCentric(ref a, ref b, ref c, u, v, out result); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_Matrix3TimesVector3_operator() - { - Matrix3 A = new Matrix3(); - A[0, 0] = 16; A[0, 1] = 15; A[0, 2] = 14; - A[1, 0] = 12; A[1, 1] = 11; A[1, 2] = 10; - A[2, 0] = 8; A[2, 1] = 7; A[2, 2] = 6; - - Vector3 input = new Vector3(1, 5, 9); - Vector3 result = A * input; - OpenTK.Vector3 expected = new OpenTK.Vector3(217, 157, 97); - Assert.IsTrue(expected == result); - } - - [Test] - public void Vector3_Equal_operator() - { - Vector3 V = new Vector3(1, 2, 3); - Vector3 U = new Vector3(1, 2, 3); - Assert.IsTrue(U == V); - } - - - } -} diff --git a/tests/OpenTK.Tests/packages.config b/tests/OpenTK.Tests/packages.config deleted file mode 100644 index 1f8800b2..00000000 --- a/tests/OpenTK.Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From 5cb6090343497bf477fb5a6cc63eb59b86bc1db0 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 13:34:47 +0200 Subject: [PATCH 02/66] Add property based testing framework + example for vectors --- OpenTK.sln | 7 + paket.dependencies | 1 + paket.lock | 652 +++++++--- tests/OpenTK.Tests/App.config | 17 + tests/OpenTK.Tests/AssemblyInfo.fs | 41 + tests/OpenTK.Tests/OpenTK.Tests.fsproj | 1503 ++++++++++++++++++++++++ tests/OpenTK.Tests/Vectors.fs | 86 ++ tests/OpenTK.Tests/paket.references | 2 + 8 files changed, 2170 insertions(+), 139 deletions(-) create mode 100644 tests/OpenTK.Tests/App.config create mode 100644 tests/OpenTK.Tests/AssemblyInfo.fs create mode 100644 tests/OpenTK.Tests/OpenTK.Tests.fsproj create mode 100644 tests/OpenTK.Tests/Vectors.fs create mode 100644 tests/OpenTK.Tests/paket.references diff --git a/OpenTK.sln b/OpenTK.sln index f8a9c184..a57a63b9 100644 --- a/OpenTK.sln +++ b/OpenTK.sln @@ -36,6 +36,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{5EEE RELEASE_NOTES.md = RELEASE_NOTES.md EndProjectSection EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests", "tests\OpenTK.Tests\OpenTK.Tests.fsproj", "{6801C263-ADDA-4A7B-979D-649BCB5A1DF7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -78,12 +80,17 @@ Global {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Debug|Any CPU.Build.0 = Debug|Any CPU {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Release|Any CPU.ActiveCfg = Release|Any CPU {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99}.Release|Any CPU.Build.0 = Release|Any CPU + {6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6801C263-ADDA-4A7B-979D-649BCB5A1DF7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {C4DDD20F-CB4E-43F4-A75C-4A3D668E1F99} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B} + {6801C263-ADDA-4A7B-979D-649BCB5A1DF7} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Source\Examples\OpenTK.Examples.csproj diff --git a/paket.dependencies b/paket.dependencies index f7f692c6..1df3fa40 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -3,6 +3,7 @@ source https://nuget.org/api/v2 #Open packages nuget FSharp.Formatting +nuget FsCheck nuget FsCheck.Xunit nuget xunit.runner.console nuget xunit.assert diff --git a/paket.lock b/paket.lock index 0b74580d..8fcfa088 100644 --- a/paket.lock +++ b/paket.lock @@ -1,11 +1,11 @@ NUGET remote: https://www.nuget.org/api/v2 FAKE (4.28) - FsCheck (2.4) + FsCheck (2.8) FSharp.Core (>= 3.1.2.5) - FsCheck.Xunit (2.4) - FsCheck (>= 2.4) - xunit.extensibility.execution (>= 2.1 < 3.0) + FsCheck.Xunit (2.8) + FsCheck (>= 2.8) + xunit.extensibility.execution (>= 2.2 < 3.0) FSharp.Compiler.Service (2.0.0.6) FSharp.Core (4.0.0.1) FSharp.Formatting (2.14.4) @@ -14,124 +14,510 @@ NUGET FSharpVSPowerTools.Core (2.3) FSharp.Compiler.Service (>= 2.0.0.3) GtkSharp (3.1.3) + Microsoft.NETCore.Platforms (1.1) - framework: >= net452, dnxcore50, >= netstandard11, netstandard12, netstandard13, netstandard14 + Microsoft.NETCore.Targets (1.1) - framework: >= net452, dnxcore50, >= netstandard11, netstandard12, netstandard13, netstandard14 + Microsoft.Win32.Primitives (4.3) - framework: >= net452, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 Mono.Cecil (0.9.6.1) - System.Collections (4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Contracts (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Globalization (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.IO (4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Text.Encoding (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.Encoding.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.Linq (4.0) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Linq.Expressions (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.ObjectModel (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit (>= 4.0) - framework: dnxcore50 - System.Reflection.Extensions (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.ObjectModel (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Private.Uri (4.0) - framework: dnxcore50 - System.Reflection (4.0.10) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Reflection.Emit (4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit.ILGeneration (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Reflection.Emit.ILGeneration (4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Reflection.Extensions (4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Reflection.TypeExtensions (4.0) - framework: dnxcore50 - System.Diagnostics.Contracts (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0.10) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Reflection.Primitives (>= 4.0) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (4.0) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime (4.0.20) - framework: dnxcore50 - System.Private.Uri (>= 4.0) - framework: dnxcore50 - System.Runtime.Extensions (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Text.Encoding (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Text.Encoding.Extensions (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0.10) - framework: dnxcore50 - System.Text.RegularExpressions (4.0.10) - framework: dnxcore50 - System.Collections (>= 4.0.10) - framework: dnxcore50 - System.Globalization (>= 4.0.10) - framework: dnxcore50 - System.Resources.ResourceManager (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0.20) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0.10) - framework: dnxcore50 - System.Threading (>= 4.0.10) - framework: dnxcore50 - System.Threading (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (4.0.10) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - xunit.abstractions (2.0) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1 + NETStandard.Library (1.6.1) - framework: >= net452, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard10 + Microsoft.Win32.Primitives (>= 4.3) - framework: >= net46, >= netstandard13 + System.AppContext (>= 4.3) - framework: >= net46, >= netstandard13 + System.Collections (>= 4.3) - framework: >= netstandard10 + System.Collections.Concurrent (>= 4.3) - framework: >= net45, >= netstandard11 + System.Console (>= 4.3) - framework: >= net46, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: >= netstandard10 + System.Diagnostics.Tools (>= 4.3) - framework: >= netstandard10 + System.Diagnostics.Tracing (>= 4.3) - framework: >= net45, >= netstandard11 + System.Globalization (>= 4.3) - framework: >= netstandard10 + System.Globalization.Calendars (>= 4.3) - framework: >= net46, >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard10 + System.IO.Compression (>= 4.3) - framework: >= net45, >= netstandard11 + System.IO.Compression.ZipFile (>= 4.3) - framework: >= net46, >= netstandard13 + System.IO.FileSystem (>= 4.3) - framework: >= net46, >= netstandard13 + System.IO.FileSystem.Primitives (>= 4.3) - framework: >= net46, >= netstandard13 + System.Linq (>= 4.3) - framework: >= netstandard10 + System.Linq.Expressions (>= 4.3) - framework: >= netstandard10 + System.Net.Http (>= 4.3) - framework: >= net45, >= netstandard11 + System.Net.Primitives (>= 4.3) - framework: >= netstandard10 + System.Net.Sockets (>= 4.3) - framework: >= net46, >= netstandard13 + System.ObjectModel (>= 4.3) - framework: >= netstandard10 + System.Reflection (>= 4.3) - framework: >= netstandard10 + System.Reflection.Extensions (>= 4.3) - framework: >= netstandard10 + System.Reflection.Primitives (>= 4.3) - framework: >= netstandard10 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard10 + System.Runtime (>= 4.3) - framework: >= netstandard10 + System.Runtime.Extensions (>= 4.3) - framework: >= netstandard10 + System.Runtime.Handles (>= 4.3) - framework: >= net46, >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: >= net45, >= netstandard11 + System.Runtime.InteropServices.RuntimeInformation (>= 4.3) - framework: >= net45, >= netstandard11 + System.Runtime.Numerics (>= 4.3) - framework: >= net45, >= netstandard11 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: >= net46, >= netstandard13 + System.Security.Cryptography.Encoding (>= 4.3) - framework: >= net46, >= netstandard13 + System.Security.Cryptography.Primitives (>= 4.3) - framework: >= net46, >= netstandard13 + System.Security.Cryptography.X509Certificates (>= 4.3) - framework: >= net46, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard10 + System.Text.Encoding.Extensions (>= 4.3) - framework: >= netstandard10 + System.Text.RegularExpressions (>= 4.3) - framework: >= netstandard10 + System.Threading (>= 4.3) - framework: >= netstandard10 + System.Threading.Tasks (>= 4.3) - framework: >= netstandard10 + System.Threading.Timer (>= 4.3) - framework: >= net451, >= netstandard12 + System.Xml.ReaderWriter (>= 4.3) - framework: >= netstandard10 + System.Xml.XDocument (>= 4.3) - framework: >= netstandard10 + runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.fedora.24-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.native.System (4.3) - framework: >= net452, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.NETCore.Targets (>= 1.1) + runtime.native.System.IO.Compression (4.3) - framework: >= net452, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.NETCore.Targets (>= 1.1) + runtime.native.System.Net.Http (4.3) - framework: >= net452, >= netstandard16 + Microsoft.NETCore.Platforms (>= 1.1) + Microsoft.NETCore.Targets (>= 1.1) + runtime.native.System.Security.Cryptography.Apple (4.3) - framework: >= net452, >= netstandard16 + runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.Apple (>= 4.3) + runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.fedora.24-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.opensuse.42.1-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.rhel.7-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.opensuse.42.1-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.Apple (4.3) - framework: >= net452, >= netstandard16 + runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.rhel.7-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard13, netstandard14 + System.AppContext (4.3) - framework: >= net46, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Buffers (4.3) - framework: >= net452, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: >= netstandard11 + System.Diagnostics.Tracing (>= 4.3) - framework: >= netstandard11 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard11 + System.Runtime (>= 4.3) - framework: >= netstandard11 + System.Threading (>= 4.3) - framework: >= netstandard11 + System.Collections (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Collections.Concurrent (4.3) - framework: >= net452, >= netstandard11, netstandard14 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Tracing (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Reflection (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Console (4.3) - framework: >= net46, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard13 + System.Diagnostics.Contracts (4.3) - framework: dnxcore50 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Diagnostics.Debug (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Diagnostics.DiagnosticSource (4.3) - framework: >= net452, netstandard13, >= netstandard16 + System.Collections (>= 4.3) - framework: netstandard11, >= netstandard13 + System.Diagnostics.Tracing (>= 4.3) - framework: netstandard11, >= netstandard13 + System.Reflection (>= 4.3) - framework: netstandard11, >= netstandard13 + System.Runtime (>= 4.3) - framework: netstandard11, >= netstandard13 + System.Threading (>= 4.3) - framework: netstandard11, >= netstandard13 + System.Diagnostics.Tools (4.3) - framework: >= net452, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard10 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, >= netstandard10 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Diagnostics.Tracing (4.3) - framework: >= net452, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Globalization (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Globalization.Calendars (4.3) - framework: >= net46, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.Globalization (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Globalization.Extensions (4.3) - framework: >= net452, >= netstandard16 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + System.Globalization (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: >= netstandard13 + System.IO (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.IO.Compression (4.3) - framework: >= net452, >= netstandard11, netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + runtime.native.System (>= 4.3) - framework: >= netstandard13 + runtime.native.System.IO.Compression (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Buffers (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.IO (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime.Handles (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.IO.Compression.ZipFile (4.3) - framework: >= net46, >= netstandard13 + System.Buffers (>= 4.3) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.IO.Compression (>= 4.3) - framework: >= netstandard13 + System.IO.FileSystem (>= 4.3) - framework: >= netstandard13 + System.IO.FileSystem.Primitives (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard13 + System.IO.FileSystem (4.3) - framework: >= net452, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.IO.FileSystem.Primitives (>= 4.3) - framework: >= net46, >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.Handles (>= 4.3) - framework: >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: >= netstandard13 + System.IO.FileSystem.Primitives (4.3) - framework: >= net452, >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Linq (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard14 + System.Collections (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard16 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Linq.Expressions (4.3) - framework: >= net452, >= netstandard11 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.IO (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Linq (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.ObjectModel (>= 4.3) - framework: >= netstandard16 + System.Reflection (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard16 + System.Reflection.Emit (>= 4.3) - framework: >= netstandard16 + System.Reflection.Emit.ILGeneration (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Reflection.Emit.Lightweight (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Reflection.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Reflection.Primitives (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Reflection.TypeExtensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Net.Http (4.3.1) - framework: >= net452, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard13, >= netstandard16 + Microsoft.Win32.Primitives (>= 4.3) - framework: netstandard13 + runtime.native.System (>= 4.3) - framework: >= netstandard16 + runtime.native.System.Net.Http (>= 4.3) - framework: >= netstandard16 + runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard16 + System.Collections (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Diagnostics.DiagnosticSource (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Diagnostics.Tracing (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Globalization (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Globalization.Extensions (>= 4.3) - framework: >= netstandard16 + System.IO (>= 4.3) - framework: dnxcore50, netstandard11, netstandard13, >= netstandard16 + System.IO.Compression (>= 4.3) - framework: netstandard13 + System.IO.FileSystem (>= 4.3) - framework: >= netstandard16 + System.Net.Primitives (>= 4.3) - framework: dnxcore50, netstandard11, netstandard13, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard11, netstandard13, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Runtime.Handles (>= 4.3) - framework: netstandard13, >= netstandard16 + System.Runtime.InteropServices (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Encoding (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Primitives (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.X509Certificates (>= 4.3) - framework: >= net46, dnxcore50, netstandard13, >= netstandard16 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, netstandard11, netstandard13, >= netstandard16 + System.Threading (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard16 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, netstandard11, netstandard13, >= netstandard16 + System.Net.Primitives (4.3) - framework: >= net452, >= netstandard11, netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, netstandard11, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, netstandard11, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard11, >= netstandard13 + System.Runtime.Handles (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Net.Sockets (4.3) - framework: >= net46, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.Net.Primitives (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: >= netstandard13 + System.ObjectModel (4.3) - framework: >= net452, dnxcore50, >= netstandard11 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Reflection (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard12, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.IO (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Reflection.Primitives (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Reflection.Emit (4.3) - framework: >= net452, >= netstandard16 + System.IO (>= 4.3) - framework: >= netstandard11 + System.Reflection (>= 4.3) - framework: >= netstandard11 + System.Reflection.Emit.ILGeneration (>= 4.3) - framework: >= netstandard11 + System.Reflection.Primitives (>= 4.3) - framework: >= netstandard11 + System.Runtime (>= 4.3) - framework: >= netstandard11 + System.Reflection.Emit.ILGeneration (4.3) - framework: >= net452, >= netstandard16 + System.Reflection (>= 4.3) - framework: >= netstandard10 + System.Reflection.Primitives (>= 4.3) - framework: >= netstandard10 + System.Runtime (>= 4.3) - framework: >= netstandard10 + System.Reflection.Emit.Lightweight (4.3) - framework: >= net452, >= netstandard16 + System.Reflection (>= 4.3) - framework: >= netstandard10 + System.Reflection.Emit.ILGeneration (>= 4.3) - framework: >= netstandard10 + System.Reflection.Primitives (>= 4.3) - framework: >= netstandard10 + System.Runtime (>= 4.3) - framework: >= netstandard10 + System.Reflection.Extensions (4.3) - framework: >= net452, dnxcore50, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard10 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, >= netstandard10 + System.Reflection (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Reflection.Primitives (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard12, netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard10 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, >= netstandard10 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Reflection.TypeExtensions (4.3) - framework: >= net452, dnxcore50, >= netstandard16 + System.Diagnostics.Contracts (>= 4.3) - framework: dnxcore50 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50 + System.Linq (>= 4.3) - framework: dnxcore50 + System.Reflection (>= 4.3) - framework: >= net462, dnxcore50, netstandard13, >= netstandard15 + System.Reflection.Primitives (>= 4.3) - framework: dnxcore50 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard15 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50 + System.Resources.ResourceManager (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard10 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, >= netstandard10 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Reflection (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard10 + System.Runtime (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard12, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, netstandard12, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, netstandard12, netstandard13, >= netstandard15 + System.Runtime.Extensions (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard15 + System.Runtime.Handles (4.3) - framework: >= net452, >= netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.InteropServices (4.3) - framework: >= net452, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Reflection (>= 4.3) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Reflection.Primitives (>= 4.3) - framework: dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Runtime (>= 4.3) - framework: net462, >= net463, dnxcore50, netstandard11, netstandard12, netstandard13, >= netstandard15 + System.Runtime.Handles (>= 4.3) - framework: dnxcore50, netstandard13, >= netstandard15 + System.Runtime.InteropServices.RuntimeInformation (4.3) - framework: >= net452, >= netstandard11 + runtime.native.System (>= 4.3) - framework: >= netstandard11 + System.Reflection (>= 4.3) - framework: dnxcore50, >= netstandard11 + System.Reflection.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard11 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard11 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard11 + System.Runtime.InteropServices (>= 4.3) - framework: >= netstandard11 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard11 + System.Runtime.Numerics (4.3) - framework: >= net452, >= netstandard11 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard11, >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Security.Cryptography.Algorithms (4.3) - framework: >= net452, >= netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard16 + runtime.native.System.Security.Cryptography.Apple (>= 4.3) - framework: >= netstandard16 + runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard16 + System.Collections (>= 4.3) - framework: >= netstandard16 + System.IO (>= 4.3) - framework: >= net463, dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime (>= 4.3) - framework: >= net463, dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime.Handles (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime.InteropServices (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime.Numerics (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Encoding (>= 4.3) - framework: >= net463, dnxcore50, >= netstandard16 + System.Security.Cryptography.Primitives (>= 4.3) - framework: net46, net461, >= net463, dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Security.Cryptography.Cng (4.3) - framework: >= net46, >= netstandard16 + Microsoft.NETCore.Platforms (>= 1.1) - framework: netstandard14, >= netstandard16 + System.IO (>= 4.3) - framework: netstandard13, netstandard14, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: netstandard14, >= netstandard16 + System.Runtime (>= 4.3) - framework: netstandard13, netstandard14, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: netstandard14, >= netstandard16 + System.Runtime.Handles (>= 4.3) - framework: netstandard13, netstandard14, >= netstandard16 + System.Runtime.InteropServices (>= 4.3) - framework: netstandard14, >= netstandard16 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: net46, net461, >= net463, netstandard13, netstandard14, >= netstandard16 + System.Security.Cryptography.Encoding (>= 4.3) - framework: netstandard14, >= netstandard16 + System.Security.Cryptography.Primitives (>= 4.3) - framework: net46, net461, >= net463, netstandard13, netstandard14, >= netstandard16 + System.Text.Encoding (>= 4.3) - framework: netstandard14, >= netstandard16 + System.Security.Cryptography.Csp (4.3) - framework: >= net46, >= netstandard16 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.Reflection (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: >= netstandard13 + System.Runtime.Handles (>= 4.3) - framework: >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: >= net46, >= netstandard13 + System.Security.Cryptography.Encoding (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.Primitives (>= 4.3) - framework: >= net46, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard13 + System.Threading (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.Encoding (4.3) - framework: >= net452, >= netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: >= netstandard13 + runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard13 + System.Collections (>= 4.3) - framework: >= netstandard13 + System.Collections.Concurrent (>= 4.3) - framework: >= netstandard13 + System.Linq (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: >= netstandard13 + System.Runtime.Handles (>= 4.3) - framework: >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.Primitives (>= 4.3) - framework: >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.OpenSsl (4.3) - framework: >= net452, >= netstandard16 + runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) + System.Collections (>= 4.3) - framework: >= netstandard16 + System.IO (>= 4.3) - framework: >= net463, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard16 + System.Runtime (>= 4.3) - framework: >= net463, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: >= net463, >= netstandard16 + System.Runtime.Handles (>= 4.3) - framework: >= netstandard16 + System.Runtime.InteropServices (>= 4.3) - framework: >= netstandard16 + System.Runtime.Numerics (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: >= net463, >= netstandard16 + System.Security.Cryptography.Encoding (>= 4.3) - framework: >= net463, >= netstandard16 + System.Security.Cryptography.Primitives (>= 4.3) - framework: >= net463, >= netstandard16 + System.Text.Encoding (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Primitives (4.3) - framework: >= net452, >= netstandard13, netstandard14 + System.Diagnostics.Debug (>= 4.3) - framework: >= netstandard13 + System.Globalization (>= 4.3) - framework: >= netstandard13 + System.IO (>= 4.3) - framework: >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: >= netstandard13 + System.Runtime (>= 4.3) - framework: >= netstandard13 + System.Threading (>= 4.3) - framework: >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: >= netstandard13 + System.Security.Cryptography.X509Certificates (4.3) - framework: >= net46, >= netstandard13 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard16 + runtime.native.System (>= 4.3) - framework: >= netstandard16 + runtime.native.System.Net.Http (>= 4.3) - framework: >= netstandard16 + runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard16 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Diagnostics.Debug (>= 4.3) - framework: >= netstandard16 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Globalization.Calendars (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.IO (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.IO.FileSystem (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.IO.FileSystem.Primitives (>= 4.3) - framework: >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime.Handles (>= 4.3) - framework: dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Runtime.InteropServices (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime.Numerics (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Security.Cryptography.Algorithms (>= 4.3) - framework: net46, >= net461, dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Security.Cryptography.Cng (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Security.Cryptography.Csp (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Encoding (>= 4.3) - framework: net46, >= net461, dnxcore50, netstandard13, netstandard14, >= netstandard16 + System.Security.Cryptography.OpenSsl (>= 4.3) - framework: >= netstandard16 + System.Security.Cryptography.Primitives (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Text.Encoding (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Text.Encoding.Extensions (4.3) - framework: >= net452, >= netstandard11 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Text.RegularExpressions (4.3) - framework: >= net452, dnxcore50, >= netstandard11 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, netstandard13, >= netstandard16 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard16 + System.Threading (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Threading.Tasks (4.3) - framework: >= net452, dnxcore50, >= netstandard11, netstandard13, netstandard14 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Threading.Tasks.Extensions (4.3) - framework: >= net452, >= netstandard13 + System.Collections (>= 4.3) - framework: >= netstandard10 + System.Runtime (>= 4.3) - framework: >= netstandard10 + System.Threading.Tasks (>= 4.3) - framework: >= netstandard10 + System.Threading.Timer (4.3) - framework: >= net452, >= netstandard12 + Microsoft.NETCore.Platforms (>= 1.1) - framework: dnxcore50, >= netstandard12 + Microsoft.NETCore.Targets (>= 1.1) - framework: dnxcore50, >= netstandard12 + System.Runtime (>= 4.3) - framework: dnxcore50, >= netstandard12 + System.Xml.ReaderWriter (4.3) - framework: >= net452, >= netstandard11 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.IO (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.IO.FileSystem (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.IO.FileSystem.Primitives (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime.InteropServices (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Text.Encoding.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Text.RegularExpressions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Threading.Tasks (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Threading.Tasks.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Xml.XDocument (4.3) - framework: >= net452, >= netstandard11 + System.Collections (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Debug (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Diagnostics.Tools (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Globalization (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.IO (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Reflection (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Resources.ResourceManager (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Runtime (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + System.Runtime.Extensions (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Text.Encoding (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Threading (>= 4.3) - framework: dnxcore50, >= netstandard13 + System.Xml.ReaderWriter (>= 4.3) - framework: dnxcore50, netstandard10, >= netstandard13 + xunit.abstractions (2.0.1) - framework: >= net452, >= netstandard11 + NETStandard.Library (>= 1.6) - framework: >= netstandard10 xunit.assert (2.1) System.Collections (>= 4.0) - framework: dnxcore50 System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 @@ -144,22 +530,10 @@ NUGET System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 System.Text.RegularExpressions (>= 4.0) - framework: dnxcore50 System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1 - xunit.abstractions (2.0) - xunit.extensibility.execution (2.1) - System.Collections (>= 4.0) - framework: dnxcore50 - System.Diagnostics.Debug (>= 4.0) - framework: dnxcore50 - System.Globalization (>= 4.0) - framework: dnxcore50 - System.IO (>= 4.0) - framework: dnxcore50 - System.Linq (>= 4.0) - framework: dnxcore50 - System.Linq.Expressions (>= 4.0) - framework: dnxcore50 - System.Reflection (>= 4.0) - framework: dnxcore50 - System.Reflection.Extensions (>= 4.0) - framework: dnxcore50 - System.Runtime (>= 4.0) - framework: dnxcore50 - System.Runtime.Extensions (>= 4.0) - framework: dnxcore50 - System.Text.Encoding (>= 4.0) - framework: dnxcore50 - System.Threading (>= 4.0) - framework: dnxcore50 - System.Threading.Tasks (>= 4.0) - framework: dnxcore50 - xunit.abstractions (>= 2.0) - framework: dnxcore50 - xunit.extensibility.core (2.1) - framework: >= net45, dnx451, dnxcore50, monoandroid, monotouch, xamarinios, winv4.5, wpv8.0, wpav8.1 + xunit.extensibility.core (2.2) - framework: >= net452, >= netstandard11 + NETStandard.Library (>= 1.6) - framework: >= netstandard11 + xunit.abstractions (>= 2.0.1) - framework: >= net452, >= netstandard11 + xunit.extensibility.execution (2.2) + NETStandard.Library (>= 1.6) - framework: >= netstandard11 + xunit.extensibility.core (2.2) - framework: >= net452, >= netstandard11 xunit.runner.console (2.1) diff --git a/tests/OpenTK.Tests/App.config b/tests/OpenTK.Tests/App.config new file mode 100644 index 00000000..571e8b49 --- /dev/null +++ b/tests/OpenTK.Tests/App.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/OpenTK.Tests/AssemblyInfo.fs b/tests/OpenTK.Tests/AssemblyInfo.fs new file mode 100644 index 00000000..1d63b8ec --- /dev/null +++ b/tests/OpenTK.Tests/AssemblyInfo.fs @@ -0,0 +1,41 @@ +namespace OpenTK.Tests.AssemblyInfo + +open System.Reflection +open System.Runtime.CompilerServices +open System.Runtime.InteropServices + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[] +[] +[] +[] +[] +[] +[] +[] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [] +[] +[] + +do + () \ No newline at end of file diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj new file mode 100644 index 00000000..46190f28 --- /dev/null +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -0,0 +1,1503 @@ + + + + + Debug + AnyCPU + 2.0 + 6801c263-adda-4a7b-979d-649bcb5a1df7 + Library + OpenTK.Tests + OpenTK.Tests + v4.5.2 + 4.4.0.0 + true + OpenTK.Tests + + + true + full + false + false + bin\Debug\ + DEBUG;TRACE + 3 + bin\Debug\OpenTK.Tests.XML + + + pdbonly + true + true + bin\Release\ + TRACE + 3 + bin\Release\OpenTK.Tests.XML + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + ..\..\packages\FsCheck\lib\net452\FsCheck.dll + True + True + + + + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45\FsCheck.dll + True + True + + + + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45+wp8\FsCheck.dll + True + True + + + + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45+wpa81+wp8\FsCheck.dll + True + True + + + + + + + + + ..\..\packages\FsCheck.Xunit\lib\net452\FsCheck.Xunit.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Win32.Primitives\ref\net46\Microsoft.Win32.Primitives.dll + False + True + + + + + + + ..\..\packages\Microsoft.Win32.Primitives\ref\netstandard1.3\Microsoft.Win32.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.AppContext\ref\net46\System.AppContext.dll + False + True + + + + + + + ..\..\packages\System.AppContext\ref\net463\System.AppContext.dll + False + True + + + + + + + ..\..\packages\System.AppContext\ref\netstandard1.3\System.AppContext.dll + False + True + + + + + + + + + ..\..\packages\System.Buffers\lib\netstandard1.1\System.Buffers.dll + True + True + + + + + + + + + ..\..\packages\System.Collections\ref\netstandard1.0\System.Collections.dll + False + True + + + + + + + ..\..\packages\System.Collections\ref\netstandard1.3\System.Collections.dll + False + True + + + + + + + + + ..\..\packages\System.Collections.Concurrent\ref\netstandard1.1\System.Collections.Concurrent.dll + False + True + + + + + + + ..\..\packages\System.Collections.Concurrent\ref\netstandard1.3\System.Collections.Concurrent.dll + False + True + + + + + + + + + ..\..\packages\System.Console\ref\net46\System.Console.dll + False + True + + + + + + + ..\..\packages\System.Console\ref\netstandard1.3\System.Console.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.Debug\ref\netstandard1.0\System.Diagnostics.Debug.dll + False + True + + + + + + + ..\..\packages\System.Diagnostics.Debug\ref\netstandard1.3\System.Diagnostics.Debug.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\net46\System.Diagnostics.DiagnosticSource.dll + True + True + + + + + + + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\netstandard1.1\System.Diagnostics.DiagnosticSource.dll + True + True + + + + + + + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\netstandard1.3\System.Diagnostics.DiagnosticSource.dll + True + True + + + + + + + + + ..\..\packages\System.Diagnostics.Tools\ref\netstandard1.0\System.Diagnostics.Tools.dll + False + True + + + + + + + + + ..\..\packages\System.Diagnostics.Tracing\ref\net462\System.Diagnostics.Tracing.dll + False + True + + + + + + + ..\..\packages\System.Diagnostics.Tracing\ref\netstandard1.1\System.Diagnostics.Tracing.dll + False + True + + + + + + + ..\..\packages\System.Diagnostics.Tracing\ref\netstandard1.2\System.Diagnostics.Tracing.dll + False + True + + + + + + + ..\..\packages\System.Diagnostics.Tracing\ref\netstandard1.3\System.Diagnostics.Tracing.dll + False + True + + + + + + + ..\..\packages\System.Diagnostics.Tracing\ref\netstandard1.5\System.Diagnostics.Tracing.dll + False + True + + + + + + + + + ..\..\packages\System.Globalization\ref\netstandard1.0\System.Globalization.dll + False + True + + + + + + + ..\..\packages\System.Globalization\ref\netstandard1.3\System.Globalization.dll + False + True + + + + + + + + + ..\..\packages\System.Globalization.Calendars\ref\net46\System.Globalization.Calendars.dll + False + True + + + + + + + ..\..\packages\System.Globalization.Calendars\ref\netstandard1.3\System.Globalization.Calendars.dll + False + True + + + + + + + + + ..\..\packages\System.Globalization.Extensions\ref\net46\System.Globalization.Extensions.dll + False + True + + + + + + + ..\..\packages\System.Globalization.Extensions\ref\netstandard1.3\System.Globalization.Extensions.dll + False + True + + + + + + + + + ..\..\packages\System.IO\ref\net462\System.IO.dll + False + True + + + + + + + ..\..\packages\System.IO\ref\netstandard1.0\System.IO.dll + False + True + + + + + + + ..\..\packages\System.IO\ref\netstandard1.3\System.IO.dll + False + True + + + + + + + ..\..\packages\System.IO\ref\netstandard1.5\System.IO.dll + False + True + + + + + + + + + True + + + + + + + ..\..\packages\System.IO.Compression\ref\net46\System.IO.Compression.dll + False + True + + + + + + + ..\..\packages\System.IO.Compression\ref\netstandard1.1\System.IO.Compression.dll + False + True + + + + + + + ..\..\packages\System.IO.Compression\ref\netstandard1.3\System.IO.Compression.dll + False + True + + + + + + + + + ..\..\packages\System.IO.Compression.ZipFile\ref\net46\System.IO.Compression.ZipFile.dll + False + True + + + True + + + + + + + ..\..\packages\System.IO.Compression.ZipFile\ref\netstandard1.3\System.IO.Compression.ZipFile.dll + False + True + + + + + + + + + ..\..\packages\System.IO.FileSystem\ref\net46\System.IO.FileSystem.dll + False + True + + + + + + + ..\..\packages\System.IO.FileSystem\ref\netstandard1.3\System.IO.FileSystem.dll + False + True + + + + + + + + + ..\..\packages\System.IO.FileSystem.Primitives\ref\net46\System.IO.FileSystem.Primitives.dll + False + True + + + + + + + ..\..\packages\System.IO.FileSystem.Primitives\ref\netstandard1.3\System.IO.FileSystem.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Linq\ref\net463\System.Linq.dll + False + True + + + + + + + ..\..\packages\System.Linq\ref\netstandard1.0\System.Linq.dll + False + True + + + + + + + ..\..\packages\System.Linq\ref\netstandard1.6\System.Linq.dll + False + True + + + + + + + + + ..\..\packages\System.Linq.Expressions\ref\net463\System.Linq.Expressions.dll + False + True + + + + + + + ..\..\packages\System.Linq.Expressions\ref\netstandard1.0\System.Linq.Expressions.dll + False + True + + + + + + + ..\..\packages\System.Linq.Expressions\ref\netstandard1.3\System.Linq.Expressions.dll + False + True + + + + + + + ..\..\packages\System.Linq.Expressions\ref\netstandard1.6\System.Linq.Expressions.dll + False + True + + + + + + + + + True + + + + + + + ..\..\packages\System.Net.Http\ref\net46\System.Net.Http.dll + False + True + + + + + + + ..\..\packages\System.Net.Http\ref\netstandard1.1\System.Net.Http.dll + False + True + + + + + + + ..\..\packages\System.Net.Http\ref\netstandard1.3\System.Net.Http.dll + False + True + + + + + + + + + ..\..\packages\System.Net.Primitives\ref\netstandard1.1\System.Net.Primitives.dll + False + True + + + + + + + ..\..\packages\System.Net.Primitives\ref\netstandard1.3\System.Net.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Net.Sockets\ref\net46\System.Net.Sockets.dll + False + True + + + + + + + ..\..\packages\System.Net.Sockets\ref\netstandard1.3\System.Net.Sockets.dll + False + True + + + + + + + + + ..\..\packages\System.ObjectModel\ref\netstandard1.0\System.ObjectModel.dll + False + True + + + + + + + ..\..\packages\System.ObjectModel\ref\netstandard1.3\System.ObjectModel.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection\ref\net462\System.Reflection.dll + False + True + + + + + + + ..\..\packages\System.Reflection\ref\netstandard1.0\System.Reflection.dll + False + True + + + + + + + ..\..\packages\System.Reflection\ref\netstandard1.3\System.Reflection.dll + False + True + + + + + + + ..\..\packages\System.Reflection\ref\netstandard1.5\System.Reflection.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Emit\ref\netstandard1.1\System.Reflection.Emit.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Emit.ILGeneration\ref\netstandard1.0\System.Reflection.Emit.ILGeneration.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Emit.Lightweight\ref\netstandard1.0\System.Reflection.Emit.Lightweight.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Extensions\ref\netstandard1.0\System.Reflection.Extensions.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.Primitives\ref\netstandard1.0\System.Reflection.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Reflection.TypeExtensions\ref\net46\System.Reflection.TypeExtensions.dll + False + True + + + + + + + ..\..\packages\System.Reflection.TypeExtensions\ref\net462\System.Reflection.TypeExtensions.dll + False + True + + + + + + + ..\..\packages\System.Reflection.TypeExtensions\ref\netstandard1.5\System.Reflection.TypeExtensions.dll + False + True + + + + + + + + + ..\..\packages\System.Resources.ResourceManager\ref\netstandard1.0\System.Resources.ResourceManager.dll + False + True + + + + + + + + + True + + + + + + + ..\..\packages\System.Runtime\ref\net462\System.Runtime.dll + False + True + + + True + + + + + + + ..\..\packages\System.Runtime\ref\netstandard1.0\System.Runtime.dll + False + True + + + + + + + ..\..\packages\System.Runtime\ref\netstandard1.2\System.Runtime.dll + False + True + + + + + + + ..\..\packages\System.Runtime\ref\netstandard1.3\System.Runtime.dll + False + True + + + + + + + ..\..\packages\System.Runtime\ref\netstandard1.5\System.Runtime.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.Extensions\ref\net462\System.Runtime.Extensions.dll + False + True + + + + + + + ..\..\packages\System.Runtime.Extensions\ref\netstandard1.0\System.Runtime.Extensions.dll + False + True + + + + + + + ..\..\packages\System.Runtime.Extensions\ref\netstandard1.3\System.Runtime.Extensions.dll + False + True + + + + + + + ..\..\packages\System.Runtime.Extensions\ref\netstandard1.5\System.Runtime.Extensions.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.Handles\ref\netstandard1.3\System.Runtime.Handles.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\net462\System.Runtime.InteropServices.dll + False + True + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\net463\System.Runtime.InteropServices.dll + False + True + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.1\System.Runtime.InteropServices.dll + False + True + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.2\System.Runtime.InteropServices.dll + False + True + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.3\System.Runtime.InteropServices.dll + False + True + + + + + + + ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.5\System.Runtime.InteropServices.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll + False + True + + + + + + + + + ..\..\packages\System.Runtime.Numerics\ref\netstandard1.1\System.Runtime.Numerics.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\net46\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\net461\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\net463\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\netstandard1.3\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\netstandard1.4\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Algorithms\ref\netstandard1.6\System.Security.Cryptography.Algorithms.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Cng\ref\net46\System.Security.Cryptography.Cng.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Cng\ref\net461\System.Security.Cryptography.Cng.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Cng\ref\net463\System.Security.Cryptography.Cng.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Cng\ref\netstandard1.6\System.Security.Cryptography.Cng.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Csp\ref\net46\System.Security.Cryptography.Csp.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Csp\ref\netstandard1.3\System.Security.Cryptography.Csp.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Encoding\ref\net46\System.Security.Cryptography.Encoding.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Encoding\ref\netstandard1.3\System.Security.Cryptography.Encoding.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.OpenSsl\ref\netstandard1.6\System.Security.Cryptography.OpenSsl.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.Primitives\ref\net46\System.Security.Cryptography.Primitives.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.Primitives\ref\netstandard1.3\System.Security.Cryptography.Primitives.dll + False + True + + + + + + + + + ..\..\packages\System.Security.Cryptography.X509Certificates\ref\net46\System.Security.Cryptography.X509Certificates.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.X509Certificates\ref\net461\System.Security.Cryptography.X509Certificates.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.X509Certificates\ref\netstandard1.3\System.Security.Cryptography.X509Certificates.dll + False + True + + + + + + + ..\..\packages\System.Security.Cryptography.X509Certificates\ref\netstandard1.4\System.Security.Cryptography.X509Certificates.dll + False + True + + + + + + + + + ..\..\packages\System.Text.Encoding\ref\netstandard1.0\System.Text.Encoding.dll + False + True + + + + + + + ..\..\packages\System.Text.Encoding\ref\netstandard1.3\System.Text.Encoding.dll + False + True + + + + + + + + + ..\..\packages\System.Text.Encoding.Extensions\ref\netstandard1.0\System.Text.Encoding.Extensions.dll + False + True + + + + + + + ..\..\packages\System.Text.Encoding.Extensions\ref\netstandard1.3\System.Text.Encoding.Extensions.dll + False + True + + + + + + + + + ..\..\packages\System.Text.RegularExpressions\ref\net463\System.Text.RegularExpressions.dll + False + True + + + + + + + ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.0\System.Text.RegularExpressions.dll + False + True + + + + + + + ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.3\System.Text.RegularExpressions.dll + False + True + + + + + + + ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.6\System.Text.RegularExpressions.dll + False + True + + + + + + + + + ..\..\packages\System.Threading\ref\netstandard1.0\System.Threading.dll + False + True + + + + + + + ..\..\packages\System.Threading\ref\netstandard1.3\System.Threading.dll + False + True + + + + + + + + + ..\..\packages\System.Threading.Tasks\ref\netstandard1.0\System.Threading.Tasks.dll + False + True + + + + + + + ..\..\packages\System.Threading.Tasks\ref\netstandard1.3\System.Threading.Tasks.dll + False + True + + + + + + + + + ..\..\packages\System.Threading.Tasks.Extensions\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll + True + True + + + + + + + + + ..\..\packages\System.Threading.Timer\ref\netstandard1.2\System.Threading.Timer.dll + False + True + + + + + + + + + True + + + + + + + ..\..\packages\System.Xml.ReaderWriter\ref\net46\System.Xml.ReaderWriter.dll + False + True + + + True + + + + + + + ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.0\System.Xml.ReaderWriter.dll + False + True + + + + + + + ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.3\System.Xml.ReaderWriter.dll + False + True + + + + + + + + + True + + + + + + + ..\..\packages\System.Xml.XDocument\ref\netstandard1.0\System.Xml.XDocument.dll + False + True + + + + + + + ..\..\packages\System.Xml.XDocument\ref\netstandard1.3\System.Xml.XDocument.dll + False + True + + + + + + + + + ..\..\packages\xunit.abstractions\lib\net35\xunit.abstractions.dll + True + True + + + + + + + ..\..\packages\xunit.abstractions\lib\netstandard1.0\xunit.abstractions.dll + True + True + + + + + + + + + ..\..\packages\xunit.assert\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll + True + True + + + + + + + + + ..\..\packages\xunit.extensibility.core\lib\netstandard1.1\xunit.core.dll + True + True + + + + + + + + + ..\..\packages\xunit.extensibility.execution\lib\net452\xunit.execution.desktop.dll + True + True + + + + + + + ..\..\packages\xunit.extensibility.execution\lib\netstandard1.1\xunit.execution.dotnet.dll + True + True + + + + + + + + + + + + + + True + + + + + + OpenTK + {a37a7e14-0000-0000-0000-000000000000} + True + + + \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs new file mode 100644 index 00000000..3adeb2fa --- /dev/null +++ b/tests/OpenTK.Tests/Vectors.fs @@ -0,0 +1,86 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +[] +module internal Generators = + let private isValidFloat f = not (Single.IsNaN f || Single.IsInfinity f) + + let Vec2 = + Arb.generate + |> Gen.filter isValidFloat + |> Gen.two + |> Gen.map Vector2 + |> Arb.fromGen + + let Vec3 = + Arb.generate + |> Gen.filter isValidFloat + |> Gen.three + |> Gen.map Vector3 + |> Arb.fromGen + + let Vec4 = + Arb.generate + |> Gen.filter isValidFloat + |> Gen.four + |> Gen.map Vector4 + |> Arb.fromGen + +type VectorGen = + static member Vector2() = Generators.Vec2 + static member Vector3() = Generators.Vec3 + static member Vector4() = Generators.Vec4 + +[ |])>] +module ``Vector2 tests`` = + // + [] + let ``Vector equality is by component`` (a : Vector2,b : Vector2) = + // + Assert.Equal((a.X = b.X && a.Y = b.Y),(a = b)) + + [] + let ``Vector length is always >= 0`` (a : Vector2) = + // + Assert.True(a.Length >= 0.0f) + + [] + let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = + let c = a + b + Assert.Equal(a.X + b.X,c.X) + Assert.Equal(a.Y + b.Y,c.Y) + + [] + let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = + let c = a + b + let c2 = b + a + Assert.Equal(c,c2) + + [] + let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = + let r1 = (a + b) + c + let r2 = a + (b + c) + Assert.Equal(r1,r2) + + [] + let ``Vector multiplication is the same as component multiplication`` (a : Vector2,b : Vector2) = + let c = a * b + Assert.Equal(a.X * b.X,c.X) + Assert.Equal(a.Y * b.Y,c.Y) + + [] + let ``Vector multiplication is commutative`` (a : Vector2,b : Vector2) = + let r1 = a * b + let r2 = b * a + Assert.Equal(r1,r2) + + [] + let ``Vector-float multiplication is the same as component-float multiplication`` (a : Vector2,f : float32) = + let r = a * f + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) diff --git a/tests/OpenTK.Tests/paket.references b/tests/OpenTK.Tests/paket.references new file mode 100644 index 00000000..ecbc089e --- /dev/null +++ b/tests/OpenTK.Tests/paket.references @@ -0,0 +1,2 @@ +FsCheck.Xunit +xunit.assert From fee1cfe21bd2647a69fb42fccfd7df37b2a604b6 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 13:39:01 +0200 Subject: [PATCH 03/66] Improve vector test organization --- tests/OpenTK.Tests/Vectors.fs | 110 +++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs index 3adeb2fa..90ba1b1c 100644 --- a/tests/OpenTK.Tests/Vectors.fs +++ b/tests/OpenTK.Tests/Vectors.fs @@ -36,51 +36,77 @@ type VectorGen = static member Vector3() = Generators.Vec3 static member Vector4() = Generators.Vec4 -[ |])>] -module ``Vector2 tests`` = - // - [] - let ``Vector equality is by component`` (a : Vector2,b : Vector2) = +module Vector2 = + [ |])>] + module ``Simple Properties`` = // - Assert.Equal((a.X = b.X && a.Y = b.Y),(a = b)) + [] + let ``Vector equality is by component`` (a : Vector2,b : Vector2) = + // + Assert.Equal((a.X = b.X && a.Y = b.Y),(a = b)) + + [] + let ``Vector length is always >= 0`` (a : Vector2) = + // + Assert.True(a.Length >= 0.0f) - [] - let ``Vector length is always >= 0`` (a : Vector2) = + [ |])>] + module Addition = // - Assert.True(a.Length >= 0.0f) + [] + let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = + let c = a + b + Assert.Equal(a.X + b.X,c.X) + Assert.Equal(a.Y + b.Y,c.Y) + + [] + let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = + let c = a + b + let c2 = b + a + Assert.Equal(c,c2) + + [] + let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = + let r1 = (a + b) + c + let r2 = a + (b + c) + Assert.Equal(r1,r2) - [] - let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = - let c = a + b - Assert.Equal(a.X + b.X,c.X) - Assert.Equal(a.Y + b.Y,c.Y) + [ |])>] + module Multiplication = + // + [] + let ``Vector multiplication is the same as component multiplication`` (a : Vector2,b : Vector2) = + let c = a * b + Assert.Equal(a.X * b.X,c.X) + Assert.Equal(a.Y * b.Y,c.Y) + + [] + let ``Vector multiplication is commutative`` (a : Vector2,b : Vector2) = + let r1 = a * b + let r2 = b * a + Assert.Equal(r1,r2) + + [] + let ``Vector-float multiplication is the same as component-float multiplication`` (a : Vector2,f : float32) = + let r = a * f + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) - [] - let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = - let c = a + b - let c2 = b + a - Assert.Equal(c,c2) + [ |])>] + module Subtraction = + // + [] + let ``Vector subtraction is the same as component subtraction`` (a : Vector2,b : Vector2) = + let c = a - b + Assert.Equal(a.X - b.X,c.X) + Assert.Equal(a.Y - b.Y,c.Y) - [] - let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = - let r1 = (a + b) + c - let r2 = a + (b + c) - Assert.Equal(r1,r2) - - [] - let ``Vector multiplication is the same as component multiplication`` (a : Vector2,b : Vector2) = - let c = a * b - Assert.Equal(a.X * b.X,c.X) - Assert.Equal(a.Y * b.Y,c.Y) - - [] - let ``Vector multiplication is commutative`` (a : Vector2,b : Vector2) = - let r1 = a * b - let r2 = b * a - Assert.Equal(r1,r2) - - [] - let ``Vector-float multiplication is the same as component-float multiplication`` (a : Vector2,f : float32) = - let r = a * f - Assert.Equal(a.X * f,r.X) - Assert.Equal(a.Y * f,r.Y) + [ |])>] + module Division = + // + [] + let ``Vector-float division is the same as component-float division`` (a : Vector2,f : float32) = + if f <> 0.0f then + let r = a / f + Assert.Equal(a.X / f,r.X) + Assert.Equal(a.Y / f,r.Y) From 38efb29af0ebbb52a384298e47423481b7f16f36 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 15:33:58 +0200 Subject: [PATCH 04/66] Addint based floating point approximate comparison --- src/OpenTK/Math/MathHelper.cs | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Math/MathHelper.cs b/src/OpenTK/Math/MathHelper.cs index 81ad33b5..a5ecc61c 100644 --- a/src/OpenTK/Math/MathHelper.cs +++ b/src/OpenTK/Math/MathHelper.cs @@ -326,8 +326,35 @@ namespace OpenTK return Math.Max(Math.Min(n, max), min); } - #endregion + private static unsafe int FloatToInt32Bits(float f) { + return *((int*) &f); + } - #endregion - } + /// + /// Approximates floating point equality with a maximum number of different bits. + /// This is typically used in place of an epsilon comparison. + /// see: https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + /// see: https://stackoverflow.com/questions/3874627/floating-point-comparison-functions-for-c-sharp + /// + /// the first value to compare + /// >the second value to compare + /// the number of floating point bits to check + /// + public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits) { + int aInt = FloatToInt32Bits(a); + if (aInt < 0) + aInt = Int32.MinValue - aInt; + + int bInt = FloatToInt32Bits(b); + if (bInt < 0) + bInt = Int32.MinValue - bInt; + + int intDiff = Math.Abs(aInt - bInt); + return intDiff <= (1 << maxDeltaBits); + } + + #endregion + + #endregion + } } From 79ec4c89a314a00417ab441b143e5e8097d49e99 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 15:35:46 +0200 Subject: [PATCH 05/66] Enhance testing; add more generators; add testing for approxEqual --- tests/OpenTK.Tests/Assertions.fs | 31 +++++++++++ tests/OpenTK.Tests/Generators.fs | 76 ++++++++++++++++++++++++++ tests/OpenTK.Tests/MathHelper.fs | 55 +++++++++++++++++++ tests/OpenTK.Tests/OpenTK.Tests.fsproj | 3 + tests/OpenTK.Tests/Vectors.fs | 55 ++++--------------- 5 files changed, 177 insertions(+), 43 deletions(-) create mode 100644 tests/OpenTK.Tests/Assertions.fs create mode 100644 tests/OpenTK.Tests/Generators.fs create mode 100644 tests/OpenTK.Tests/MathHelper.fs diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs new file mode 100644 index 00000000..93baa61a --- /dev/null +++ b/tests/OpenTK.Tests/Assertions.fs @@ -0,0 +1,31 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +[] +module private AssertHelpers = + [] + let private BitAccuracy = 4 + + let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) + +/// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal. +[] +type internal Assert = + + static member ApproximatelyEqual(a : Vector2,b : Vector2) = + if not <| approxEq a.X b.X && approxEq a.Y b.Y then raise <| new Xunit.Sdk.EqualException(a,b) + + static member ApproximatelyEqual(a : Vector3,b : Vector3) = + if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z then raise <| new Xunit.Sdk.EqualException(a,b) + + static member ApproximatelyEqual(a : Vector4,b : Vector4) = + if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z && approxEq a.W b.W then + raise <| new Xunit.Sdk.EqualException(a,b) + + static member ApproximatelyEqual(a : float32,b : float32) = + if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs new file mode 100644 index 00000000..a57424f8 --- /dev/null +++ b/tests/OpenTK.Tests/Generators.fs @@ -0,0 +1,76 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +[] +module private Generators = + let private isValidFloat f = not (Single.IsNaN f || Single.IsInfinity f || Single.IsInfinity (f * f) || f = Single.MinValue || f = Single.MaxValue ) + let private isValidDouble d = not (Double.IsNaN d || Double.IsInfinity d || Double.IsInfinity (d * d)|| d = Double.MinValue || d = Double.MaxValue) + let singleArb = Arb.Default.Float32() |> Arb.toGen |> Gen.filter isValidFloat + let single = singleArb |> Arb.fromGen + + let double = + Arb.Default.Float() |> Arb.toGen + |> Gen.filter isValidDouble + |> Arb.fromGen + + let vec2 = + singleArb + |> Gen.two + |> Gen.map Vector2 + |> Arb.fromGen + + let vec3 = + singleArb + |> Gen.three + |> Gen.map Vector3 + |> Arb.fromGen + + let vec4 = + singleArb + |> Gen.four + |> Gen.map Vector4 + |> Arb.fromGen + + let quat = + singleArb + |> Gen.four + |> Gen.map Quaternion + |> Arb.fromGen + + let mat2 = + singleArb + |> Gen.four + |> Gen.map Matrix2 + |> Arb.fromGen + + let mat3 = + vec3 + |> Arb.toGen + |> Gen.three + |> Gen.map Matrix3 + |> Arb.fromGen + + let mat4 = + vec4 + |> Arb.toGen + |> Gen.four + |> Gen.map Matrix4 + |> Arb.fromGen + +type OpenTKGen = + static member Single() = single + static member float32() = single + static member Double() = double + static member float() = double + static member Vector2() = vec2 + static member Vector3() = vec3 + static member Vector4() = vec4 + static member Quaternion() = quat + static member Matrix2() = mat2 + static member Matrix3() = mat3 + static member Matrix4() = mat4 diff --git a/tests/OpenTK.Tests/MathHelper.fs b/tests/OpenTK.Tests/MathHelper.fs new file mode 100644 index 00000000..7c37a25f --- /dev/null +++ b/tests/OpenTK.Tests/MathHelper.fs @@ -0,0 +1,55 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +[ |])>] +module MathHelper = + /// This test ensures that approximately equal can never get it 'wrong' about the values. + [] + let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) = + let clamped = max 0 (min bits 24) + let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) + let areExactlyEqual = a = b + let isWrong = areExactlyEqual && not areApproxEqual + Assert.False(isWrong) + + [] + let ``ApproximatelyEqual can return true if some values are not exactly equal`` (a : float32,b : float32,bits : int32) = + let clamped = max 0 (min bits 24) + let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) + let areExactlyEqual = a = b + let isWrong = areExactlyEqual && not areApproxEqual + let p = new PropertyAttribute() + Assert.False(isWrong) + + [] + let ``ApproximatelyEqual correctly approximates equality``() = + let a = 0.000000001f + let b = 0.0000000010000001f + Assert.NotEqual(a,b) + [ 1..24 ] |> List.iter (fun i -> Assert.True(MathHelper.ApproximatelyEqual(a,b,i))) + + [] + let ``ApproximatelyEqual reports very different values as non-equal even with high bit count``() = + let a = 2.0f + let b = 1.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEqual(a,b,10)) + + [] + let ``ApproximatelyEqual works with single zero value``() = + let a = 1.0f + let b = 0.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEqual(a,b,0)) + + [] + let ``ApproximatelyEqual works with both zero values``() = + let a = 0.0f + let b = 0.0f + Assert.Equal(a,b) + Assert.True(MathHelper.ApproximatelyEqual(a,b,0)) diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index 46190f28..c57ae0c8 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -1483,6 +1483,9 @@ + + + diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs index 90ba1b1c..13e6a750 100644 --- a/tests/OpenTK.Tests/Vectors.fs +++ b/tests/OpenTK.Tests/Vectors.fs @@ -6,38 +6,8 @@ open FsCheck.Xunit open System open OpenTK -[] -module internal Generators = - let private isValidFloat f = not (Single.IsNaN f || Single.IsInfinity f) - - let Vec2 = - Arb.generate - |> Gen.filter isValidFloat - |> Gen.two - |> Gen.map Vector2 - |> Arb.fromGen - - let Vec3 = - Arb.generate - |> Gen.filter isValidFloat - |> Gen.three - |> Gen.map Vector3 - |> Arb.fromGen - - let Vec4 = - Arb.generate - |> Gen.filter isValidFloat - |> Gen.four - |> Gen.map Vector4 - |> Arb.fromGen - -type VectorGen = - static member Vector2() = Generators.Vec2 - static member Vector3() = Generators.Vec3 - static member Vector4() = Generators.Vec4 - module Vector2 = - [ |])>] + [ |])>] module ``Simple Properties`` = // [] @@ -50,28 +20,28 @@ module Vector2 = // Assert.True(a.Length >= 0.0f) - [ |])>] + [ |])>] module Addition = // [] let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = let c = a + b - Assert.Equal(a.X + b.X,c.X) - Assert.Equal(a.Y + b.Y,c.Y) + Assert.ApproximatelyEqual(a.X + b.X,c.X) + Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) [] let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = let c = a + b let c2 = b + a - Assert.Equal(c,c2) + Assert.ApproximatelyEqual(c,c2) [] let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = let r1 = (a + b) + c let r2 = a + (b + c) - Assert.Equal(r1,r2) + Assert.ApproximatelyEqual(r1,r2) - [ |])>] + [ |])>] module Multiplication = // [] @@ -92,7 +62,7 @@ module Vector2 = Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - [ |])>] + [ |])>] module Subtraction = // [] @@ -101,12 +71,11 @@ module Vector2 = Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) - [ |])>] + [ |])>] module Division = // [] let ``Vector-float division is the same as component-float division`` (a : Vector2,f : float32) = - if f <> 0.0f then - let r = a / f - Assert.Equal(a.X / f,r.X) - Assert.Equal(a.Y / f,r.Y) + let r = a / f + Assert.ApproximatelyEqual(a.X / f,r.X) + Assert.ApproximatelyEqual(a.Y / f,r.Y) From 3e38074a9f49fae439e9e8ce84d3f5da537d88c7 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 15:56:16 +0200 Subject: [PATCH 06/66] Use longs to avoid two's complement failure in approxEqual --- src/OpenTK/Math/MathHelper.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenTK/Math/MathHelper.cs b/src/OpenTK/Math/MathHelper.cs index a5ecc61c..f1effe6e 100644 --- a/src/OpenTK/Math/MathHelper.cs +++ b/src/OpenTK/Math/MathHelper.cs @@ -341,15 +341,16 @@ namespace OpenTK /// the number of floating point bits to check /// public static bool ApproximatelyEqual(float a, float b, int maxDeltaBits) { - int aInt = FloatToInt32Bits(a); + // we use longs here, otherwise we run into a two's complement problem, causing this to fail with -2 and 2.0 + long aInt = FloatToInt32Bits(a); if (aInt < 0) aInt = Int32.MinValue - aInt; - int bInt = FloatToInt32Bits(b); + long bInt = FloatToInt32Bits(b); if (bInt < 0) bInt = Int32.MinValue - bInt; - int intDiff = Math.Abs(aInt - bInt); + long intDiff = Math.Abs(aInt - bInt); return intDiff <= (1 << maxDeltaBits); } From 68c4260f52b1b968cd407ec77fbca7429cf8b79b Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:17:53 +0200 Subject: [PATCH 07/66] Slightly reduce approxEq bit equality accuracy --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index 93baa61a..eaff950f 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 4 + let private BitAccuracy = 5 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From 3ef546b45656738a024fc06c8601816af7f69a90 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:18:13 +0200 Subject: [PATCH 08/66] Add tests to build script --- build.fsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.fsx b/build.fsx index 012efed9..19144a08 100644 --- a/build.fsx +++ b/build.fsx @@ -86,8 +86,9 @@ let activeProjects = f -- "**/OpenTK.Android.csproj" -- "**/OpenTK.iOS.csproj" - + !! "src/**/*.??proj" + ++ "tests/OpenTK.Tests.fsproj" -- "**/OpenTK.GLWidget.csproj" |> xamarinFilter @@ -194,7 +195,7 @@ Target "All" DoNothing ==> "AssemblyInfo" ==> "Build" ==> "CopyBinaries" -// ==> "RunTests" + ==> "RunTests" ==> "All" "All" From 6e0f55a584a7e2527093b4e5f9ab90b05885d6b0 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:32:37 +0200 Subject: [PATCH 09/66] Add additional Vector2 tests --- tests/OpenTK.Tests/Vectors.fs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs index 13e6a750..7376324f 100644 --- a/tests/OpenTK.Tests/Vectors.fs +++ b/tests/OpenTK.Tests/Vectors.fs @@ -7,6 +7,39 @@ open System open OpenTK module Vector2 = + [ |])>] + module Constructors = + // + [] + let ``Single value constructor sets all components to the same value`` (f : float32) = + let v = Vector2(f) + Assert.Equal(f,v.X) + Assert.Equal(f,v.Y) + + [] + let ``Two value constructor sets all components correctly`` (x,y) = + let v = Vector2(x,y) + Assert.Equal(x,v.X) + Assert.Equal(y,v.Y) + + [] + let ``Index operators work for the correct components`` (x,y) = + let v = Vector2(x,y) + Assert.Equal(v.[0],v.X) + Assert.Equal(v.[1],v.Y) + + [] + let ``Clamping works for each component`` (a : Vector2,b : Vector2,c : Vector2) = + let inline clamp (value : float32) minV maxV = MathHelper.Clamp(value,minV,maxV) + let r = Vector2.Clamp(a,b,c) + Assert.Equal(clamp a.X b.X c.X,r.X) + Assert.Equal(clamp a.X b.X c.X,r.Y) + + [] + let ``Length is always >= 0`` (a : Vector2) = + // + Assert.True(a.Length >= 0.0f) + [ |])>] module ``Simple Properties`` = // From 4e93da0f41a099238cfe1014065e7b9c427cc3f1 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:36:36 +0200 Subject: [PATCH 10/66] fixed and disabled test with possibly broken implementation --- tests/OpenTK.Tests/Vectors.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs index 7376324f..53516529 100644 --- a/tests/OpenTK.Tests/Vectors.fs +++ b/tests/OpenTK.Tests/Vectors.fs @@ -28,12 +28,13 @@ module Vector2 = Assert.Equal(v.[0],v.X) Assert.Equal(v.[1],v.Y) - [] +// [] + // disabled - behaviour needs discussion let ``Clamping works for each component`` (a : Vector2,b : Vector2,c : Vector2) = let inline clamp (value : float32) minV maxV = MathHelper.Clamp(value,minV,maxV) let r = Vector2.Clamp(a,b,c) Assert.Equal(clamp a.X b.X c.X,r.X) - Assert.Equal(clamp a.X b.X c.X,r.Y) + Assert.Equal(clamp a.Y b.Y c.Y,r.Y) [] let ``Length is always >= 0`` (a : Vector2) = From 33dfaa2df7cdb986c8fb76f7c588a7304f36695d Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:43:19 +0200 Subject: [PATCH 11/66] Fix div-by-zero in component division test --- tests/OpenTK.Tests/Vectors.fs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vectors.fs index 53516529..ac70d1c9 100644 --- a/tests/OpenTK.Tests/Vectors.fs +++ b/tests/OpenTK.Tests/Vectors.fs @@ -110,6 +110,7 @@ module Vector2 = // [] let ``Vector-float division is the same as component-float division`` (a : Vector2,f : float32) = - let r = a / f - Assert.ApproximatelyEqual(a.X / f,r.X) - Assert.ApproximatelyEqual(a.Y / f,r.Y) + if not (approxEq f 0.0f) then // we don't support diving by zero. + let r = a / f + Assert.ApproximatelyEqual(a.X / f,r.X) + Assert.ApproximatelyEqual(a.Y / f,r.Y) From de71367b4b48af67edf89a91ec12c8ec92847724 Mon Sep 17 00:00:00 2001 From: varon Date: Sun, 19 Mar 2017 16:43:28 +0200 Subject: [PATCH 12/66] Fix test assembly path --- build.fsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index 19144a08..d6bec54e 100644 --- a/build.fsx +++ b/build.fsx @@ -88,7 +88,7 @@ let activeProjects = -- "**/OpenTK.iOS.csproj" !! "src/**/*.??proj" - ++ "tests/OpenTK.Tests.fsproj" + ++ "tests/**/OpenTK.Tests.fsproj" -- "**/OpenTK.GLWidget.csproj" |> xamarinFilter From 4ee0700babf6c4f2be84743f5c1382428da7d193 Mon Sep 17 00:00:00 2001 From: varon Date: Wed, 31 May 2017 14:13:17 +0200 Subject: [PATCH 13/66] Update project deps --- src/Generator.Bind/Properties/AssemblyInfo.cs | 9 +- .../Properties/AssemblyInfo.cs | 9 +- .../Properties/AssemblyInfo.cs | 9 +- .../Properties/AssemblyInfo.cs | 9 +- src/OpenTK.GLWidget/OpenTK.GLWidget.csproj | 4 +- .../Properties/AssemblyInfo.cs | 9 +- src/OpenTK/Properties/AssemblyInfo.cs | 9 +- tests/OpenTK.Tests/OpenTK.Tests.fsproj | 764 ++++++++++-------- 8 files changed, 466 insertions(+), 356 deletions(-) diff --git a/src/Generator.Bind/Properties/AssemblyInfo.cs b/src/Generator.Bind/Properties/AssemblyInfo.cs index 9767ed4e..16ced826 100644 --- a/src/Generator.Bind/Properties/AssemblyInfo.cs +++ b/src/Generator.Bind/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "Generator.Bind"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/src/Generator.Converter/Properties/AssemblyInfo.cs b/src/Generator.Converter/Properties/AssemblyInfo.cs index 1adfda08..462df852 100644 --- a/src/Generator.Converter/Properties/AssemblyInfo.cs +++ b/src/Generator.Converter/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "Generator.Convert"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/src/Generator.Rewrite/Properties/AssemblyInfo.cs b/src/Generator.Rewrite/Properties/AssemblyInfo.cs index 63a68040..438811f0 100644 --- a/src/Generator.Rewrite/Properties/AssemblyInfo.cs +++ b/src/Generator.Rewrite/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "Generator.Rewrite"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/src/OpenTK.GLControl/Properties/AssemblyInfo.cs b/src/OpenTK.GLControl/Properties/AssemblyInfo.cs index eeeb1acb..a2f2b85c 100644 --- a/src/OpenTK.GLControl/Properties/AssemblyInfo.cs +++ b/src/OpenTK.GLControl/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "OpenTK.GLControl"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj index e71c63a7..91e089ba 100644 --- a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj +++ b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj @@ -113,7 +113,7 @@ - + <__paket__GtkSharp_targets>net45\GtkSharp @@ -126,7 +126,7 @@ - + ..\..\packages\GtkSharp\lib\net45\cairo-sharp.dll diff --git a/src/OpenTK.GLWidget/Properties/AssemblyInfo.cs b/src/OpenTK.GLWidget/Properties/AssemblyInfo.cs index 15d61fa4..0db3d7c1 100644 --- a/src/OpenTK.GLWidget/Properties/AssemblyInfo.cs +++ b/src/OpenTK.GLWidget/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "OpenTK.GLWidget"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/src/OpenTK/Properties/AssemblyInfo.cs b/src/OpenTK/Properties/AssemblyInfo.cs index e6e2009c..f0d6b897 100644 --- a/src/OpenTK/Properties/AssemblyInfo.cs +++ b/src/OpenTK/Properties/AssemblyInfo.cs @@ -11,7 +11,12 @@ using System.Reflection; [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "3.0.0"; - internal const string InformationalVersion = "3.0.0"; + internal const System.String AssemblyTitle = "OpenTK"; + internal const System.String AssemblyProduct = "OpenTK"; + internal const System.String AssemblyDescription = "A set of fast, low-level C# bindings for OpenGL, OpenGL ES and OpenAL."; + internal const System.String AssemblyVersion = "3.0.0"; + internal const System.String AssemblyFileVersion = "3.0.0"; + internal const System.Boolean CLSCompliant = true; + internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; } } diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index c57ae0c8..c4b2094a 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -56,8 +56,28 @@ --> + + + + + + + + + + + + + + + + OpenTK + {a37a7e14-0000-0000-0000-000000000000} + True + + - + ..\..\packages\FsCheck\lib\net452\FsCheck.dll @@ -66,7 +86,16 @@ - + + + + ..\..\packages\FsCheck\lib\netstandard1.6\FsCheck.dll + True + True + + + + ..\..\packages\FsCheck\lib\portable-net45+netcore45\FsCheck.dll @@ -95,7 +124,7 @@ - + ..\..\packages\FsCheck.Xunit\lib\net452\FsCheck.Xunit.dll @@ -104,18 +133,83 @@ - - - + - - ..\..\packages\Microsoft.Win32.Primitives\ref\net46\Microsoft.Win32.Primitives.dll - False + + ..\..\packages\FsCheck.Xunit\lib\netstandard1.6\FsCheck.Xunit.dll + True True - + + + + + + ..\..\packages\FSharp.Core\lib\net20\FSharp.Core.dll + True + True + + + + + + + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll + True + True + + + + + + + ..\..\packages\FSharp.Core\lib\net45\FSharp.Core.dll + True + True + + + + + + + ..\..\packages\FSharp.Core\lib\netstandard1.6\FSharp.Core.dll + True + True + + + + + + + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45\FSharp.Core.dll + True + True + + + + + + + ..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wp8\FSharp.Core.dll + True + True + + + + + + + + + ..\..\packages\Microsoft.Win32.Primitives\lib\net46\Microsoft.Win32.Primitives.dll + True + True + + + + ..\..\packages\Microsoft.Win32.Primitives\ref\netstandard1.3\Microsoft.Win32.Primitives.dll @@ -129,17 +223,17 @@ - ..\..\packages\System.AppContext\ref\net46\System.AppContext.dll - False + ..\..\packages\System.AppContext\lib\net46\System.AppContext.dll + True True - + - ..\..\packages\System.AppContext\ref\net463\System.AppContext.dll - False + ..\..\packages\System.AppContext\lib\net463\System.AppContext.dll + True True @@ -153,9 +247,18 @@ + + + + ..\..\packages\System.AppContext\lib\netstandard1.6\System.AppContext.dll + True + True + + + - + ..\..\packages\System.Buffers\lib\netstandard1.1\System.Buffers.dll @@ -175,7 +278,7 @@ - + ..\..\packages\System.Collections\ref\netstandard1.3\System.Collections.dll @@ -186,36 +289,27 @@ - + - ..\..\packages\System.Collections.Concurrent\ref\netstandard1.1\System.Collections.Concurrent.dll - False - True - - - - - - - ..\..\packages\System.Collections.Concurrent\ref\netstandard1.3\System.Collections.Concurrent.dll - False + ..\..\packages\System.Collections.Concurrent\lib\netstandard1.3\System.Collections.Concurrent.dll + True True - + - ..\..\packages\System.Console\ref\net46\System.Console.dll - False + ..\..\packages\System.Console\lib\net46\System.Console.dll + True True - + ..\..\packages\System.Console\ref\netstandard1.3\System.Console.dll @@ -235,7 +329,7 @@ - + ..\..\packages\System.Diagnostics.Debug\ref\netstandard1.3\System.Diagnostics.Debug.dll @@ -246,7 +340,7 @@ - + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\net46\System.Diagnostics.DiagnosticSource.dll @@ -255,7 +349,7 @@ - + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\netstandard1.1\System.Diagnostics.DiagnosticSource.dll @@ -264,7 +358,7 @@ - + ..\..\packages\System.Diagnostics.DiagnosticSource\lib\netstandard1.3\System.Diagnostics.DiagnosticSource.dll @@ -275,22 +369,11 @@ - - - - ..\..\packages\System.Diagnostics.Tools\ref\netstandard1.0\System.Diagnostics.Tools.dll - False - True - - - - - - + - ..\..\packages\System.Diagnostics.Tracing\ref\net462\System.Diagnostics.Tracing.dll - False + ..\..\packages\System.Diagnostics.Tracing\lib\net462\System.Diagnostics.Tracing.dll + True True @@ -322,7 +405,7 @@ - + ..\..\packages\System.Diagnostics.Tracing\ref\netstandard1.5\System.Diagnostics.Tracing.dll @@ -342,7 +425,7 @@ - + ..\..\packages\System.Globalization\ref\netstandard1.3\System.Globalization.dll @@ -353,16 +436,16 @@ - + - ..\..\packages\System.Globalization.Calendars\ref\net46\System.Globalization.Calendars.dll - False + ..\..\packages\System.Globalization.Calendars\lib\net46\System.Globalization.Calendars.dll + True True - + ..\..\packages\System.Globalization.Calendars\ref\netstandard1.3\System.Globalization.Calendars.dll @@ -373,16 +456,16 @@ - + - ..\..\packages\System.Globalization.Extensions\ref\net46\System.Globalization.Extensions.dll - False + ..\..\packages\System.Globalization.Extensions\lib\net46\System.Globalization.Extensions.dll + True True - + ..\..\packages\System.Globalization.Extensions\ref\netstandard1.3\System.Globalization.Extensions.dll @@ -393,11 +476,11 @@ - + - ..\..\packages\System.IO\ref\net462\System.IO.dll - False + ..\..\packages\System.IO\lib\net462\System.IO.dll + True True @@ -420,7 +503,7 @@ - + ..\..\packages\System.IO\ref\netstandard1.5\System.IO.dll @@ -431,18 +514,18 @@ - + True - + - ..\..\packages\System.IO.Compression\ref\net46\System.IO.Compression.dll - False + ..\..\packages\System.IO.Compression\lib\net46\System.IO.Compression.dll + True True @@ -456,7 +539,7 @@ - + ..\..\packages\System.IO.Compression\ref\netstandard1.3\System.IO.Compression.dll @@ -467,39 +550,39 @@ - + - - ..\..\packages\System.IO.Compression.ZipFile\ref\net46\System.IO.Compression.ZipFile.dll - False + True - + + ..\..\packages\System.IO.Compression.ZipFile\lib\net46\System.IO.Compression.ZipFile.dll + True True - + - ..\..\packages\System.IO.Compression.ZipFile\ref\netstandard1.3\System.IO.Compression.ZipFile.dll - False + ..\..\packages\System.IO.Compression.ZipFile\lib\netstandard1.3\System.IO.Compression.ZipFile.dll + True True - + - ..\..\packages\System.IO.FileSystem\ref\net46\System.IO.FileSystem.dll - False + ..\..\packages\System.IO.FileSystem\lib\net46\System.IO.FileSystem.dll + True True - + ..\..\packages\System.IO.FileSystem\ref\netstandard1.3\System.IO.FileSystem.dll @@ -510,60 +593,51 @@ - + - ..\..\packages\System.IO.FileSystem.Primitives\ref\net46\System.IO.FileSystem.Primitives.dll - False + ..\..\packages\System.IO.FileSystem.Primitives\lib\net46\System.IO.FileSystem.Primitives.dll + True True - + - ..\..\packages\System.IO.FileSystem.Primitives\ref\netstandard1.3\System.IO.FileSystem.Primitives.dll - False + ..\..\packages\System.IO.FileSystem.Primitives\lib\netstandard1.3\System.IO.FileSystem.Primitives.dll + True True - + - ..\..\packages\System.Linq\ref\net463\System.Linq.dll - False + ..\..\packages\System.Linq\lib\net463\System.Linq.dll + True True - + - ..\..\packages\System.Linq\ref\netstandard1.0\System.Linq.dll - False - True - - - - - - - ..\..\packages\System.Linq\ref\netstandard1.6\System.Linq.dll - False + ..\..\packages\System.Linq\lib\netstandard1.6\System.Linq.dll + True True - + - ..\..\packages\System.Linq.Expressions\ref\net463\System.Linq.Expressions.dll - False + ..\..\packages\System.Linq.Expressions\lib\net463\System.Linq.Expressions.dll + True True @@ -586,29 +660,40 @@ - + - ..\..\packages\System.Linq.Expressions\ref\netstandard1.6\System.Linq.Expressions.dll - False + ..\..\packages\System.Linq.Expressions\lib\netstandard1.6\System.Linq.Expressions.dll + True True - + + + + ..\..\packages\System.Linq.Queryable\lib\netstandard1.3\System.Linq.Queryable.dll + True + True + + + + + + True - + - ..\..\packages\System.Net.Http\ref\net46\System.Net.Http.dll - False + ..\..\packages\System.Net.Http\lib\net46\System.Net.Http.dll + True True @@ -622,7 +707,7 @@ - + ..\..\packages\System.Net.Http\ref\netstandard1.3\System.Net.Http.dll @@ -642,7 +727,7 @@ - + ..\..\packages\System.Net.Primitives\ref\netstandard1.3\System.Net.Primitives.dll @@ -653,16 +738,16 @@ - + - ..\..\packages\System.Net.Sockets\ref\net46\System.Net.Sockets.dll - False + ..\..\packages\System.Net.Sockets\lib\net46\System.Net.Sockets.dll + True True - + ..\..\packages\System.Net.Sockets\ref\netstandard1.3\System.Net.Sockets.dll @@ -673,31 +758,33 @@ - + - - ..\..\packages\System.ObjectModel\ref\netstandard1.0\System.ObjectModel.dll - False - True - - - - - - - ..\..\packages\System.ObjectModel\ref\netstandard1.3\System.ObjectModel.dll - False + + ..\..\packages\System.Net.WebHeaderCollection\lib\netstandard1.3\System.Net.WebHeaderCollection.dll + True True - + + + + ..\..\packages\System.ObjectModel\lib\netstandard1.3\System.ObjectModel.dll + True + True + + + + + + - ..\..\packages\System.Reflection\ref\net462\System.Reflection.dll - False + ..\..\packages\System.Reflection\lib\net462\System.Reflection.dll + True True @@ -720,7 +807,7 @@ - + ..\..\packages\System.Reflection\ref\netstandard1.5\System.Reflection.dll @@ -731,55 +818,33 @@ - + - ..\..\packages\System.Reflection.Emit\ref\netstandard1.1\System.Reflection.Emit.dll - False + ..\..\packages\System.Reflection.Emit\lib\netstandard1.3\System.Reflection.Emit.dll + True True - + - ..\..\packages\System.Reflection.Emit.ILGeneration\ref\netstandard1.0\System.Reflection.Emit.ILGeneration.dll - False + ..\..\packages\System.Reflection.Emit.ILGeneration\lib\netstandard1.3\System.Reflection.Emit.ILGeneration.dll + True True - + - ..\..\packages\System.Reflection.Emit.Lightweight\ref\netstandard1.0\System.Reflection.Emit.Lightweight.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Extensions\ref\netstandard1.0\System.Reflection.Extensions.dll - False - True - - - - - - - - - ..\..\packages\System.Reflection.Primitives\ref\netstandard1.0\System.Reflection.Primitives.dll - False + ..\..\packages\System.Reflection.Emit.Lightweight\lib\netstandard1.3\System.Reflection.Emit.Lightweight.dll + True True @@ -789,58 +854,47 @@ - ..\..\packages\System.Reflection.TypeExtensions\ref\net46\System.Reflection.TypeExtensions.dll - False + ..\..\packages\System.Reflection.TypeExtensions\lib\net46\System.Reflection.TypeExtensions.dll + True True - + - ..\..\packages\System.Reflection.TypeExtensions\ref\net462\System.Reflection.TypeExtensions.dll - False + ..\..\packages\System.Reflection.TypeExtensions\lib\net462\System.Reflection.TypeExtensions.dll + True True - + - ..\..\packages\System.Reflection.TypeExtensions\ref\netstandard1.5\System.Reflection.TypeExtensions.dll - False + ..\..\packages\System.Reflection.TypeExtensions\lib\netstandard1.5\System.Reflection.TypeExtensions.dll + True True - - - - ..\..\packages\System.Resources.ResourceManager\ref\netstandard1.0\System.Resources.ResourceManager.dll - False - True - - - - - - + True - + + + True + - ..\..\packages\System.Runtime\ref\net462\System.Runtime.dll - False - True - - + ..\..\packages\System.Runtime\lib\net462\System.Runtime.dll + True True @@ -872,7 +926,7 @@ - + ..\..\packages\System.Runtime\ref\netstandard1.5\System.Runtime.dll @@ -883,11 +937,11 @@ - + - ..\..\packages\System.Runtime.Extensions\ref\net462\System.Runtime.Extensions.dll - False + ..\..\packages\System.Runtime.Extensions\lib\net462\System.Runtime.Extensions.dll + True True @@ -910,7 +964,7 @@ - + ..\..\packages\System.Runtime.Extensions\ref\netstandard1.5\System.Runtime.Extensions.dll @@ -921,7 +975,7 @@ - + ..\..\packages\System.Runtime.Handles\ref\netstandard1.3\System.Runtime.Handles.dll @@ -935,17 +989,17 @@ - ..\..\packages\System.Runtime.InteropServices\ref\net462\System.Runtime.InteropServices.dll - False + ..\..\packages\System.Runtime.InteropServices\lib\net462\System.Runtime.InteropServices.dll + True True - + - ..\..\packages\System.Runtime.InteropServices\ref\net463\System.Runtime.InteropServices.dll - False + ..\..\packages\System.Runtime.InteropServices\lib\net463\System.Runtime.InteropServices.dll + True True @@ -977,7 +1031,7 @@ - + ..\..\packages\System.Runtime.InteropServices\ref\netstandard1.5\System.Runtime.InteropServices.dll @@ -988,7 +1042,25 @@ - + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\lib\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll @@ -997,9 +1069,18 @@ + + + + ..\..\packages\System.Runtime.InteropServices.RuntimeInformation\lib\wpa81\System.Runtime.InteropServices.RuntimeInformation.dll + True + True + + + - + ..\..\packages\System.Runtime.Numerics\ref\netstandard1.1\System.Runtime.Numerics.dll @@ -1008,13 +1089,22 @@ + + + + ..\..\packages\System.Runtime.Numerics\lib\netstandard1.3\System.Runtime.Numerics.dll + True + True + + + - ..\..\packages\System.Security.Cryptography.Algorithms\ref\net46\System.Security.Cryptography.Algorithms.dll - False + ..\..\packages\System.Security.Cryptography.Algorithms\lib\net46\System.Security.Cryptography.Algorithms.dll + True True @@ -1022,17 +1112,17 @@ - ..\..\packages\System.Security.Cryptography.Algorithms\ref\net461\System.Security.Cryptography.Algorithms.dll - False + ..\..\packages\System.Security.Cryptography.Algorithms\lib\net461\System.Security.Cryptography.Algorithms.dll + True True - + - ..\..\packages\System.Security.Cryptography.Algorithms\ref\net463\System.Security.Cryptography.Algorithms.dll - False + ..\..\packages\System.Security.Cryptography.Algorithms\lib\net463\System.Security.Cryptography.Algorithms.dll + True True @@ -1055,7 +1145,7 @@ - + ..\..\packages\System.Security.Cryptography.Algorithms\ref\netstandard1.6\System.Security.Cryptography.Algorithms.dll @@ -1069,8 +1159,8 @@ - ..\..\packages\System.Security.Cryptography.Cng\ref\net46\System.Security.Cryptography.Cng.dll - False + ..\..\packages\System.Security.Cryptography.Cng\lib\net46\System.Security.Cryptography.Cng.dll + True True @@ -1078,22 +1168,22 @@ - ..\..\packages\System.Security.Cryptography.Cng\ref\net461\System.Security.Cryptography.Cng.dll - False + ..\..\packages\System.Security.Cryptography.Cng\lib\net461\System.Security.Cryptography.Cng.dll + True True - + - ..\..\packages\System.Security.Cryptography.Cng\ref\net463\System.Security.Cryptography.Cng.dll - False + ..\..\packages\System.Security.Cryptography.Cng\lib\net463\System.Security.Cryptography.Cng.dll + True True - + ..\..\packages\System.Security.Cryptography.Cng\ref\netstandard1.6\System.Security.Cryptography.Cng.dll @@ -1104,16 +1194,16 @@ - + - ..\..\packages\System.Security.Cryptography.Csp\ref\net46\System.Security.Cryptography.Csp.dll - False + ..\..\packages\System.Security.Cryptography.Csp\lib\net46\System.Security.Cryptography.Csp.dll + True True - + ..\..\packages\System.Security.Cryptography.Csp\ref\netstandard1.3\System.Security.Cryptography.Csp.dll @@ -1124,16 +1214,16 @@ - + - ..\..\packages\System.Security.Cryptography.Encoding\ref\net46\System.Security.Cryptography.Encoding.dll - False + ..\..\packages\System.Security.Cryptography.Encoding\lib\net46\System.Security.Cryptography.Encoding.dll + True True - + ..\..\packages\System.Security.Cryptography.Encoding\ref\netstandard1.3\System.Security.Cryptography.Encoding.dll @@ -1144,31 +1234,31 @@ - + - ..\..\packages\System.Security.Cryptography.OpenSsl\ref\netstandard1.6\System.Security.Cryptography.OpenSsl.dll - False + ..\..\packages\System.Security.Cryptography.OpenSsl\lib\netstandard1.6\System.Security.Cryptography.OpenSsl.dll + True True - + - ..\..\packages\System.Security.Cryptography.Primitives\ref\net46\System.Security.Cryptography.Primitives.dll - False + ..\..\packages\System.Security.Cryptography.Primitives\lib\net46\System.Security.Cryptography.Primitives.dll + True True - + - ..\..\packages\System.Security.Cryptography.Primitives\ref\netstandard1.3\System.Security.Cryptography.Primitives.dll - False + ..\..\packages\System.Security.Cryptography.Primitives\lib\netstandard1.3\System.Security.Cryptography.Primitives.dll + True True @@ -1178,17 +1268,17 @@ - ..\..\packages\System.Security.Cryptography.X509Certificates\ref\net46\System.Security.Cryptography.X509Certificates.dll - False + ..\..\packages\System.Security.Cryptography.X509Certificates\lib\net46\System.Security.Cryptography.X509Certificates.dll + True True - + - ..\..\packages\System.Security.Cryptography.X509Certificates\ref\net461\System.Security.Cryptography.X509Certificates.dll - False + ..\..\packages\System.Security.Cryptography.X509Certificates\lib\net461\System.Security.Cryptography.X509Certificates.dll + True True @@ -1202,7 +1292,7 @@ - + ..\..\packages\System.Security.Cryptography.X509Certificates\ref\netstandard1.4\System.Security.Cryptography.X509Certificates.dll @@ -1222,7 +1312,7 @@ - + ..\..\packages\System.Text.Encoding\ref\netstandard1.3\System.Text.Encoding.dll @@ -1242,7 +1332,7 @@ - + ..\..\packages\System.Text.Encoding.Extensions\ref\netstandard1.3\System.Text.Encoding.Extensions.dll @@ -1253,11 +1343,11 @@ - + - ..\..\packages\System.Text.RegularExpressions\ref\net463\System.Text.RegularExpressions.dll - False + ..\..\packages\System.Text.RegularExpressions\lib\net463\System.Text.RegularExpressions.dll + True True @@ -1280,31 +1370,22 @@ - + - ..\..\packages\System.Text.RegularExpressions\ref\netstandard1.6\System.Text.RegularExpressions.dll - False + ..\..\packages\System.Text.RegularExpressions\lib\netstandard1.6\System.Text.RegularExpressions.dll + True True - + - ..\..\packages\System.Threading\ref\netstandard1.0\System.Threading.dll - False - True - - - - - - - ..\..\packages\System.Threading\ref\netstandard1.3\System.Threading.dll - False + ..\..\packages\System.Threading\lib\netstandard1.3\System.Threading.dll + True True @@ -1320,7 +1401,7 @@ - + ..\..\packages\System.Threading.Tasks\ref\netstandard1.3\System.Threading.Tasks.dll @@ -1331,7 +1412,7 @@ - + ..\..\packages\System.Threading.Tasks.Extensions\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll @@ -1342,84 +1423,106 @@ - + - - ..\..\packages\System.Threading.Timer\ref\netstandard1.2\System.Threading.Timer.dll - False + + ..\..\packages\System.Threading.Tasks.Parallel\lib\netstandard1.3\System.Threading.Tasks.Parallel.dll + True True - + - + + ..\..\packages\System.Threading.Thread\lib\net46\System.Threading.Thread.dll + True True - + - - ..\..\packages\System.Xml.ReaderWriter\ref\net46\System.Xml.ReaderWriter.dll - False - True - - - True - - - - - - - ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.0\System.Xml.ReaderWriter.dll - False - True - - - - - - - ..\..\packages\System.Xml.ReaderWriter\ref\netstandard1.3\System.Xml.ReaderWriter.dll - False + + ..\..\packages\System.Threading.Thread\lib\netstandard1.3\System.Threading.Thread.dll + True True - + + + + ..\..\packages\System.Threading.ThreadPool\lib\net46\System.Threading.ThreadPool.dll + True + True + + + + + + + ..\..\packages\System.Threading.ThreadPool\lib\netstandard1.3\System.Threading.ThreadPool.dll + True + True + + + + + + + + + True + + + + + + + True + + + ..\..\packages\System.Xml.ReaderWriter\lib\net46\System.Xml.ReaderWriter.dll + True + True + + + + + + + ..\..\packages\System.Xml.ReaderWriter\lib\netstandard1.3\System.Xml.ReaderWriter.dll + True + True + + + + + + True - + - ..\..\packages\System.Xml.XDocument\ref\netstandard1.0\System.Xml.XDocument.dll - False - True - - - - - - - ..\..\packages\System.Xml.XDocument\ref\netstandard1.3\System.Xml.XDocument.dll - False + ..\..\packages\System.Xml.XDocument\lib\netstandard1.3\System.Xml.XDocument.dll + True True - + ..\..\packages\xunit.abstractions\lib\net35\xunit.abstractions.dll @@ -1428,7 +1531,7 @@ - + ..\..\packages\xunit.abstractions\lib\netstandard1.0\xunit.abstractions.dll @@ -1439,10 +1542,10 @@ - + - ..\..\packages\xunit.assert\lib\portable-net45+win8+wp8+wpa81\xunit.assert.dll + ..\..\packages\xunit.assert\lib\netstandard1.1\xunit.assert.dll True True @@ -1450,7 +1553,7 @@ - + ..\..\packages\xunit.extensibility.core\lib\netstandard1.1\xunit.core.dll @@ -1461,7 +1564,7 @@ - + ..\..\packages\xunit.extensibility.execution\lib\net452\xunit.execution.desktop.dll @@ -1470,7 +1573,7 @@ - + ..\..\packages\xunit.extensibility.execution\lib\netstandard1.1\xunit.execution.dotnet.dll @@ -1480,27 +1583,4 @@ - - - - - - - - - - - - - True - - - - - - OpenTK - {a37a7e14-0000-0000-0000-000000000000} - True - - \ No newline at end of file From 043c4e3c5acf40542d6076992d9e8aea266e9ccf Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 14:45:23 +0200 Subject: [PATCH 14/66] Added code coverage CI step. --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 88b294ad..60792844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,8 @@ before_install: script: - ./build.sh NuGet + +after_success: + - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert packages/xunit.runner.console/tools/xunit.console.exe -parallel none tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll + - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert "packages/xunit.runner.console/tools/xunit.console.exe" "tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll" -parallel none + - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd + - bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash) From 23bbe37eb9d735a83750635718b045bf8a25ba7f Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 14:46:50 +0200 Subject: [PATCH 15/66] Renamed Vectors.fs to Vector2Tests.fs. --- tests/OpenTK.Tests/OpenTK.Tests.fsproj | 2 +- tests/OpenTK.Tests/{Vectors.fs => Vector2Tests.fs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/OpenTK.Tests/{Vectors.fs => Vector2Tests.fs} (100%) diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index c4b2094a..408f9fa8 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -62,7 +62,7 @@ - + diff --git a/tests/OpenTK.Tests/Vectors.fs b/tests/OpenTK.Tests/Vector2Tests.fs similarity index 100% rename from tests/OpenTK.Tests/Vectors.fs rename to tests/OpenTK.Tests/Vector2Tests.fs From 7d883f2ca996e991b577c14bf86e4c88104090b9 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 14:59:34 +0200 Subject: [PATCH 16/66] Updated gitignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 9399ea25..8a029402 100644 --- a/.gitignore +++ b/.gitignore @@ -174,6 +174,8 @@ temp/ # Test results produced by build TestResults.xml +output.mlpd +coverage.xml # Nuget outputs nuget/*.nupkg From 89f49e35e7a1af2e585b4f2ee78722f1beb4a51c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 15:01:06 +0200 Subject: [PATCH 17/66] Corrected mangled reapplication. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 60792844..c0a6c143 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,6 @@ script: - ./build.sh NuGet after_success: - - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert packages/xunit.runner.console/tools/xunit.console.exe -parallel none tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll + - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert "packages/xunit.runner.console/tools/xunit.console.exe" "tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll" -parallel none - - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd - - bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash) + - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert "packages/xunit.runner.console/tools/xunit.console.exe" "tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll" -parallel none + - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd + - bash <(curl -s https://codecov.io/bash) From 890d96798a9bc46e4c62f835892f1df571032133 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 16:14:04 +0200 Subject: [PATCH 18/66] Added more tests for the Vector2 class. --- tests/OpenTK.Tests/Vector2Tests.fs | 169 +++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 8 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index ac70d1c9..fa79fab4 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -22,13 +22,7 @@ module Vector2 = Assert.Equal(x,v.X) Assert.Equal(y,v.Y) - [] - let ``Index operators work for the correct components`` (x,y) = - let v = Vector2(x,y) - Assert.Equal(v.[0],v.X) - Assert.Equal(v.[1],v.Y) - -// [] + //[] // disabled - behaviour needs discussion let ``Clamping works for each component`` (a : Vector2,b : Vector2,c : Vector2) = let inline clamp (value : float32) minV maxV = MathHelper.Clamp(value,minV,maxV) @@ -40,7 +34,34 @@ module Vector2 = let ``Length is always >= 0`` (a : Vector2) = // Assert.True(a.Length >= 0.0f) - + + [ |])>] + module Indexing = + // + [] + let ``Index operators work for the correct components`` (x,y) = + let v = Vector2(x,y) + Assert.Equal(v.[0],v.X) + Assert.Equal(v.[1],v.Y) + + [] + let ``Vector indexing throws index out of range exception correctly`` (x, y) = + let mutable v = Vector2(x, y) + let invalidIndexingAccess = fun() -> v.[2] |> ignore + Assert.Throws(invalidIndexingAccess) |> ignore + + let invalidIndexingAssignment = (fun() -> v.[2] <- x) + Assert.Throws(invalidIndexingAssignment) |> ignore + + [] + let ``Component assignment by indexing works`` (x, y) = + let mutable v = Vector2() + v.[0] <- x + v.[1] <- y + Assert.Equal(x, v.X) + Assert.Equal(y, v.Y) + + [ |])>] module ``Simple Properties`` = // @@ -95,6 +116,11 @@ module Vector2 = let r = a * f Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) + + // Inverse direction + let r = f * a + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) [ |])>] module Subtraction = @@ -114,3 +140,130 @@ module Vector2 = let r = a / f Assert.ApproximatelyEqual(a.X / f,r.X) Assert.ApproximatelyEqual(a.Y / f,r.Y) + + [ |])>] + module Negation = + // + [] + let ``Vector negation operator works`` (x, y) = + let v = Vector2(x, y) + let vNeg = -v + Assert.Equal(-x, vNeg.X) + Assert.Equal(-y, vNeg.Y) + + [ |])>] + module Equality = + // + [] + let ``Vector equality operator works`` (x, y) = + let v1 = Vector2(x, y) + let v2 = Vector2(x, y) + let equality = v1 = v2 + Assert.True(equality) + + [] + let ``Vector inequality operator works`` (x, y) = + let v1 = Vector2(x, y) + let v2 = Vector2(y, x) + let inequality = v1 <> v2 + Assert.True(inequality) + + [] + let ``Vector equality method works`` (x, y) = + let v1 = Vector2(x, y) + let v2 = Vector2(x, y) + let notVector = Matrix2() + + let equality = v1.Equals(v2) + let inequalityByOtherType = v1.Equals(notVector) + + Assert.True(equality) + Assert.False(inequalityByOtherType) + + [ |])>] + module Swizzling = + // + [] + let ``Vector swizzling works`` (x, y) = + let v1 = Vector2(x, y) + let v2 = Vector2(y, x) + + let v1yx = v1.Yx; + Assert.Equal(v2, v1yx); + + [ |])>] + module Interpolation = + // + [] + let ``Linear interpolation works`` (a : Vector2, b : Vector2, q) = + + let blend = q + + let rX = blend * (b.X - a.X) + a.X + let rY = blend * (b.Y - a.Y) + a.Y + let vExp = Vector2(rX, rY) + + Assert.Equal(vExp, Vector2.Lerp(a, b, q)) + + let mutable vRes = Vector2() + Vector2.Lerp(ref a, ref b, q, &vRes) + Assert.Equal(vExp, vRes) + + [] + let ``Barycentric interpolation works`` (a : Vector2, b : Vector2, c : Vector2, u, v) = + + let r = a + u * (b - a) + v * (c - a) + + Assert.Equal(r, Vector2.BaryCentric(a, b, c, u, v)) + + let mutable vRes = Vector2() + Vector2.BaryCentric(ref a, ref b, ref c, u, v, &vRes) + Assert.Equal(r, vRes) + + [ |])>] + module ``Vector products`` = + // + [] + let ``Dot product works`` (a : Vector2, b : Vector2) = + let dot = a.X * b.X + a.Y * b.Y + + Assert.Equal(dot, Vector2.Dot(a, b)); + + let mutable vRes = (float32)0 + Vector2.Dot(ref a, ref b, &vRes) + Assert.Equal(dot, vRes) + + [] + let ``Perpendicular dot product works`` (a : Vector2, b : Vector2) = + let dot = a.X * b.Y + a.Y * b.X + + Assert.Equal(dot, Vector2.PerpDot(a, b)); + + let mutable vRes = (float32)0 + Vector2.PerpDot(ref a, ref b, &vRes) + Assert.Equal(dot, vRes) + + [ |])>] + module Normalization = + // + [] + let ``Normalization works`` (a : Vector2) = + let scale = 1.0f / a.Length + let norm = Vector2(a.X * scale, a.Y * scale) + + Assert.Equal(norm, Vector2.Normalize(a)); + + let mutable vRes = Vector2() + Vector2.Normalize(ref a, &vRes) + Assert.Equal(norm, vRes) + + [] + let ``Fast approximate normalization works`` (a : Vector2, b : Vector2) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + let norm = Vector2(a.X * scale, a.Y * scale) + + Assert.Equal(norm, Vector2.Normalize(a)); + + let mutable vRes = Vector2() + Vector2.Normalize(ref a, &vRes) + Assert.Equal(norm, vRes) \ No newline at end of file From c4c4dfecc504604828bf2b03943db5deb57d20f0 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 16:39:19 +0200 Subject: [PATCH 19/66] Corrected badly formed tests. --- tests/OpenTK.Tests/Vector2Tests.fs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index fa79fab4..3925c7c2 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -159,6 +159,7 @@ module Vector2 = let v1 = Vector2(x, y) let v2 = Vector2(x, y) let equality = v1 = v2 + Assert.True(equality) [] @@ -166,6 +167,7 @@ module Vector2 = let v1 = Vector2(x, y) let v2 = Vector2(y, x) let inequality = v1 <> v2 + Assert.True(inequality) [] @@ -205,8 +207,7 @@ module Vector2 = Assert.Equal(vExp, Vector2.Lerp(a, b, q)) - let mutable vRes = Vector2() - Vector2.Lerp(ref a, ref b, q, &vRes) + let vRes = Vector2.Lerp(ref a, ref b, q) Assert.Equal(vExp, vRes) [] @@ -216,8 +217,7 @@ module Vector2 = Assert.Equal(r, Vector2.BaryCentric(a, b, c, u, v)) - let mutable vRes = Vector2() - Vector2.BaryCentric(ref a, ref b, ref c, u, v, &vRes) + let vRes = Vector2.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) [ |])>] @@ -229,18 +229,16 @@ module Vector2 = Assert.Equal(dot, Vector2.Dot(a, b)); - let mutable vRes = (float32)0 - Vector2.Dot(ref a, ref b, &vRes) + let vRes = Vector2.Dot(ref a, ref b) Assert.Equal(dot, vRes) [] let ``Perpendicular dot product works`` (a : Vector2, b : Vector2) = - let dot = a.X * b.Y + a.Y * b.X + let dot = a.X * b.Y - a.Y * b.X Assert.Equal(dot, Vector2.PerpDot(a, b)); - let mutable vRes = (float32)0 - Vector2.PerpDot(ref a, ref b, &vRes) + let vRes = Vector2.PerpDot(ref a, ref b) Assert.Equal(dot, vRes) [ |])>] @@ -250,20 +248,15 @@ module Vector2 = let ``Normalization works`` (a : Vector2) = let scale = 1.0f / a.Length let norm = Vector2(a.X * scale, a.Y * scale) - + let vRes = Vector2.Normalize(ref a) Assert.Equal(norm, Vector2.Normalize(a)); - - let mutable vRes = Vector2() - Vector2.Normalize(ref a, &vRes) Assert.Equal(norm, vRes) [] let ``Fast approximate normalization works`` (a : Vector2, b : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) let norm = Vector2(a.X * scale, a.Y * scale) + let vRes = Vector2.NormalizeFast(ref a) - Assert.Equal(norm, Vector2.Normalize(a)); - - let mutable vRes = Vector2() - Vector2.Normalize(ref a, &vRes) + Assert.Equal(norm, Vector2.NormalizeFast(a)); Assert.Equal(norm, vRes) \ No newline at end of file From 9ac04b9e364631355e9445f3a4597a0f860409dd Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 16:45:18 +0200 Subject: [PATCH 20/66] Ensure that the vectors are different. --- tests/OpenTK.Tests/Vector2Tests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 3925c7c2..1bde27da 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -165,7 +165,7 @@ module Vector2 = [] let ``Vector inequality operator works`` (x, y) = let v1 = Vector2(x, y) - let v2 = Vector2(y, x) + let v2 = Vector2(x + (float32)1 , y + (float32)1) let inequality = v1 <> v2 Assert.True(inequality) From 48889ad30817d979cd9c823b490e037e03cf4554 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 17:48:33 +0200 Subject: [PATCH 21/66] Ported existing Matrix4 tests. --- tests/OpenTK.Tests/Matrix4Tests.fs | 282 +++++++++++++++++++++++++ tests/OpenTK.Tests/OpenTK.Tests.fsproj | 1 + 2 files changed, 283 insertions(+) create mode 100644 tests/OpenTK.Tests/Matrix4Tests.fs diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs new file mode 100644 index 00000000..920788e6 --- /dev/null +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -0,0 +1,282 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +module Matrix4 = + [ |])>] + module Constructors = + // + [] + let ``Sixteen value constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + Assert.Equal(a, A.M11) + Assert.Equal(b, A.M12) + Assert.Equal(c, A.M13) + Assert.Equal(d, A.M14) + + Assert.Equal(e, A.M21) + Assert.Equal(f, A.M22) + Assert.Equal(g, A.M23) + Assert.Equal(h, A.M24) + + Assert.Equal(i, A.M31) + Assert.Equal(j, A.M32) + Assert.Equal(k, A.M33) + Assert.Equal(l, A.M34) + + Assert.Equal(m, A.M41) + Assert.Equal(n, A.M42) + Assert.Equal(o, A.M43) + Assert.Equal(p, A.M44) + + [] + let ``Matrix3 partial constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i) = + let B = Matrix3(a, b, c, d, e, f, g, h, i) + let A = Matrix4(B) + + Assert.Equal(a, A.M11) + Assert.Equal(b, A.M12) + Assert.Equal(c, A.M13) + Assert.Equal((float32)0, A.M14) + + Assert.Equal(d, A.M21) + Assert.Equal(e, A.M22) + Assert.Equal(f, A.M23) + Assert.Equal((float32)0, A.M24) + + Assert.Equal(g, A.M31) + Assert.Equal(h, A.M32) + Assert.Equal(i, A.M33) + Assert.Equal((float32)0, A.M34) + + Assert.Equal((float32)0, A.M41) + Assert.Equal((float32)0, A.M42) + Assert.Equal((float32)0, A.M43) + Assert.Equal((float32)1, A.M44) + + [] + let ``Four-vector4 constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let v1 = Vector4(a, b, c, d) + let v2 = Vector4(e, f, g, h) + let v3 = Vector4(i, j, k, l) + let v4 = Vector4(m, n, o, p) + + let A = Matrix4(v1, v2, v3, v4) + + Assert.Equal(a, A.M11) + Assert.Equal(b, A.M12) + Assert.Equal(c, A.M13) + Assert.Equal(d, A.M14) + + Assert.Equal(e, A.M21) + Assert.Equal(f, A.M22) + Assert.Equal(g, A.M23) + Assert.Equal(h, A.M24) + + Assert.Equal(i, A.M31) + Assert.Equal(j, A.M32) + Assert.Equal(k, A.M33) + Assert.Equal(l, A.M34) + + Assert.Equal(m, A.M41) + Assert.Equal(n, A.M42) + Assert.Equal(o, A.M43) + Assert.Equal(p, A.M44) + + [ |])>] + module Equality = + // + [] + let ``Sixteen value constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + let equality = A = B + + Assert.True(equality) + + [ |])>] + module Multiplication = + // + [] + let ``Matrix multiplication is done by row/column multiplication and summation`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let R11 = a*a + b*e + c*i + d*m + let R12 = a*b + b*f + c*j + d*n + let R13 = a*c + b*g + c*k + d*o + let R14 = a*d + b*h + c*l + d*p + + let R21 = e*a + f*e + g*i + h*m + let R22 = e*b + f*f + g*j + h*n + let R23 = e*c + f*g + g*k + h*o + let R24 = e*d + f*h + g*l + h*p + + let R31 = i*a + j*e + k*i + l*m + let R32 = i*b + j*f + k*j + l*n + let R33 = i*c + j*g + k*k + l*o + let R34 = i*d + j*h + k*l + l*p + + let R41 = m*a + n*e + o*i + p*m + let R42 = m*b + n*f + o*j + p*n + let R43 = m*c + n*g + o*k + p*o + let R44 = m*d + n*h + o*l + p*p + + let AB = A*B + + Assert.Equal(R11, AB.M11) + Assert.Equal(R12, AB.M12) + Assert.Equal(R13, AB.M13) + Assert.Equal(R14, AB.M14) + + Assert.Equal(R21, AB.M21) + Assert.Equal(R22, AB.M22) + Assert.Equal(R23, AB.M23) + Assert.Equal(R24, AB.M24) + + Assert.Equal(R31, AB.M31) + Assert.Equal(R32, AB.M32) + Assert.Equal(R33, AB.M33) + Assert.Equal(R34, AB.M34) + + Assert.Equal(R41, AB.M41) + Assert.Equal(R42, AB.M42) + Assert.Equal(R43, AB.M43) + Assert.Equal(R44, AB.M44) + + + [ |])>] + module Addition = + // + [] + let ``Matrix addition adds corresponding components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let sum = A + B + + Assert.Equal(a + a, sum.M11) + Assert.Equal(b + b, sum.M12) + Assert.Equal(c + c, sum.M13) + Assert.Equal(d + d, sum.M14) + + Assert.Equal(e + e, sum.M21) + Assert.Equal(f + f, sum.M22) + Assert.Equal(g + g, sum.M23) + Assert.Equal(h + h, sum.M24) + + Assert.Equal(i + i, sum.M31) + Assert.Equal(j + j, sum.M32) + Assert.Equal(k + k, sum.M33) + Assert.Equal(l + l, sum.M34) + + Assert.Equal(m + m, sum.M41) + Assert.Equal(n + n, sum.M42) + Assert.Equal(o + o, sum.M43) + Assert.Equal(p + p, sum.M44) + + [ |])>] + module Subtraction = + // + [] + let ``Matrix subtraction subtracts corresponding components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let sub = A - B + + Assert.Equal(a - a, sub.M11) + Assert.Equal(b - b, sub.M12) + Assert.Equal(c - c, sub.M13) + Assert.Equal(d - d, sub.M14) + + Assert.Equal(e - e, sub.M21) + Assert.Equal(f - f, sub.M22) + Assert.Equal(g - g, sub.M23) + Assert.Equal(h - h, sub.M24) + + Assert.Equal(i - i, sub.M31) + Assert.Equal(j - j, sub.M32) + Assert.Equal(k - k, sub.M33) + Assert.Equal(l - l, sub.M34) + + Assert.Equal(m - m, sub.M41) + Assert.Equal(n - n, sub.M42) + Assert.Equal(o - o, sub.M43) + Assert.Equal(p - p, sub.M44) + + [ |])>] + module Indexing = + // + [] + let ``Matrix indexing sets correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let mutable A = Matrix4() + + A.[0, 0] <- a + A.[0, 1] <- b + A.[0, 2] <- c + A.[0, 3] <- d + + A.[1, 0] <- e + A.[1, 1] <- f + A.[1, 2] <- g + A.[1, 3] <- h + + A.[2, 0] <- i + A.[2, 1] <- j + A.[2, 2] <- k + A.[2, 3] <- l + + A.[3, 0] <- m + A.[3, 1] <- n + A.[3, 2] <- o + A.[3, 3] <- p + + Assert.Equal(a, A.M11) + Assert.Equal(b, A.M12) + Assert.Equal(c, A.M13) + Assert.Equal(d, A.M14) + + Assert.Equal(e, A.M21) + Assert.Equal(f, A.M22) + Assert.Equal(g, A.M23) + Assert.Equal(h, A.M24) + + Assert.Equal(i, A.M31) + Assert.Equal(j, A.M32) + Assert.Equal(k, A.M33) + Assert.Equal(l, A.M34) + + Assert.Equal(m, A.M41) + Assert.Equal(n, A.M42) + Assert.Equal(o, A.M43) + Assert.Equal(p, A.M44) + + [] + let ``Matrix indexing throws on negative indices`` (a) = + let mutable A = Matrix4() + + let invalidIndexingAssignmentR = fun() -> A.[-1, 2] <- a + let invalidIndexingAssignmentC = fun() -> A.[1, -2] <- a + let invalidIndexingAssignmentRC = fun() -> A.[-1, -2] <- a + + Assert.Throws(invalidIndexingAssignmentR) |> ignore + Assert.Throws(invalidIndexingAssignmentC) |> ignore + Assert.Throws(invalidIndexingAssignmentRC) |> ignore + + [] + let ``Matrix indexing throws on large indices`` (a) = + let mutable A = Matrix4() + + let invalidIndexingAssignmentR = fun() -> A.[5, 2] <- a + let invalidIndexingAssignmentC = fun() -> A.[1, 6] <- a + let invalidIndexingAssignmentRC = fun() -> A.[7, 12] <- a + + Assert.Throws(invalidIndexingAssignmentR) |> ignore + Assert.Throws(invalidIndexingAssignmentC) |> ignore + Assert.Throws(invalidIndexingAssignmentRC) |> ignore \ No newline at end of file diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index 408f9fa8..93abb4d6 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -62,6 +62,7 @@ + From 108906dfe4f6da0cc3ddb0c4c8e6904812aa6403 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 20:08:41 +0200 Subject: [PATCH 22/66] Ported all Vector3 tests. --- .../{MathHelper.fs => MathHelperTests.fs} | 0 tests/OpenTK.Tests/Matrix4Tests.fs | 18 +- tests/OpenTK.Tests/OpenTK.Tests.fsproj | 5 +- tests/OpenTK.Tests/Vector2Tests.fs | 10 +- tests/OpenTK.Tests/Vector3Tests.fs | 527 ++++++++++++++++++ 5 files changed, 552 insertions(+), 8 deletions(-) rename tests/OpenTK.Tests/{MathHelper.fs => MathHelperTests.fs} (100%) create mode 100644 tests/OpenTK.Tests/Vector3Tests.fs diff --git a/tests/OpenTK.Tests/MathHelper.fs b/tests/OpenTK.Tests/MathHelperTests.fs similarity index 100% rename from tests/OpenTK.Tests/MathHelper.fs rename to tests/OpenTK.Tests/MathHelperTests.fs diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 920788e6..8153abff 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -265,10 +265,18 @@ module Matrix4 = let invalidIndexingAssignmentC = fun() -> A.[1, -2] <- a let invalidIndexingAssignmentRC = fun() -> A.[-1, -2] <- a + let invalidIndexingAccessR = fun() -> A.[-1, 2] |> ignore + let invalidIndexingAccessC = fun() -> A.[1, -2] |> ignore + let invalidIndexingAccessRC = fun() -> A.[-1, -2] |> ignore + Assert.Throws(invalidIndexingAssignmentR) |> ignore Assert.Throws(invalidIndexingAssignmentC) |> ignore Assert.Throws(invalidIndexingAssignmentRC) |> ignore + Assert.Throws(invalidIndexingAccessR) |> ignore + Assert.Throws(invalidIndexingAccessC) |> ignore + Assert.Throws(invalidIndexingAccessRC) |> ignore + [] let ``Matrix indexing throws on large indices`` (a) = let mutable A = Matrix4() @@ -277,6 +285,14 @@ module Matrix4 = let invalidIndexingAssignmentC = fun() -> A.[1, 6] <- a let invalidIndexingAssignmentRC = fun() -> A.[7, 12] <- a + let invalidIndexingAccessR = fun() -> A.[5, 2] |> ignore + let invalidIndexingAccessC = fun() -> A.[1, 6] |> ignore + let invalidIndexingAccessRC = fun() -> A.[7, 12] |> ignore + Assert.Throws(invalidIndexingAssignmentR) |> ignore Assert.Throws(invalidIndexingAssignmentC) |> ignore - Assert.Throws(invalidIndexingAssignmentRC) |> ignore \ No newline at end of file + Assert.Throws(invalidIndexingAssignmentRC) |> ignore + + Assert.Throws(invalidIndexingAccessR) |> ignore + Assert.Throws(invalidIndexingAccessC) |> ignore + Assert.Throws(invalidIndexingAccessRC) |> ignore \ No newline at end of file diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index 93abb4d6..09bd26c0 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -58,13 +58,14 @@ --> - - + + + diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 1bde27da..e69f2321 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -100,19 +100,19 @@ module Vector2 = module Multiplication = // [] - let ``Vector multiplication is the same as component multiplication`` (a : Vector2,b : Vector2) = + let ``Vector2 multiplication is the same as component multiplication`` (a : Vector2, b : Vector2) = let c = a * b Assert.Equal(a.X * b.X,c.X) Assert.Equal(a.Y * b.Y,c.Y) [] - let ``Vector multiplication is commutative`` (a : Vector2,b : Vector2) = + let ``Vector2 multiplication is commutative`` (a : Vector2, b : Vector2) = let r1 = a * b let r2 = b * a Assert.Equal(r1,r2) [] - let ``Vector-float multiplication is the same as component-float multiplication`` (a : Vector2,f : float32) = + let ``Vector2-float multiplication is the same as component-float multiplication`` (a : Vector2, f : float32) = let r = a * f Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) @@ -126,7 +126,7 @@ module Vector2 = module Subtraction = // [] - let ``Vector subtraction is the same as component subtraction`` (a : Vector2,b : Vector2) = + let ``Vector2 subtraction is the same as component subtraction`` (a : Vector2, b : Vector2) = let c = a - b Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) @@ -135,7 +135,7 @@ module Vector2 = module Division = // [] - let ``Vector-float division is the same as component-float division`` (a : Vector2,f : float32) = + let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f Assert.ApproximatelyEqual(a.X / f,r.X) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs new file mode 100644 index 00000000..77bde230 --- /dev/null +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -0,0 +1,527 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open OpenTK + +module Vector3 = + [ |])>] + module Constructors = + // + [] + let ``Triple value constructor sets all components to the correct values`` (a, b, c) = + let v = Vector3(a, b, c) + + Assert.Equal(a, v.X) + Assert.Equal(b, v.Y) + Assert.Equal(c, v.Z) + + [] + let ``Single value constructor sets all components to the correct values`` (a : float32) = + let v = Vector3(a) + + Assert.Equal(a, v.X) + Assert.Equal(a, v.Y) + Assert.Equal(a, v.Z) + + [] + let ``Vector2 value constructor sets all components to the correct values`` (a, b) = + let v1 = Vector2(a, b) + let v2 = Vector3(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + + Assert.Equal(a, v2.X) + Assert.Equal(b, v2.Y) + Assert.Equal((float32)0, v2.Z) + + [] + let ``Vector3 value constructor sets all components to the correct values`` (a, b, c) = + let v1 = Vector3(a, b, c) + let v2 = Vector3(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + Assert.Equal(v1.Z, v2.Z) + + Assert.Equal(a, v2.X) + Assert.Equal(b, v2.Y) + Assert.Equal(c, v2.Z) + + [ |])>] + module Indexing = + // + [] + let ``Index operator accesses the correct components`` (a, b, c) = + let v = Vector3(a, b, c) + + Assert.Equal(a, v.[0]) + Assert.Equal(b, v.[1]) + Assert.Equal(c, v.[2]) + + [] + let ``Index operator throws exception for negative indices`` (a, b, c) = + let mutable v = Vector3(a, b, c) + + let invalidIndexingAccess = fun() -> v.[-1] |> ignore + let invalidIndexingAssignment = fun() -> v.[-1] <- a + + Assert.Throws(invalidIndexingAccess) |> ignore + Assert.Throws(invalidIndexingAssignment) |> ignore + + [] + let ``Index operator throws exception for large indices`` (a, b, c) = + let mutable v = Vector3(a, b, c) + + let invalidIndexingAccess = fun() -> v.[3] |> ignore + let invalidIndexingAssignment = fun() -> v.[3] <- a + + Assert.Throws(invalidIndexingAccess) |> ignore + Assert.Throws(invalidIndexingAssignment) |> ignore + + [ |])>] + module Length = + // + [] + let ``Length method works`` (a, b, c) = + let v = Vector3(a, b, c) + let l = System.Math.Sqrt((float)(a * a + b * b + c * c)) + + Assert.Equal((float32)l, v.Length) + + [] + let ``Fast length method works`` (a, b, c) = + let v = Vector3(a, b, c) + let l = 1.0f / MathHelper.InverseSqrtFast(a * a + b * b + c * c) + + Assert.Equal(l, v.LengthFast) + + [] + let ``Length squared method works`` (a, b, c) = + let v = Vector3(a, b, c) + let lsq = a * a + b * b + c * c + + Assert.Equal(lsq, v.LengthSquared) + + [ |])>] + module Normalization = + // + [] + let ``Normalization of instance, creating a new vector, works`` (a, b, c) = + let v = Vector3(a, b, c) + let l = v.Length + + let norm = v.Normalized() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + + [] + let ``Normalization of instance works`` (a, b, c) = + let v = Vector3(a, b, c) + let norm = Vector3(a, b, c) + norm.Normalize() + + let l = v.Length + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + + [] + let ``Fast approximate normalization of instance works`` (a, b, c) = + let v = Vector3(a, b, c) + let norm = Vector3(a, b, c) + norm.NormalizeFast() + + let scale = MathHelper.InverseSqrtFast(a * a + b * b + c * c) + + Assert.ApproximatelyEqual(v.X * scale, norm.X) + Assert.ApproximatelyEqual(v.Y * scale, norm.Y) + Assert.ApproximatelyEqual(v.Z * scale, norm.Z) + + [] + let ``Normalization by reference works`` (a : Vector3) = + let scale = 1.0f / a.Length + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + let vRes = Vector3.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) + + [] + let ``Normalization works`` (a : Vector3) = + let scale = 1.0f / a.Length + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + + [] + let ``Fast approximate normalization by reference works`` (a : Vector3) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + let vRes = Vector3.NormalizeFast(ref a) + + Assert.ApproximatelyEqual(norm, vRes) + + [] + let ``Fast approximate normalization works`` (a : Vector3) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + + Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a)); + + [ |])>] + module Addition = + // + [] + let ``Vector3 addition is the same as component addition`` (a : Vector3, b : Vector3) = + let c = a + b + + Assert.ApproximatelyEqual(a.X + b.X,c.X) + Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) + + [] + let ``Vector3 addition is commutative`` (a : Vector3, b : Vector3) = + let c = a + b + let c2 = b + a + + Assert.ApproximatelyEqual(c, c2) + + [] + let ``Vector3 addition is associative`` (a : Vector3, b : Vector3, c : Vector3) = + let r1 = (a + b) + c + let r2 = a + (b + c) + + Assert.ApproximatelyEqual(r1, r2) + + [ |])>] + module Subtraction = + // + [] + let ``Vector3 subtraction is the same as component subtraction`` (a : Vector3, b : Vector3) = + let c = a - b + + Assert.Equal(a.X - b.X,c.X) + Assert.Equal(a.Y - b.Y,c.Y) + Assert.Equal(a.Z - b.Z,c.Z) + + [ |])>] + module Multiplication = + // + [] + let ``Vector3 multiplication is the same as component multiplication`` (a : Vector3, b : Vector3) = + let c = a * b + + Assert.Equal(a.X * b.X,c.X) + Assert.Equal(a.Y * b.Y,c.Y) + Assert.Equal(a.Z * b.Z,c.Z) + + [] + let ``Vector3 multiplication is commutative`` (a : Vector3, b : Vector3) = + let r1 = a * b + let r2 = b * a + + Assert.Equal(r1, r2) + + [] + let ``Vector3-float multiplication is the same as component-float multiplication`` (a : Vector3, f : float32) = + let r = a * f + + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) + + // Inverse direction + let r = f * a + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) + + [] + let ``Vector3-Matrix3 multiplication works`` (a : Matrix3, b : Vector3) = + let res = a*b + + let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 + let c2 = b.X * a.M21 + b.Y * a.M22 + b.Z * a.M23 + let c3 = b.X * a.M31 + b.Y * a.M32 + b.Z * a.M33 + + let exp = Vector3(c1, c2, c3) + + Assert.Equal(exp, res) + + [ |])>] + module Division = + // + [] + let ``Vector3-float division is the same as component-float division`` (a : Vector3, f : float32) = + if not (approxEq f 0.0f) then // we don't support diving by zero. + let r = a / f + + Assert.ApproximatelyEqual(a.X / f,r.X) + Assert.ApproximatelyEqual(a.Y / f,r.Y) + Assert.ApproximatelyEqual(a.Z / f,r.Z) + + [ |])>] + module Negation = + // + [] + let ``Vector negation operator works`` (x, y, z) = + let v = Vector3(x, y, z) + let vNeg = -v + Assert.Equal(-x, vNeg.X) + Assert.Equal(-y, vNeg.Y) + Assert.Equal(-z, vNeg.Z) + + [ |])>] + module Equality = + // + [] + let ``Vector equality operator works`` (x, y, z) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(x, y, z) + let equality = v1 = v2 + + Assert.True(equality) + + [] + let ``Vector inequality operator works`` (x, y, z) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(x + (float32)1 , y + (float32)1, z + (float32)1) + let inequality = v1 <> v2 + + Assert.True(inequality) + + [] + let ``Vector equality method works`` (x, y, z) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(x, y, z) + let notVector = Matrix2() + + let equality = v1.Equals(v2) + let inequalityByOtherType = v1.Equals(notVector) + + Assert.True(equality) + Assert.False(inequalityByOtherType) + + [ |])>] + module Swizzling = + // + [] + let ``Vector swizzling works`` (x, y, z) = + let v = Vector3(x, y, z) + + let xyz = Vector3(x, y, z) + let xzy = Vector3(x, z, y) + let xy = Vector2(x, y) + let xz = Vector2(x, z) + + let yxz = Vector3(y, x, z) + let yzx = Vector3(y, z, x) + let yx = Vector2(y, x) + let yz = Vector2(y, z) + + let zxy = Vector3(z, x, y) + let zyx = Vector3(z, y, x) + let zx = Vector2(z, x) + let zy = Vector2(z, y) + + Assert.Equal(xyz, v); + Assert.Equal(xzy, v.Xzy); + Assert.Equal(xy, v.Xy); + Assert.Equal(xz, v.Xz); + + Assert.Equal(yxz, v.Yxz); + Assert.Equal(yzx, v.Yzx); + Assert.Equal(yx, v.Yx); + Assert.Equal(yz, v.Yz); + + Assert.Equal(zxy, v.Zxy); + Assert.Equal(zyx, v.Zyx); + Assert.Equal(zx, v.Zx); + Assert.Equal(zy, v.Zy); + + [ |])>] + module Interpolation = + // + [] + let ``Linear interpolation works`` (a : Vector3, b : Vector3, q) = + + let blend = q + + let rX = blend * (b.X - a.X) + a.X + let rY = blend * (b.Y - a.Y) + a.Y + let rZ = blend * (b.Z - a.Z) + a.Z + let vExp = Vector3(rX, rY, rZ) + + Assert.Equal(vExp, Vector3.Lerp(a, b, q)) + + let vRes = Vector3.Lerp(ref a, ref b, q) + Assert.Equal(vExp, vRes) + + [] + let ``Barycentric interpolation works`` (a : Vector3, b : Vector3, c : Vector3, u, v) = + + let r = a + u * (b - a) + v * (c - a) + + Assert.Equal(r, Vector3.BaryCentric(a, b, c, u, v)) + + let vRes = Vector3.BaryCentric(ref a, ref b, ref c, u, v) + Assert.Equal(r, vRes) + + [ |])>] + module ``Vector products`` = + // + [] + let ``Dot product works`` (a : Vector3, b : Vector3) = + let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z + + Assert.Equal(dot, Vector3.Dot(a, b)); + + let vRes = Vector3.Dot(ref a, ref b) + Assert.Equal(dot, vRes) + + [] + let ``Cross product works`` (a : Vector3, b : Vector3) = + let crossX = a.Y * b.Z - a.Z * b.Y + let crossY = a.Z * b.X - a.X * b.Z + let crossZ = a.X * b.Y - a.Y * b.X + let cross = Vector3(crossX, crossY, crossZ) + + Assert.Equal(cross, Vector3.Cross(a, b)); + + let vRes = Vector3.Cross(ref a, ref b) + Assert.Equal(cross, vRes) + + [ |])>] + module ``Component min and max`` = + // + [] + let ``Producing a new vector from the smallest components of given vectors works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let vMin = Vector3.ComponentMin(v1, v2) + + Assert.True(vMin.X <= v1.X) + Assert.True(vMin.X <= v2.X) + + Assert.True(vMin.Y <= v1.Y) + Assert.True(vMin.Y <= v2.Y) + + Assert.True(vMin.Z <= v1.Z) + Assert.True(vMin.Z <= v2.Z) + + [] + let ``Producing a new vector from the largest components of given vectors works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let vMax = Vector3.ComponentMax(v1, v2) + + Assert.True(vMax.X >= v1.X) + Assert.True(vMax.X >= v2.X) + + Assert.True(vMax.Y >= v1.Y) + Assert.True(vMax.Y >= v2.Y) + + Assert.True(vMax.Z >= v1.Z) + Assert.True(vMax.Z >= v2.Z) + + [] + let ``Producing a new vector from the smallest components of given vectors by reference works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let vMin = Vector3.ComponentMin(ref v1, ref v2) + + Assert.True(vMin.X <= v1.X) + Assert.True(vMin.X <= v2.X) + + Assert.True(vMin.Y <= v1.Y) + Assert.True(vMin.Y <= v2.Y) + + Assert.True(vMin.Z <= v1.Z) + Assert.True(vMin.Z <= v2.Z) + + [] + let ``Producing a new vector from the largest components of given vectors by reference works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let vMax = Vector3.ComponentMax(ref v1, ref v2) + + Assert.True(vMax.X >= v1.X) + Assert.True(vMax.X >= v2.X) + + Assert.True(vMax.Y >= v1.Y) + Assert.True(vMax.Y >= v2.Y) + + Assert.True(vMax.Z >= v1.Z) + Assert.True(vMax.Z >= v2.Z) + + [] + let ``Selecting the lesser of two vectors works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.Min(v1, v2) + + if l1 < l2 then + let equalsFirst = vMin = v1 + Assert.True(equalsFirst) + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + + [] + let ``Selecting the greater of two vectors works`` (x, y, z, u, w, q) = + let v1 = Vector3(x, y, z) + let v2 = Vector3(u, w, q) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.Max(v1, v2) + + if l1 >= l2 then + let equalsFirst = vMin = v1 + Assert.True(equalsFirst) + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + + [ |])>] + module Clamping = + // + [] + let ``Clamping one vector between two other vectors works`` (a : Vector3, b : Vector3, w : Vector3) = + let res = Vector3.Clamp(w, a, b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + Assert.Equal(expZ, res.Z) + + [] + let ``Clamping one vector between two other vectors works by reference`` (a : Vector3, b : Vector3, w : Vector3) = + let res = Vector3.Clamp(ref w, ref a, ref b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + Assert.Equal(expZ, res.Z) \ No newline at end of file From b83174af94dedd4aac20e6336ac6fa01f75516c5 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 20:21:16 +0200 Subject: [PATCH 23/66] Added additional check against nonmatrix objects. --- tests/OpenTK.Tests/Matrix4Tests.fs | 6 +++++- tests/OpenTK.Tests/Vector3Tests.fs | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 8153abff..a37cd92c 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -92,13 +92,17 @@ module Matrix4 = module Equality = // [] - let ``Sixteen value constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let ``Two matrices with identical values are equal`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let equality = A = B Assert.True(equality) + [] + let ``A matrix is not equal to an object which is not a matrix`` (a : Matrix4, b : Vector3) = + Assert.False(a.Equals(b)) + [ |])>] module Multiplication = // diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 77bde230..9d643543 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -113,13 +113,13 @@ module Vector3 = let ``Normalization of instance, creating a new vector, works`` (a, b, c) = let v = Vector3(a, b, c) let l = v.Length - + let norm = v.Normalized() Assert.ApproximatelyEqual(v.X / l, norm.X) Assert.ApproximatelyEqual(v.Y / l, norm.Y) Assert.ApproximatelyEqual(v.Z / l, norm.Z) - + [] let ``Normalization of instance works`` (a, b, c) = let v = Vector3(a, b, c) From 754e5776237f82c627f1ce8901a4c9a937a15408 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 21:26:21 +0200 Subject: [PATCH 24/66] Increased approximation tolerance. --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index eaff950f..a322b4cd 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 5 + let private BitAccuracy = 6 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From e4ec841e7a5caf67c2fabd9f0b615501e7876e9c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 21:31:11 +0200 Subject: [PATCH 25/66] Added preventing of division-by-zero cases when normalizing. --- tests/OpenTK.Tests/Vector3Tests.fs | 49 +++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 9d643543..4828f869 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -114,23 +114,28 @@ module Vector3 = let v = Vector3(a, b, c) let l = v.Length - let norm = v.Normalized() - - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) + // Dividing by zero is not supported + if not (approxEq l 0.0f) then + let norm = v.Normalized() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] let ``Normalization of instance works`` (a, b, c) = let v = Vector3(a, b, c) - let norm = Vector3(a, b, c) - norm.Normalize() - let l = v.Length - - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) + + if not (approxEq l 0.0f) then + let norm = Vector3(a, b, c) + norm.Normalize() + + + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] let ``Fast approximate normalization of instance works`` (a, b, c) = @@ -146,18 +151,20 @@ module Vector3 = [] let ``Normalization by reference works`` (a : Vector3) = - let scale = 1.0f / a.Length - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) - let vRes = Vector3.Normalize(ref a) - - Assert.ApproximatelyEqual(norm, vRes) + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + let vRes = Vector3.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) [] let ``Normalization works`` (a : Vector3) = - let scale = 1.0f / a.Length - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) - - Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); [] let ``Fast approximate normalization by reference works`` (a : Vector3) = From 03f916abbb430807e90627bad6d61a24c27c99e2 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 21:40:44 +0200 Subject: [PATCH 26/66] Added Vector4 constructor test. --- tests/OpenTK.Tests/Vector3Tests.fs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 4828f869..483c7596 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -51,6 +51,19 @@ module Vector3 = Assert.Equal(b, v2.Y) Assert.Equal(c, v2.Z) + [] + let ``Vector4 value constructor sets all components to the correct values`` (a, b, c, d) = + let v1 = Vector4(a, b, c, d) + let v2 = Vector3(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + Assert.Equal(v1.Z, v2.Z) + + Assert.Equal(a, v2.X) + Assert.Equal(b, v2.Y) + Assert.Equal(c, v2.Z) + [ |])>] module Indexing = // From 72b00b4460bee5ff8bc00df53a63778bf62a23c9 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:09:04 +0200 Subject: [PATCH 27/66] Added additional multiplication and division tests. --- tests/OpenTK.Tests/Vector3Tests.fs | 129 ++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 483c7596..a209386b 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -220,6 +220,22 @@ module Vector3 = Assert.ApproximatelyEqual(r1, r2) + [] + let ``Static Vector3 addition method works`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) + let sum = Vector3.Add(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3 addition method works by reference`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) + let sum = Vector3.Add(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + [ |])>] module Subtraction = // @@ -231,6 +247,22 @@ module Vector3 = Assert.Equal(a.Y - b.Y,c.Y) Assert.Equal(a.Z - b.Z,c.Z) + [] + let ``Static Vector3 subtraction method works`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) + let sum = Vector3.Subtract(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3 subtraction method works by reference`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) + let sum = Vector3.Subtract(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + [ |])>] module Multiplication = // @@ -264,7 +296,7 @@ module Vector3 = Assert.Equal(a.Z * f,r.Z) [] - let ``Vector3-Matrix3 multiplication works`` (a : Matrix3, b : Vector3) = + let ``Vector3-Matrix3 multiplication works for right-handed notation`` (a : Matrix3, b : Vector3) = let res = a*b let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 @@ -274,6 +306,34 @@ module Vector3 = let exp = Vector3(c1, c2, c3) Assert.Equal(exp, res) + + [] + let ``Vector3-Matrix3 multiplication works for left-handed notation`` (a : Matrix3, b : Vector3) = + let res = b*a + + let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 + let c2 = b.X * a.M12 + b.Y * a.M22 + b.Z * a.M32 + let c3 = b.X * a.M13 + b.Y * a.M23 + b.Z * a.M33 + + let exp = Vector3(c1, c2, c3) + + Assert.Equal(exp, res) + + [] + let ``Static Vector3 multiplication method works`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) + let sum = Vector3.Multiply(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3 multiplication method works by reference`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) + let sum = Vector3.Multiply(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) [ |])>] module Division = @@ -287,6 +347,38 @@ module Vector3 = Assert.ApproximatelyEqual(a.Y / f,r.Y) Assert.ApproximatelyEqual(a.Z / f,r.Z) + [] + let ``Static Vector3-Vector3 division method works`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) + let sum = Vector3.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3-Vector3 divison method works by reference`` (a : Vector3, b : Vector3) = + + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) + let sum = Vector3.Divide(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3-scalar division method works`` (a : Vector3, b : float32) = + + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) + let sum = Vector3.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector3-scalar divison method works by reference`` (a : Vector3, b : float32) = + + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) + let sum = Vector3.Divide(ref a, b) + + Assert.ApproximatelyEqual(v1, sum) + [ |])>] module Negation = // @@ -544,4 +636,37 @@ module Vector3 = Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) - Assert.Equal(expZ, res.Z) \ No newline at end of file + Assert.Equal(expZ, res.Z) + + [ |])>] + module ``Unit vectors``= + // + [] + let ``Unit X is correct`` = + let unitX = Vector3((float32)1, (float32)0, (float32)0) + + Assert.Equal(Vector3.UnitX, unitX) + + [] + let ``Unit Y is correct`` = + let unitY = Vector3((float32)0, (float32)1, (float32)0) + + Assert.Equal(Vector3.UnitY, unitY) + + [] + let ``Unit Z is correct`` = + let unitZ = Vector3((float32)0, (float32)0, (float32)1) + + Assert.Equal(Vector3.UnitZ, unitZ) + + [] + let ``Unit zero is correct`` = + let unitZero = Vector3((float32)0, (float32)0, (float32)0) + + Assert.Equal(Vector3.Zero, unitZero) + + [] + let ``Unit one is correct`` = + let unitOne = Vector3((float32)1, (float32)1, (float32)1) + + Assert.Equal(Vector3.One, unitOne) \ No newline at end of file From 05fcf7961e1c2d49833e056e096cc6e463142175 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:20:46 +0200 Subject: [PATCH 28/66] Added final multiplication test and split one test into two. --- tests/OpenTK.Tests/Vector3Tests.fs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index a209386b..b3ece0cc 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -282,18 +282,27 @@ module Vector3 = Assert.Equal(r1, r2) [] - let ``Vector3-float multiplication is the same as component-float multiplication`` (a : Vector3, f : float32) = + let ``Left-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = let r = a * f Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) - // Inverse direction + [] + let ``Right-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = let r = f * a Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) + + [] + let ``Static method Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = + let r = Vector3.Multiply(a, f) + + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) [] let ``Vector3-Matrix3 multiplication works for right-handed notation`` (a : Matrix3, b : Vector3) = From be213a782890d0ab42a52f556bbc5295143fa982 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:28:27 +0200 Subject: [PATCH 29/66] Fixed normalization tests in Vector3 and ported some common tests to Vector2. --- tests/OpenTK.Tests/Vector2Tests.fs | 113 ++++++++++++++++++++++++++--- tests/OpenTK.Tests/Vector3Tests.fs | 4 +- 2 files changed, 105 insertions(+), 12 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index e69f2321..e2947b73 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -35,6 +35,47 @@ module Vector2 = // Assert.True(a.Length >= 0.0f) + [ |])>] + module Length = + // + [] + let ``Length method works`` (a, b) = + let v = Vector2(a, b) + let l = System.Math.Sqrt((float)(a * a + b * b)) + + Assert.Equal((float32)l, v.Length) + + [] + let ``Fast length method works`` (a, b) = + let v = Vector2(a, b) + let l = 1.0f / MathHelper.InverseSqrtFast(a * a + b * b) + + Assert.Equal(l, v.LengthFast) + + [] + let ``Length squared method works`` (a, b) = + let v = Vector2(a, b) + let lsq = a * a + b * b + + Assert.Equal(lsq, v.LengthSquared) + + [ |])>] + module ``Unit vectors and perpendicularity`` = + // + [] + let ``Perpendicular vector to the right is correct`` (a, b) = + let v = Vector2(a, b) + let perp = Vector2(a, -b) + + Assert.Equal(perp, v.PerpendicularRight) + + [] + let ``Perpendicular vector to the left is correct`` (a, b) = + let v = Vector2(a, b) + let perp = Vector2(-a, b) + + Assert.Equal(perp, v.PerpendicularLeft) + [ |])>] module Indexing = // @@ -242,21 +283,73 @@ module Vector2 = Assert.Equal(dot, vRes) [ |])>] - module Normalization = + module Normalization = // [] - let ``Normalization works`` (a : Vector2) = - let scale = 1.0f / a.Length - let norm = Vector2(a.X * scale, a.Y * scale) - let vRes = Vector2.Normalize(ref a) - Assert.Equal(norm, Vector2.Normalize(a)); - Assert.Equal(norm, vRes) + let ``Normalization of instance, creating a new vector, works`` (a, b) = + let v = Vector2(a, b) + let l = v.Length + + // Dividing by zero is not supported + if not (approxEq l 0.0f) then + let norm = v.Normalized() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + + [] + let ``Normalization of instance works`` (a, b) = + let v = Vector2(a, b) + let l = v.Length + + if not (approxEq l 0.0f) then + let norm = Vector2(a, b) + norm.Normalize() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + + [] + let ``Fast approximate normalization of instance works`` (a, b) = + let v = Vector2(a, b) + let norm = Vector2(a, b) + norm.NormalizeFast() + + let scale = MathHelper.InverseSqrtFast(a * a + b * b) + + Assert.ApproximatelyEqual(v.X * scale, norm.X) + Assert.ApproximatelyEqual(v.Y * scale, norm.Y) [] - let ``Fast approximate normalization works`` (a : Vector2, b : Vector2) = + let ``Normalization by reference works`` (a : Vector2) = + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector2(a.X * scale, a.Y * scale) + let vRes = Vector2.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) + + [] + let ``Normalization works`` (a : Vector2) = + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector2(a.X * scale, a.Y * scale) + + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + + [] + let ``Fast approximate normalization by reference works`` (a : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + let norm = Vector2(a.X * scale, a.Y * scale) let vRes = Vector2.NormalizeFast(ref a) - Assert.Equal(norm, Vector2.NormalizeFast(a)); - Assert.Equal(norm, vRes) \ No newline at end of file + Assert.ApproximatelyEqual(norm, vRes) + + [] + let ``Fast approximate normalization works`` (a : Vector2) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + + let norm = Vector2(a.X * scale, a.Y * scale) + + Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index b3ece0cc..ab8fcd69 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -181,7 +181,7 @@ module Vector3 = [] let ``Fast approximate normalization by reference works`` (a : Vector3) = - let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) let vRes = Vector3.NormalizeFast(ref a) @@ -190,7 +190,7 @@ module Vector3 = [] let ``Fast approximate normalization works`` (a : Vector3) = - let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) From 476d55b5dd25fd8ac393838cf183cdb4298edcad Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:28:51 +0200 Subject: [PATCH 30/66] Missed one. --- tests/OpenTK.Tests/Vector2Tests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index e2947b73..7b6310b2 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -335,7 +335,7 @@ module Vector2 = let scale = 1.0f / a.Length let norm = Vector2(a.X * scale, a.Y * scale) - Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); [] let ``Fast approximate normalization by reference works`` (a : Vector2) = From a658d7a1cd843c3f050c6df19d725de36818bc8e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:38:54 +0200 Subject: [PATCH 31/66] Ported more arithmetic tests. --- tests/OpenTK.Tests/Vector2Tests.fs | 212 ++++++++++++++++++++++++++++- tests/OpenTK.Tests/Vector3Tests.fs | 12 +- 2 files changed, 213 insertions(+), 11 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 7b6310b2..2c9f01dc 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -65,14 +65,14 @@ module Vector2 = [] let ``Perpendicular vector to the right is correct`` (a, b) = let v = Vector2(a, b) - let perp = Vector2(a, -b) + let perp = Vector2(b, -a) Assert.Equal(perp, v.PerpendicularRight) [] let ``Perpendicular vector to the left is correct`` (a, b) = let v = Vector2(a, b) - let perp = Vector2(-a, b) + let perp = Vector2(-b, a) Assert.Equal(perp, v.PerpendicularLeft) @@ -136,6 +136,22 @@ module Vector2 = let r1 = (a + b) + c let r2 = a + (b + c) Assert.ApproximatelyEqual(r1,r2) + + [] + let ``Static Vector2 addition method is the same as component addition`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X + b.X, a.Y + b.Y) + let sum = Vector2.Add(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2 addition method by reference is the same as component addition`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X + b.X, a.Y + b.Y) + let sum = Vector2.Add(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) [ |])>] module Multiplication = @@ -153,15 +169,40 @@ module Vector2 = Assert.Equal(r1,r2) [] - let ``Vector2-float multiplication is the same as component-float multiplication`` (a : Vector2, f : float32) = + let ``Left-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = let r = a * f + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - // Inverse direction + [] + let ``Right-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = let r = f * a Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) + + [] + let ``Static Vector2 multiplication method is the same as component multiplication`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X * b.X, a.Y * b.Y) + let sum = Vector2.Multiply(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2 multiplication method by reference is the same as component multiplication`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X * b.X, a.Y * b.Y) + let sum = Vector2.Multiply(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static method Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = + let r = Vector2.Multiply(a, f) + + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) [ |])>] module Subtraction = @@ -171,6 +212,22 @@ module Vector2 = let c = a - b Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) + + [] + let ``Static Vector2 subtraction method is the same as component addition`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X - b.X, a.Y - b.Y) + let sum = Vector2.Subtract(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2 subtraction method by reference is the same as component addition`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X - b.X, a.Y - b.Y) + let sum = Vector2.Subtract(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) [ |])>] module Division = @@ -179,8 +236,41 @@ module Vector2 = let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f + Assert.ApproximatelyEqual(a.X / f,r.X) Assert.ApproximatelyEqual(a.Y / f,r.Y) + + [] + let ``Static Vector2-Vector2 division method works`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X / b.X, a.Y / b.Y) + let sum = Vector2.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2-Vector2 divison method works by reference`` (a : Vector2, b : Vector2) = + + let v1 = Vector2(a.X / b.X, a.Y / b.Y) + let sum = Vector2.Divide(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2-scalar division method works`` (a : Vector2, b : float32) = + + let v1 = Vector2(a.X / b, a.Y / b) + let sum = Vector2.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector2-scalar divison method works by reference`` (a : Vector2, b : float32) = + + let v1 = Vector2(a.X / b, a.Y / b) + let sum = Vector2.Divide(ref a, b) + + Assert.ApproximatelyEqual(v1, sum) [ |])>] module Negation = @@ -352,4 +442,116 @@ module Vector2 = let norm = Vector2(a.X * scale, a.Y * scale) - Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); \ No newline at end of file + Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); + + [ |])>] + module ``Component min and max`` = + // + [] + let ``Producing a new vector from the smallest components of given vectors works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let vMin = Vector2.ComponentMin(v1, v2) + + Assert.True(vMin.X <= v1.X) + Assert.True(vMin.X <= v2.X) + + Assert.True(vMin.Y <= v1.Y) + Assert.True(vMin.Y <= v2.Y) + + [] + let ``Producing a new vector from the largest components of given vectors works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let vMax = Vector2.ComponentMax(v1, v2) + + Assert.True(vMax.X >= v1.X) + Assert.True(vMax.X >= v2.X) + + Assert.True(vMax.Y >= v1.Y) + Assert.True(vMax.Y >= v2.Y) + + [] + let ``Producing a new vector from the smallest components of given vectors by reference works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let vMin = Vector2.ComponentMin(ref v1, ref v2) + + Assert.True(vMin.X <= v1.X) + Assert.True(vMin.X <= v2.X) + + Assert.True(vMin.Y <= v1.Y) + Assert.True(vMin.Y <= v2.Y) + + [] + let ``Producing a new vector from the largest components of given vectors by reference works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let vMax = Vector2.ComponentMax(ref v1, ref v2) + + Assert.True(vMax.X >= v1.X) + Assert.True(vMax.X >= v2.X) + + Assert.True(vMax.Y >= v1.Y) + Assert.True(vMax.Y >= v2.Y) + + [] + let ``Selecting the lesser of two vectors works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.Min(v1, v2) + + if l1 < l2 then + let equalsFirst = vMin = v1 + Assert.True(equalsFirst) + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + + [] + let ``Selecting the greater of two vectors works`` (x, y, u, w) = + let v1 = Vector2(x, y) + let v2 = Vector2(u, w) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.Max(v1, v2) + + if l1 >= l2 then + let equalsFirst = vMin = v1 + Assert.True(equalsFirst) + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + + [ |])>] + module Clamping = + // + [] + let ``Clamping one vector between two other vectors works`` (a : Vector2, b : Vector2, w : Vector2) = + let res = Vector2.Clamp(w, a, b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + + [] + let ``Clamping one vector between two other vectors works by reference`` (a : Vector2, b : Vector2, w : Vector2) = + let res = Vector2.Clamp(ref w, ref a, ref b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index ab8fcd69..b4ace2f0 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -221,7 +221,7 @@ module Vector3 = Assert.ApproximatelyEqual(r1, r2) [] - let ``Static Vector3 addition method works`` (a : Vector3, b : Vector3) = + let ``Static Vector3 addition method is the same as component addition`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(a, b) @@ -229,7 +229,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3 addition method works by reference`` (a : Vector3, b : Vector3) = + let ``Static Vector3 addition method by reference is the same as component addition`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(ref a, ref b) @@ -248,7 +248,7 @@ module Vector3 = Assert.Equal(a.Z - b.Z,c.Z) [] - let ``Static Vector3 subtraction method works`` (a : Vector3, b : Vector3) = + let ``Static Vector3 subtraction method is the same as component addition`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(a, b) @@ -256,7 +256,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3 subtraction method works by reference`` (a : Vector3, b : Vector3) = + let ``Static Vector3 subtraction method by reference is the same as component addition`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(ref a, ref b) @@ -329,7 +329,7 @@ module Vector3 = Assert.Equal(exp, res) [] - let ``Static Vector3 multiplication method works`` (a : Vector3, b : Vector3) = + let ``Static Vector3 multiplication method is the same as component multiplication`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(a, b) @@ -337,7 +337,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3 multiplication method works by reference`` (a : Vector3, b : Vector3) = + let ``Static Vector3 multiplication method by reference is the same as component multiplication`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(ref a, ref b) From d352853f479cb3e5b7aa20629931a9ebb3b0daf6 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 16:04:51 +0200 Subject: [PATCH 32/66] Complete coverage for Vector2. --- tests/OpenTK.Tests/Vector2Tests.fs | 46 ++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 2c9f01dc..5cddb743 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -4,6 +4,7 @@ open Xunit open FsCheck open FsCheck.Xunit open System +open System.Runtime.InteropServices open OpenTK module Vector2 = @@ -29,17 +30,17 @@ module Vector2 = let r = Vector2.Clamp(a,b,c) Assert.Equal(clamp a.X b.X c.X,r.X) Assert.Equal(clamp a.Y b.Y c.Y,r.Y) - - [] - let ``Length is always >= 0`` (a : Vector2) = - // - Assert.True(a.Length >= 0.0f) [ |])>] module Length = // [] - let ``Length method works`` (a, b) = + let ``Length is always >= 0`` (a : Vector2) = + // + Assert.True(a.Length >= 0.0f) + + [] + let ``Length follows the pythagorean theorem`` (a, b) = let v = Vector2(a, b) let l = System.Math.Sqrt((float)(a * a + b * b)) @@ -555,3 +556,36 @@ module Vector2 = Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) + + [ |])>] + module Transformation = + // + [] + let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) + + Assert.Equal(transformedVector, Vector2.Transform(v, q)) + + [] + let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) + + Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) + + [ |])>] + module Serialization = + // + [] + let ``The absolute size of a Vector2 is always the size of its components`` (v : Vector2) = + let expectedSize = sizeof * 2 + + Assert.Equal(expectedSize, Vector2.SizeInBytes) + Assert.Equal(expectedSize, Marshal.SizeOf(Vector2())) \ No newline at end of file From e33c3395afabab4fe810abe4cb18ea92afcc39e4 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 16:05:02 +0200 Subject: [PATCH 33/66] More tests. --- tests/OpenTK.Tests/Vector3Tests.fs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index b4ace2f0..8ac1b4ae 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -4,6 +4,7 @@ open Xunit open FsCheck open FsCheck.Xunit open System +open System.Runtime.InteropServices open OpenTK module Vector3 = @@ -678,4 +679,14 @@ module Vector3 = let ``Unit one is correct`` = let unitOne = Vector3((float32)1, (float32)1, (float32)1) - Assert.Equal(Vector3.One, unitOne) \ No newline at end of file + Assert.Equal(Vector3.One, unitOne) + + [ |])>] + module Serialization = + // + [] + let ``The absolute size of a Vector3 is always the size of its components`` (v : Vector3) = + let expectedSize = sizeof * 3 + + Assert.Equal(expectedSize, Vector3.SizeInBytes) + Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) \ No newline at end of file From ca0d54953444d91ae396476963a535a6161e1fd8 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 16:05:14 +0200 Subject: [PATCH 34/66] Add row property tests. --- tests/OpenTK.Tests/Matrix4Tests.fs | 82 +++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index a37cd92c..9c453b1a 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -152,6 +152,54 @@ module Matrix4 = Assert.Equal(R42, AB.M42) Assert.Equal(R43, AB.M43) Assert.Equal(R44, AB.M44) + + [] + let ``Matrix multiplication by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let R1 = Vector4(a, b, c, d) * scalar + let R2 = Vector4(e, f, g, h) * scalar + let R3 = Vector4(i, j, k, l) * scalar + let R4 = Vector4(m, n, o, p) * scalar + + let AScaled = A * scalar + + Assert.Equal(R1, AScaled.Row0) + Assert.Equal(R1, AScaled.Row1) + Assert.Equal(R1, AScaled.Row2) + Assert.Equal(R1, AScaled.Row3) + + [] + let ``Static method matrix multiplication by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let R1 = Vector4(a, b, c, d) * scalar + let R2 = Vector4(e, f, g, h) * scalar + let R3 = Vector4(i, j, k, l) * scalar + let R4 = Vector4(m, n, o, p) * scalar + + let AScaled = Matrix4.Mult(A, scalar) + + Assert.Equal(R1, AScaled.Row0) + Assert.Equal(R1, AScaled.Row1) + Assert.Equal(R1, AScaled.Row2) + Assert.Equal(R1, AScaled.Row3) + + [] + let ``Static method matrix multiplication by reference by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let R1 = Vector4(a, b, c, d) * scalar + let R2 = Vector4(e, f, g, h) * scalar + let R3 = Vector4(i, j, k, l) * scalar + let R4 = Vector4(m, n, o, p) * scalar + + let AScaled = Matrix4.Mult(ref A, scalar) + + Assert.Equal(R1, AScaled.Row0) + Assert.Equal(R1, AScaled.Row1) + Assert.Equal(R1, AScaled.Row2) + Assert.Equal(R1, AScaled.Row3) [ |])>] @@ -299,4 +347,36 @@ module Matrix4 = Assert.Throws(invalidIndexingAccessR) |> ignore Assert.Throws(invalidIndexingAccessC) |> ignore - Assert.Throws(invalidIndexingAccessRC) |> ignore \ No newline at end of file + Assert.Throws(invalidIndexingAccessRC) |> ignore + + [ |])>] + module ``Row and column properties`` = + // + [] + let ``Matrix row properties return the correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) + + let R0 = A.Row0 + let R1 = A.Row1 + let R2 = A.Row2 + let R3 = A.Row3 + + Assert.Equal(a, R0.X) + Assert.Equal(b, R0.Y) + Assert.Equal(c, R0.Z) + Assert.Equal(d, R0.W) + + Assert.Equal(e, R1.X) + Assert.Equal(f, R1.Y) + Assert.Equal(g, R1.Z) + Assert.Equal(h, R1.W) + + Assert.Equal(i, R2.X) + Assert.Equal(j, R2.Y) + Assert.Equal(k, R2.Z) + Assert.Equal(l, R2.W) + + Assert.Equal(m, R3.X) + Assert.Equal(n, R3.Y) + Assert.Equal(o, R3.Z) + Assert.Equal(p, R3.W) \ No newline at end of file From 3c2cda885b80695a65e8149428e3434e94fa2d27 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 16:07:21 +0200 Subject: [PATCH 35/66] Corrected row variables. --- tests/OpenTK.Tests/Matrix4Tests.fs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 9c453b1a..1a0eabc3 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -165,9 +165,9 @@ module Matrix4 = let AScaled = A * scalar Assert.Equal(R1, AScaled.Row0) - Assert.Equal(R1, AScaled.Row1) - Assert.Equal(R1, AScaled.Row2) - Assert.Equal(R1, AScaled.Row3) + Assert.Equal(R2, AScaled.Row1) + Assert.Equal(R3, AScaled.Row2) + Assert.Equal(R4, AScaled.Row3) [] let ``Static method matrix multiplication by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = @@ -181,9 +181,9 @@ module Matrix4 = let AScaled = Matrix4.Mult(A, scalar) Assert.Equal(R1, AScaled.Row0) - Assert.Equal(R1, AScaled.Row1) - Assert.Equal(R1, AScaled.Row2) - Assert.Equal(R1, AScaled.Row3) + Assert.Equal(R2, AScaled.Row1) + Assert.Equal(R3, AScaled.Row2) + Assert.Equal(R4, AScaled.Row3) [] let ``Static method matrix multiplication by reference by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = @@ -197,9 +197,9 @@ module Matrix4 = let AScaled = Matrix4.Mult(ref A, scalar) Assert.Equal(R1, AScaled.Row0) - Assert.Equal(R1, AScaled.Row1) - Assert.Equal(R1, AScaled.Row2) - Assert.Equal(R1, AScaled.Row3) + Assert.Equal(R2, AScaled.Row1) + Assert.Equal(R3, AScaled.Row2) + Assert.Equal(R4, AScaled.Row3) [ |])>] From cae5619c0efb32930ed4081e25453f05376771d9 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 19:53:32 +0200 Subject: [PATCH 36/66] Added Vector4 tests. --- tests/OpenTK.Tests/OpenTK.Tests.fsproj | 1 + tests/OpenTK.Tests/Vector3Tests.fs | 1 + tests/OpenTK.Tests/Vector4Tests.fs | 789 +++++++++++++++++++++++++ 3 files changed, 791 insertions(+) create mode 100644 tests/OpenTK.Tests/Vector4Tests.fs diff --git a/tests/OpenTK.Tests/OpenTK.Tests.fsproj b/tests/OpenTK.Tests/OpenTK.Tests.fsproj index 09bd26c0..d269e1c3 100644 --- a/tests/OpenTK.Tests/OpenTK.Tests.fsproj +++ b/tests/OpenTK.Tests/OpenTK.Tests.fsproj @@ -64,6 +64,7 @@ + diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 8ac1b4ae..87b2dc92 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -206,6 +206,7 @@ module Vector3 = Assert.ApproximatelyEqual(a.X + b.X,c.X) Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) + Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) [] let ``Vector3 addition is commutative`` (a : Vector3, b : Vector3) = diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs new file mode 100644 index 00000000..b0b9c3a5 --- /dev/null +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -0,0 +1,789 @@ +namespace OpenTK.Tests + +open Xunit +open FsCheck +open FsCheck.Xunit +open System +open System.Runtime.InteropServices +open OpenTK + +module Vector4 = + [ |])>] + module Constructors = + // + [] + let ``Triple value constructor sets all components to the correct values`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + + Assert.Equal(x, v.X) + Assert.Equal(y, v.Y) + Assert.Equal(z, v.Z) + Assert.Equal(w, v.W) + + [] + let ``Single value constructor sets all components to the correct values`` (a : float32) = + let v = Vector4(a) + + Assert.Equal(a, v.X) + Assert.Equal(a, v.Y) + Assert.Equal(a, v.Z) + Assert.Equal(a, v.W) + + [] + let ``Vector2 value constructor sets all components to the correct values`` (x, y) = + let v1 = Vector2(x, y) + let v2 = Vector4(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + + Assert.Equal(x, v2.X) + Assert.Equal(y, v2.Y) + Assert.Equal((float32)0, v2.Z) + Assert.Equal((float32)0, v2.W) + + [] + let ``Vector3 value constructor sets all components to the correct values`` (x, y, z) = + let v1 = Vector3(x, y, z) + let v2 = Vector4(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + Assert.Equal(v1.Z, v2.Z) + + Assert.Equal(x, v2.X) + Assert.Equal(y, v2.Y) + Assert.Equal(z, v2.Z) + Assert.Equal((float32)0, v2.W) + + [] + let ``Vector4 value constructor sets all components to the correct values`` (x, y, z, w) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(v1) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + Assert.Equal(v1.Z, v2.Z) + Assert.Equal(v1.W, v2.W) + + Assert.Equal(x, v2.X) + Assert.Equal(y, v2.Y) + Assert.Equal(z, v2.Z) + Assert.Equal(w, v2.W) + + [ |])>] + module Indexing = + // + [] + let ``Index operator accesses the correct components`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + + Assert.Equal(x, v.[0]) + Assert.Equal(y, v.[1]) + Assert.Equal(z, v.[2]) + Assert.Equal(w, v.[3]) + + [] + let ``Index operator throws exception for negative indices`` (x, y, z, w) = + let mutable v = Vector4(x, y, z, w) + + let invalidIndexingAccess = fun() -> v.[-1] |> ignore + let invalidIndexingAssignment = fun() -> v.[-1] <- x + + Assert.Throws(invalidIndexingAccess) |> ignore + Assert.Throws(invalidIndexingAssignment) |> ignore + + [] + let ``Index operator throws exception for large indices`` (x, y, z, w) = + let mutable v = Vector4(x, y, z, w) + + let invalidIndexingAccess = fun() -> v.[4] |> ignore + let invalidIndexingAssignment = fun() -> v.[4] <- x + + Assert.Throws(invalidIndexingAccess) |> ignore + Assert.Throws(invalidIndexingAssignment) |> ignore + + [ |])>] + module Length = + // + [] + let ``Length method works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let l = System.Math.Sqrt((float)(x * x + y * y + z * z + w * w)) + + Assert.Equal((float32)l, v.Length) + + [] + let ``Fast length method works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let l = 1.0f / MathHelper.InverseSqrtFast(x * x + y * y + z * z + w * w) + + Assert.Equal(l, v.LengthFast) + + [] + let ``Length squared method works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let lsq = x * x + y * y + z * z + w * w + + Assert.Equal(lsq, v.LengthSquared) + + [ |])>] + module Normalization = + // + [] + let ``Normalization of instance, creating a new vector, works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let l = v.Length + + // Dividing by zero is not supported + if not (approxEq l 0.0f) then + let norm = v.Normalized() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) + + [] + let ``Normalization of instance works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let l = v.Length + + if not (approxEq l 0.0f) then + let norm = Vector4(x, y, z, w) + norm.Normalize() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) + + [] + let ``Fast approximate normalization of instance works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let norm = Vector4(x, y, z, w) + norm.NormalizeFast() + + let scale = MathHelper.InverseSqrtFast(x * x + y * y + z * z + w * w) + + Assert.ApproximatelyEqual(v.X * scale, norm.X) + Assert.ApproximatelyEqual(v.Y * scale, norm.Y) + Assert.ApproximatelyEqual(v.Z * scale, norm.Z) + Assert.ApproximatelyEqual(v.W * scale, norm.W) + + [] // TODO: Eliminate coefficient calculation, rounding error + let ``Normalization by reference works`` (a : Vector4) = + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + let vRes = Vector4.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) + + [] // TODO: Eliminate coefficient calculation, rounding error + let ``Normalization works`` (a : Vector4) = + if not (approxEq a.Length 0.0f) then + let scale = 1.0f / a.Length + let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + + Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); + + [] + let ``Fast approximate normalization by reference works`` (a : Vector4) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) + + let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + let vRes = Vector4.NormalizeFast(ref a) + + Assert.ApproximatelyEqual(norm, vRes) + + [] + let ``Fast approximate normalization works`` (a : Vector4) = + let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) + + let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + + Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a)); + + [ |])>] + module Addition = + // + [] + let ``Vector4 addition is the same as component addition`` (a : Vector4, b : Vector4) = + let c = a + b + + Assert.ApproximatelyEqual(a.X + b.X,c.X) + Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) + Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) + Assert.ApproximatelyEqual(a.W + b.W,c.W) + + [] + let ``Vector4 addition is commutative`` (a : Vector4, b : Vector4) = + let c = a + b + let c2 = b + a + + Assert.ApproximatelyEqual(c, c2) + + [] + let ``Vector4 addition is associative`` (a : Vector4, b : Vector4, c : Vector4) = + let r1 = (a + b) + c + let r2 = a + (b + c) + + Assert.ApproximatelyEqual(r1, r2) + + [] + let ``Static Vector4 addition method is the same as component addition`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) + let sum = Vector4.Add(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4 addition method by reference is the same as component addition`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) + let sum = Vector4.Add(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [ |])>] + module Subtraction = + // + [] + let ``Vector4 subtraction is the same as component subtraction`` (a : Vector4, b : Vector4) = + let c = a - b + + Assert.Equal(a.X - b.X,c.X) + Assert.Equal(a.Y - b.Y,c.Y) + Assert.Equal(a.Z - b.Z,c.Z) + Assert.Equal(a.W - b.W,c.W) + + [] + let ``Static Vector4 subtraction method is the same as component addition`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) + let sum = Vector4.Subtract(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4 subtraction method by reference is the same as component addition`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) + let sum = Vector4.Subtract(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [ |])>] + module Multiplication = + // + [] + let ``Vector4 multiplication is the same as component multiplication`` (a : Vector4, b : Vector4) = + let c = a * b + + Assert.Equal(a.X * b.X,c.X) + Assert.Equal(a.Y * b.Y,c.Y) + Assert.Equal(a.Z * b.Z,c.Z) + Assert.Equal(a.W * b.W,c.W) + + + [] + let ``Vector4 multiplication is commutative`` (a : Vector4, b : Vector4) = + let r1 = a * b + let r2 = b * a + + Assert.Equal(r1, r2) + + [] + let ``Left-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let r = a * f + + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) + Assert.Equal(a.W * f,r.W) + + [] + let ``Right-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let r = f * a + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) + Assert.Equal(a.W * f,r.W) + + [] + let ``Static method Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let r = Vector4.Multiply(a, f) + + Assert.Equal(a.X * f,r.X) + Assert.Equal(a.Y * f,r.Y) + Assert.Equal(a.Z * f,r.Z) + Assert.Equal(a.W * f,r.W) + + [] + let ``Vector4-Matrix4 multiplication works for right-handed notation`` (a : Matrix4, b : Vector4) = + let res = a*b + + let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 + b.W * a.M14 + let c2 = b.X * a.M21 + b.Y * a.M22 + b.Z * a.M23 + b.W * a.M24 + let c3 = b.X * a.M31 + b.Y * a.M32 + b.Z * a.M33 + b.W * a.M34 + let c4 = b.X * a.M41 + b.Y * a.M42 + b.Z * a.M43 + b.W * a.M44 + + let exp = Vector4(c1, c2, c3, c4) + + Assert.Equal(exp, res) + + [] + let ``Vector4-Matrix4 multiplication works for left-handed notation`` (a : Matrix4, b : Vector4) = + let res = b*a + + let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 + b.W * a.M41 + let c2 = b.X * a.M12 + b.Y * a.M22 + b.Z * a.M32 + b.W * a.M42 + let c3 = b.X * a.M13 + b.Y * a.M23 + b.Z * a.M33 + b.W * a.M43 + let c4 = b.X * a.M14 + b.Y * a.M24 + b.Z * a.M34 + b.W * a.M44 + + let exp = Vector4(c1, c2, c3, c4) + + Assert.Equal(exp, res) + + [] + let ``Static Vector4 multiplication method is the same as component multiplication`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) + let sum = Vector4.Multiply(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4 multiplication method by reference is the same as component multiplication`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) + let sum = Vector4.Multiply(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [ |])>] + module Division = + // + [] + let ``Vector4-float division is the same as component-float division`` (a : Vector4, f : float32) = + if not (approxEq f 0.0f) then // we don't support diving by zero. + let r = a / f + + Assert.ApproximatelyEqual(a.X / f, r.X) + Assert.ApproximatelyEqual(a.Y / f, r.Y) + Assert.ApproximatelyEqual(a.Z / f, r.Z) + Assert.ApproximatelyEqual(a.W / f, r.W) + + [] + let ``Static Vector4-Vector4 division method works`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) + let sum = Vector4.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4-Vector4 divison method works by reference`` (a : Vector4, b : Vector4) = + + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) + let sum = Vector4.Divide(ref a, ref b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4-scalar division method works`` (a : Vector4, b : float32) = + + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) + let sum = Vector4.Divide(a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [] + let ``Static Vector4-scalar divison method works by reference`` (a : Vector4, b : float32) = + + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) + let sum = Vector4.Divide(ref a, b) + + Assert.ApproximatelyEqual(v1, sum) + + [ |])>] + module Negation = + // + [] + let ``Vector negation operator works`` (x, y, z, w) = + let v = Vector4(x, y, z, w) + let vNeg = -v + Assert.Equal(-x, vNeg.X) + Assert.Equal(-y, vNeg.Y) + Assert.Equal(-z, vNeg.Z) + Assert.Equal(-w, vNeg.W) + + [ |])>] + module Equality = + // + [] + let ``Vector equality operator works`` (x, y, z, w) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(x, y, z, w) + let equality = v1 = v2 + + Assert.True(equality) + + [] + let ``Vector inequality operator works`` (x, y, z, w) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(x + (float32)1 , y + (float32)1, z + (float32)1, w + (float32)1) + let inequality = v1 <> v2 + + Assert.True(inequality) + + [] + let ``Vector equality method works`` (x, y, z, w) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(x, y, z, w) + let notVector = Matrix2() + + let equality = v1.Equals(v2) + let inequalityByOtherType = v1.Equals(notVector) + + Assert.True(equality) + Assert.False(inequalityByOtherType) + + [ |])>] + module Swizzling = + // + [] + let ``Vector swizzling works for X-primary components`` (x, y, z, w) = + + let v = Vector4(x, y, z, w) + + let xyzw = v + let xywz = Vector4(x, y, w, z) + let xzyw = Vector4(x, z, y, w) + let xzwy = Vector4(x, z, w, y) + let xwyz = Vector4(x, w, y, z) + let xwzy = Vector4(x, w, z, y) + + let xyz = Vector3(x, y, z) + let xyw = Vector3(x, y, w) + let xzy = Vector3(x, z, y) + let xzw = Vector3(x, z, w) + let xwy = Vector3(x, w, y) + let xwz = Vector3(x, w, z) + + let xy = Vector2(x, y) + let xz = Vector2(x, z) + let xw = Vector2(x, w) + + // X primary + Assert.Equal(xyzw, v) + Assert.Equal(xywz, v.Xywz) + Assert.Equal(xzyw, v.Xzyw) + Assert.Equal(xzwy, v.Xzwy) + Assert.Equal(xwyz, v.Xwyz) + Assert.Equal(xwzy, v.Xwzy) + + Assert.Equal(xyz, v.Xyz) + Assert.Equal(xyw, v.Xyw) + Assert.Equal(xzy, v.Xzy) + Assert.Equal(xzw, v.Xzw) + Assert.Equal(xwy, v.Xwy) + Assert.Equal(xwz, v.Xwz) + + Assert.Equal(xy, v.Xy) + Assert.Equal(xz, v.Xz) + Assert.Equal(xw, v.Xw) + + [] + let ``Vector swizzling works for Y-primary components`` (x, y, z, w) = + + let v = Vector4(x, y, z, w) + + let yxzw = Vector4(y, x, z, w) + let yxwz = Vector4(y, x, w, z) + let yyzw = Vector4(y, y, z, w) + let yywz = Vector4(y, y, w, z) + let yzxw = Vector4(y, z, x, w) + let yzwx = Vector4(y, z, w, x) + let ywxz = Vector4(y, w, x, z) + let ywzx = Vector4(y, w, z, x) + + let yxz = Vector3(y, x, z) + let yxw = Vector3(y, x, w) + let yzx = Vector3(y, z, x) + let yzw = Vector3(y, z, w) + let ywx = Vector3(y, w, x) + let ywz = Vector3(y, w, z) + + let yx = Vector2(y, x) + let yz = Vector2(y, z) + let yw = Vector2(y, w) + + // Y primary + Assert.Equal(yxzw, v.Yxzw) + Assert.Equal(yxwz, v.Yxwz) + Assert.Equal(yyzw, v.Yyzw) + Assert.Equal(yywz, v.Yywz) + Assert.Equal(yzxw, v.Yzxw) + Assert.Equal(yzwx, v.Yzwx) + Assert.Equal(ywxz, v.Ywxz) + Assert.Equal(ywzx, v.Ywzx) + + Assert.Equal(yxz, v.Yxz) + Assert.Equal(yxw, v.Yxw) + Assert.Equal(yzx, v.Yzx) + Assert.Equal(yzw, v.Yzw) + Assert.Equal(ywx, v.Ywx) + Assert.Equal(ywz, v.Ywz) + + Assert.Equal(yx, v.Yx) + Assert.Equal(yz, v.Yz) + Assert.Equal(yw, v.Yw) + + [] + let ``Vector swizzling works for Z-primary components`` (x, y, z, w) = + + let v = Vector4(x, y, z, w) + + let zxyw = Vector4(z, x, y, w) + let zxwy = Vector4(z, x, w, y) + let zyxw = Vector4(z, y, x, w) + let zywx = Vector4(z, y, w, x) + let zwxy = Vector4(z, w, x, y) + let zwyx = Vector4(z, w, y, x) + let zwzy = Vector4(z, w, z, y) + + let zxy = Vector3(z, x, y) + let zxw = Vector3(z, x, w) + let zyx = Vector3(z, y, x) + let zyw = Vector3(z, y, w) + let zwx = Vector3(z, w, x) + let zwy = Vector3(z, w, y) + + let zx = Vector2(z, x) + let zy = Vector2(z, y) + let zw = Vector2(z, w) + + // Z primary + Assert.Equal(zxyw, v.Zxyw) + Assert.Equal(zxwy, v.Zxwy) + Assert.Equal(zyxw, v.Zyxw) + Assert.Equal(zywx, v.Zywx) + Assert.Equal(zwxy, v.Zwxy) + Assert.Equal(zwyx, v.Zwyx) + Assert.Equal(zwzy, v.Zwzy) + + Assert.Equal(zxy, v.Zxy) + Assert.Equal(zxw, v.Zxw) + Assert.Equal(zyx, v.Zyx) + Assert.Equal(zyw, v.Zyw) + Assert.Equal(zwx, v.Zwx) + Assert.Equal(zwy, v.Zwy) + + Assert.Equal(zx, v.Zx) + Assert.Equal(zy, v.Zy) + Assert.Equal(zw, v.Zw) + + [] + let ``Vector swizzling works for W-primary components`` (x, y, z, w) = + + let v = Vector4(x, y, z, w) + + let wxyz = Vector4(w, x, y, z) + let wxzy = Vector4(w, x, z, y) + let wyxz = Vector4(w, y, x, z) + let wyzx = Vector4(w, y, z, x) + let wzxy = Vector4(w, z, x, y) + let wzyx = Vector4(w, z, y, x) + let wzyw = Vector4(w, z, y, w) + + let wxy = Vector3(w, x, y) + let wxz = Vector3(w, x, z) + let wyx = Vector3(w, y, x) + let wyz = Vector3(w, y, z) + let wzx = Vector3(w, z, x) + let wzy = Vector3(w, z, y) + + let wx = Vector2(w, x) + let wy = Vector2(w, y) + let wz = Vector2(w, z) + + // W primary + Assert.Equal(wxyz, v.Wxyz) + Assert.Equal(wxzy, v.Wxzy) + Assert.Equal(wyxz, v.Wyxz) + Assert.Equal(wyzx, v.Wyzx) + Assert.Equal(wzxy, v.Wzxy) + Assert.Equal(wzyx, v.Wzyx) + Assert.Equal(wzyw, v.Wzyw) + + Assert.Equal(wxy, v.Wxy) + Assert.Equal(wxz, v.Wxz) + Assert.Equal(wyx, v.Wyx) + Assert.Equal(wyz, v.Wyz) + Assert.Equal(wzx, v.Wzx) + Assert.Equal(wzy, v.Wzy) + + Assert.Equal(wx, v.Wx) + Assert.Equal(wy, v.Wy) + Assert.Equal(wz, v.Wz) + + [ |])>] + module Interpolation = + // + [] + let ``Linear interpolation works`` (a : Vector4, b : Vector4, q) = + + let blend = q + + let rX = blend * (b.X - a.X) + a.X + let rY = blend * (b.Y - a.Y) + a.Y + let rZ = blend * (b.Z - a.Z) + a.Z + let rW = blend * (b.W - a.W) + a.W + let vExp = Vector4(rX, rY, rZ, rW) + + Assert.Equal(vExp, Vector4.Lerp(a, b, q)) + + let vRes = Vector4.Lerp(ref a, ref b, q) + Assert.Equal(vExp, vRes) + + [] + let ``Barycentric interpolation works`` (a : Vector4, b : Vector4, c : Vector4, u, v) = + + let r = a + u * (b - a) + v * (c - a) + + Assert.Equal(r, Vector4.BaryCentric(a, b, c, u, v)) + + let vRes = Vector4.BaryCentric(ref a, ref b, ref c, u, v) + Assert.Equal(r, vRes) + + [ |])>] + module ``Vector products`` = + // + [] + let ``Dot product works`` (a : Vector4, b : Vector4) = + let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W + + Assert.Equal(dot, Vector4.Dot(a, b)); + + let vRes = Vector4.Dot(ref a, ref b) + Assert.Equal(dot, vRes) + + [ |])>] + module ``Component min and max`` = + // + [] + let ``Selecting the lesser of two vectors works`` (x, y, z, w, a, b, c, d) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(a, b, c, d) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.Min(v1, v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanv1 = l2 < l1 + Assert.True(v2ShorterThanv1) + + [] + let ``Selecting the greater of two vectors works`` (x, y, z, w, a, b, c, d) = + let v1 = Vector4(x, y, z, w) + let v2 = Vector4(a, b, c, d) + + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.Max(v1, v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [ |])>] + module Clamping = + // + [] + let ``Clamping one vector between two other vectors works`` (a : Vector4, b : Vector4, w : Vector4) = + let res = Vector4.Clamp(w, a, b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z + let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + Assert.Equal(expZ, res.Z) + Assert.Equal(expW, res.W) + + [] + let ``Clamping one vector between two other vectors works by reference`` (a : Vector4, b : Vector4, w : Vector4) = + let res = Vector4.Clamp(ref w, ref a, ref b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z + let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + Assert.Equal(expZ, res.Z) + Assert.Equal(expW, res.W) + + [ |])>] + module ``Unit vectors``= + // + [] + let ``Unit X is correct`` = + let unitX = Vector4((float32)1, (float32)0, (float32)0, (float32)0) + + Assert.Equal(Vector4.UnitX, unitX) + + [] + let ``Unit Y is correct`` = + let unitY = Vector4((float32)0, (float32)1, (float32)0, (float32)0) + + Assert.Equal(Vector4.UnitY, unitY) + + [] + let ``Unit Z is correct`` = + let unitZ = Vector4((float32)0, (float32)0, (float32)1, (float32)0) + + Assert.Equal(Vector4.UnitZ, unitZ) + + [] + let ``Unit W is correct`` = + let unitW = Vector4((float32)0, (float32)0, (float32)0, (float32)1) + + Assert.Equal(Vector4.UnitW, unitW) + + [] + let ``Unit zero is correct`` = + let unitZero = Vector4((float32)0, (float32)0, (float32)0, (float32)0) + + Assert.Equal(Vector4.Zero, unitZero) + + [] + let ``Unit one is correct`` = + let unitOne = Vector4((float32)1, (float32)1, (float32)1, (float32)1) + + Assert.Equal(Vector4.One, unitOne) + + [ |])>] + module Serialization = + // + [] + let ``The absolute size of a Vector4 is always the size of its components`` (v : Vector4) = + let expectedSize = sizeof * 4 + + Assert.Equal(expectedSize, Vector4.SizeInBytes) + Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) \ No newline at end of file From 8993dffad2e1f34afa56344ecc85f3f86b98c754 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 19:54:05 +0200 Subject: [PATCH 37/66] Set CI report to always run, even if script fails. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c0a6c143..76cae9fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_install: script: - ./build.sh NuGet -after_success: +after_script: - mono --debug --profile=log:coverage,covfilter=+OpenTK,covfilter=-OpenTK.Tests,covfilter=-FSharp.Core,covfilter=-FsCheck,covfilter=-xunit.assert "packages/xunit.runner.console/tools/xunit.console.exe" "tests/OpenTK.Tests/bin/Release/OpenTK.Tests.dll" -parallel none - mprof-report --reports=coverage --coverage-out=coverage.xml output.mlpd - bash <(curl -s https://codecov.io/bash) From 469a8d275fa2e8ce82923467e49cacddc280bea1 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 19:58:25 +0200 Subject: [PATCH 38/66] Fixed use of incorrect components in clamping function. --- src/OpenTK/Math/Vector4.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index a821031e..2d876544 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -774,8 +774,8 @@ namespace OpenTK { vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X; vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y; - vec.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; - vec.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W; + vec.Z = vec.Z < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; + vec.W = vec.W < min.W ? min.W : vec.W > max.W ? max.W : vec.W; return vec; } @@ -790,8 +790,8 @@ namespace OpenTK { result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X; result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y; - result.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; - result.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W; + result.Z = vec.Z < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; + result.W = vec.W < min.W ? min.W : vec.W > max.W ? max.W : vec.W; } #endregion From c7298d878412d2df3cda1d8c9c5d284a2ef0c2c9 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 21:09:10 +0200 Subject: [PATCH 39/66] Improved test naming. --- tests/OpenTK.Tests/Matrix4Tests.fs | 86 +++++++------ tests/OpenTK.Tests/Vector2Tests.fs | 186 ++++++++++++++--------------- tests/OpenTK.Tests/Vector3Tests.fs | 162 +++++++++++++------------ tests/OpenTK.Tests/Vector4Tests.fs | 172 ++++++++++++++------------ 4 files changed, 318 insertions(+), 288 deletions(-) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 1a0eabc3..5a589d64 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -266,7 +266,7 @@ module Matrix4 = module Indexing = // [] - let ``Matrix indexing sets correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let ``Matrix set indexing sets correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let mutable A = Matrix4() A.[0, 0] <- a @@ -308,46 +308,56 @@ module Matrix4 = Assert.Equal(n, A.M42) Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - - [] - let ``Matrix indexing throws on negative indices`` (a) = - let mutable A = Matrix4() - - let invalidIndexingAssignmentR = fun() -> A.[-1, 2] <- a - let invalidIndexingAssignmentC = fun() -> A.[1, -2] <- a - let invalidIndexingAssignmentRC = fun() -> A.[-1, -2] <- a - - let invalidIndexingAccessR = fun() -> A.[-1, 2] |> ignore - let invalidIndexingAccessC = fun() -> A.[1, -2] |> ignore - let invalidIndexingAccessRC = fun() -> A.[-1, -2] |> ignore - - Assert.Throws(invalidIndexingAssignmentR) |> ignore - Assert.Throws(invalidIndexingAssignmentC) |> ignore - Assert.Throws(invalidIndexingAssignmentRC) |> ignore - - Assert.Throws(invalidIndexingAccessR) |> ignore - Assert.Throws(invalidIndexingAccessC) |> ignore - Assert.Throws(invalidIndexingAccessRC) |> ignore [] - let ``Matrix indexing throws on large indices`` (a) = - let mutable A = Matrix4() - - let invalidIndexingAssignmentR = fun() -> A.[5, 2] <- a - let invalidIndexingAssignmentC = fun() -> A.[1, 6] <- a - let invalidIndexingAssignmentRC = fun() -> A.[7, 12] <- a - - let invalidIndexingAccessR = fun() -> A.[5, 2] |> ignore - let invalidIndexingAccessC = fun() -> A.[1, 6] |> ignore - let invalidIndexingAccessRC = fun() -> A.[7, 12] |> ignore - - Assert.Throws(invalidIndexingAssignmentR) |> ignore - Assert.Throws(invalidIndexingAssignmentC) |> ignore - Assert.Throws(invalidIndexingAssignmentRC) |> ignore + let ``Matrix get indexing accesses the correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - Assert.Throws(invalidIndexingAccessR) |> ignore - Assert.Throws(invalidIndexingAccessC) |> ignore - Assert.Throws(invalidIndexingAccessRC) |> ignore + Assert.Equal(a, A.[0, 0]) + Assert.Equal(b, A.[0, 1]) + Assert.Equal(c, A.[0, 2]) + Assert.Equal(d, A.[0, 3]) + + Assert.Equal(e, A.[1, 0]) + Assert.Equal(f, A.[1, 1]) + Assert.Equal(g, A.[1, 2]) + Assert.Equal(h, A.[1, 3]) + + Assert.Equal(i, A.[2, 0]) + Assert.Equal(j, A.[2, 1]) + Assert.Equal(k, A.[2, 2]) + Assert.Equal(l, A.[2, 3]) + + Assert.Equal(m, A.[3, 0]) + Assert.Equal(n, A.[3, 1]) + Assert.Equal(o, A.[3, 2]) + Assert.Equal(p, A.[3, 3]) + + [] + let ``Indexed set operator throws exception for negative indices`` (b : Matrix4, x : float32) = + let mutable a = b + (fun() -> a.[-1, 2] <- x) |> Assert.Throws |> ignore + (fun() -> a.[1, -2] <- x) |> Assert.Throws |> ignore + (fun() -> a.[-1, -2] <- x) |> Assert.Throws |> ignore + + [] + let ``Indexed get operator throws exception for negative indices`` (a : Matrix4) = + (fun() -> a.[-1, 2] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[1, -2] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[-1, -2] |> ignore) |> Assert.Throws |> ignore + + [] + let ``Indexed set operator throws exception for large indices`` (a : Matrix4, x : float32) = + let mutable b = a + (fun() -> b.[5, 2] <- x) |> Assert.Throws |> ignore + (fun() -> b.[1, 6] <- x) |> Assert.Throws |> ignore + (fun() -> b.[7, 12] <- x) |> Assert.Throws |> ignore + + [] + let ``Indexed get operator throws exception for large indices`` (a : Matrix4) = + (fun() -> a.[5, 2] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[1, 6] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[7, 12] |> ignore) |> Assert.Throws |> ignore [ |])>] module ``Row and column properties`` = diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 5cddb743..3a3c3bd6 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -22,14 +22,29 @@ module Vector2 = let v = Vector2(x,y) Assert.Equal(x,v.X) Assert.Equal(y,v.Y) - - //[] - // disabled - behaviour needs discussion - let ``Clamping works for each component`` (a : Vector2,b : Vector2,c : Vector2) = - let inline clamp (value : float32) minV maxV = MathHelper.Clamp(value,minV,maxV) - let r = Vector2.Clamp(a,b,c) - Assert.Equal(clamp a.X b.X c.X,r.X) - Assert.Equal(clamp a.Y b.Y c.Y,r.Y) + + [ |])>] + module Clamping = + // + [] + let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector2, b : Vector2, w : Vector2) = + let res = Vector2.Clamp(w, a, b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) + + [] + let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector2, b : Vector2, w : Vector2) = + let res = Vector2.Clamp(ref w, ref a, ref b) + + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X + let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y + + Assert.Equal(expX, res.X) + Assert.Equal(expY, res.Y) [ |])>] module Length = @@ -81,28 +96,35 @@ module Vector2 = module Indexing = // [] - let ``Index operators work for the correct components`` (x,y) = - let v = Vector2(x,y) - Assert.Equal(v.[0],v.X) - Assert.Equal(v.[1],v.Y) + let ``Index operator accesses the correct components`` (x, y) = + let v = Vector2(x, y) + + Assert.Equal(x, v.[0]) + Assert.Equal(y, v.[1]) [] - let ``Vector indexing throws index out of range exception correctly`` (x, y) = + let ``Indexed set operator throws exception for negative indices`` (x, y) = let mutable v = Vector2(x, y) - let invalidIndexingAccess = fun() -> v.[2] |> ignore - Assert.Throws(invalidIndexingAccess) |> ignore - - let invalidIndexingAssignment = (fun() -> v.[2] <- x) - Assert.Throws(invalidIndexingAssignment) |> ignore - + + (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + [] - let ``Component assignment by indexing works`` (x, y) = - let mutable v = Vector2() - v.[0] <- x - v.[1] <- y - Assert.Equal(x, v.X) - Assert.Equal(y, v.Y) - + let ``Indexed get operator throws exception for negative indices`` (x, y) = + let mutable v = Vector2(x, y) + + (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + + [] + let ``Indexed set operator throws exception for large indices`` (x, y) = + let mutable v = Vector2(x, y) + + (fun() -> v.[2] <- x) |> Assert.Throws |> ignore + + [] + let ``Indexed get operator throws exception for large indices`` (x, y) = + let mutable v = Vector2(x, y) + + (fun() -> v.[2] |> ignore) |> Assert.Throws |> ignore [ |])>] module ``Simple Properties`` = @@ -235,14 +257,13 @@ module Vector2 = // [] let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = - if not (approxEq f 0.0f) then // we don't support diving by zero. - let r = a / f - - Assert.ApproximatelyEqual(a.X / f,r.X) - Assert.ApproximatelyEqual(a.Y / f,r.Y) + let r = a / f + + Assert.ApproximatelyEqual(a.X / f,r.X) + Assert.ApproximatelyEqual(a.Y / f,r.Y) [] - let ``Static Vector2-Vector2 division method works`` (a : Vector2, b : Vector2) = + let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) = let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(a, b) @@ -250,7 +271,7 @@ module Vector2 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector2-Vector2 divison method works by reference`` (a : Vector2, b : Vector2) = + let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) = let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(ref a, ref b) @@ -258,7 +279,7 @@ module Vector2 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector2-scalar division method works`` (a : Vector2, b : float32) = + let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) = let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(a, b) @@ -266,7 +287,7 @@ module Vector2 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector2-scalar divison method works by reference`` (a : Vector2, b : float32) = + let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) = let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(ref a, b) @@ -277,7 +298,7 @@ module Vector2 = module Negation = // [] - let ``Vector negation operator works`` (x, y) = + let ``Vector negation operator negates all components`` (x, y) = let v = Vector2(x, y) let vNeg = -v Assert.Equal(-x, vNeg.X) @@ -287,7 +308,7 @@ module Vector2 = module Equality = // [] - let ``Vector equality operator works`` (x, y) = + let ``Vector equality operator is by component`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(x, y) let equality = v1 = v2 @@ -295,7 +316,7 @@ module Vector2 = Assert.True(equality) [] - let ``Vector inequality operator works`` (x, y) = + let ``Vector inequality operator is by component`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(x + (float32)1 , y + (float32)1) let inequality = v1 <> v2 @@ -303,7 +324,7 @@ module Vector2 = Assert.True(inequality) [] - let ``Vector equality method works`` (x, y) = + let ``Vector equality method is by component`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(x, y) let notVector = Matrix2() @@ -318,7 +339,7 @@ module Vector2 = module Swizzling = // [] - let ``Vector swizzling works`` (x, y) = + let ``Vector swizzling returns the correct composites`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(y, x) @@ -329,7 +350,7 @@ module Vector2 = module Interpolation = // [] - let ``Linear interpolation works`` (a : Vector2, b : Vector2, q) = + let ``Linear interpolation is by component`` (a : Vector2, b : Vector2, q) = let blend = q @@ -343,7 +364,7 @@ module Vector2 = Assert.Equal(vExp, vRes) [] - let ``Barycentric interpolation works`` (a : Vector2, b : Vector2, c : Vector2, u, v) = + let ``Barycentric interpolation follows the barycentric formula`` (a : Vector2, b : Vector2, c : Vector2, u, v) = let r = a + u * (b - a) + v * (c - a) @@ -356,7 +377,7 @@ module Vector2 = module ``Vector products`` = // [] - let ``Dot product works`` (a : Vector2, b : Vector2) = + let ``Dot product follows the dot product formula`` (a : Vector2, b : Vector2) = let dot = a.X * b.X + a.Y * b.Y Assert.Equal(dot, Vector2.Dot(a, b)); @@ -365,19 +386,19 @@ module Vector2 = Assert.Equal(dot, vRes) [] - let ``Perpendicular dot product works`` (a : Vector2, b : Vector2) = - let dot = a.X * b.Y - a.Y * b.X + let ``Perpendicular dot product follows the perpendicular dot product formula`` (a : Vector2, b : Vector2) = + let perpDot = a.X * b.Y - a.Y * b.X - Assert.Equal(dot, Vector2.PerpDot(a, b)); + Assert.Equal(perpDot, Vector2.PerpDot(a, b)); let vRes = Vector2.PerpDot(ref a, ref b) - Assert.Equal(dot, vRes) + Assert.Equal(perpDot, vRes) [ |])>] module Normalization = // [] - let ``Normalization of instance, creating a new vector, works`` (a, b) = + let ``Normalization creates a new unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let l = v.Length @@ -389,7 +410,7 @@ module Vector2 = Assert.ApproximatelyEqual(v.Y / l, norm.Y) [] - let ``Normalization of instance works`` (a, b) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let l = v.Length @@ -401,7 +422,7 @@ module Vector2 = Assert.ApproximatelyEqual(v.Y / l, norm.Y) [] - let ``Fast approximate normalization of instance works`` (a, b) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let norm = Vector2(a, b) norm.NormalizeFast() @@ -412,36 +433,32 @@ module Vector2 = Assert.ApproximatelyEqual(v.Y * scale, norm.Y) [] - let ``Normalization by reference works`` (a : Vector2) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector2(a.X * scale, a.Y * scale) - let vRes = Vector2.Normalize(ref a) - - Assert.ApproximatelyEqual(norm, vRes) + let ``Normalization by reference is the same as division by magnitude`` (a : Vector2) = + let norm = a / a.Length + let vRes = Vector2.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) [] - let ``Normalization works`` (a : Vector2) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector2(a.X * scale, a.Y * scale) - - Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); + let ``Normalization is the same as division by magnitude`` (a : Vector2) = + let norm = a / a.Length + + Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); [] - let ``Fast approximate normalization by reference works`` (a : Vector2) = + let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) - let norm = Vector2(a.X * scale, a.Y * scale) + let norm = a * scale let vRes = Vector2.NormalizeFast(ref a) Assert.ApproximatelyEqual(norm, vRes) [] - let ``Fast approximate normalization works`` (a : Vector2) = + let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) - let norm = Vector2(a.X * scale, a.Y * scale) + let norm = a * scale Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); @@ -449,7 +466,7 @@ module Vector2 = module ``Component min and max`` = // [] - let ``Producing a new vector from the smallest components of given vectors works`` (x, y, u, w) = + let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -462,7 +479,7 @@ module Vector2 = Assert.True(vMin.Y <= v2.Y) [] - let ``Producing a new vector from the largest components of given vectors works`` (x, y, u, w) = + let ``ComponentMax produces a new vector from the largest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -475,7 +492,7 @@ module Vector2 = Assert.True(vMax.Y >= v2.Y) [] - let ``Producing a new vector from the smallest components of given vectors by reference works`` (x, y, u, w) = + let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -488,7 +505,7 @@ module Vector2 = Assert.True(vMin.Y <= v2.Y) [] - let ``Producing a new vector from the largest components of given vectors by reference works`` (x, y, u, w) = + let ``ComponentMax by reference produces a new vector from the largest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -501,7 +518,7 @@ module Vector2 = Assert.True(vMax.Y >= v2.Y) [] - let ``Selecting the lesser of two vectors works`` (x, y, u, w) = + let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -518,7 +535,7 @@ module Vector2 = Assert.True(equalsLast) [] - let ``Selecting the greater of two vectors works`` (x, y, u, w) = + let ``Max selects the vector with greater magnitude given two vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) @@ -533,29 +550,6 @@ module Vector2 = else let equalsLast = vMin = v2 Assert.True(equalsLast) - - [ |])>] - module Clamping = - // - [] - let ``Clamping one vector between two other vectors works`` (a : Vector2, b : Vector2, w : Vector2) = - let res = Vector2.Clamp(w, a, b) - - let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X - let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y - - Assert.Equal(expX, res.X) - Assert.Equal(expY, res.Y) - - [] - let ``Clamping one vector between two other vectors works by reference`` (a : Vector2, b : Vector2, w : Vector2) = - let res = Vector2.Clamp(ref w, ref a, ref b) - - let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X - let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y - - Assert.Equal(expX, res.X) - Assert.Equal(expY, res.Y) [ |])>] module Transformation = diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 87b2dc92..81edaa24 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -69,52 +69,56 @@ module Vector3 = module Indexing = // [] - let ``Index operator accesses the correct components`` (a, b, c) = - let v = Vector3(a, b, c) + let ``Index operator accesses the correct components`` (x, y, z) = + let v = Vector3(x, y, z) - Assert.Equal(a, v.[0]) - Assert.Equal(b, v.[1]) - Assert.Equal(c, v.[2]) + Assert.Equal(x, v.[0]) + Assert.Equal(y, v.[1]) + Assert.Equal(z, v.[2]) [] - let ``Index operator throws exception for negative indices`` (a, b, c) = - let mutable v = Vector3(a, b, c) - - let invalidIndexingAccess = fun() -> v.[-1] |> ignore - let invalidIndexingAssignment = fun() -> v.[-1] <- a + let ``Indexed set operator throws exception for negative indices`` (x, y, z) = + let mutable v = Vector3(x, y, z) - Assert.Throws(invalidIndexingAccess) |> ignore - Assert.Throws(invalidIndexingAssignment) |> ignore + (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + + [] + let ``Indexed get operator throws exception for negative indices`` (x, y, z) = + let mutable v = Vector3(x, y, z) + + (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + + [] + let ``Indexed set operator throws exception for large indices`` (x, y, z) = + let mutable v = Vector3(x, y, z) + + (fun() -> v.[4] <- x) |> Assert.Throws |> ignore [] - let ``Index operator throws exception for large indices`` (a, b, c) = - let mutable v = Vector3(a, b, c) + let ``Indexed get operator throws exception for large indices`` (x, y, z) = + let mutable v = Vector3(x, y, z) - let invalidIndexingAccess = fun() -> v.[3] |> ignore - let invalidIndexingAssignment = fun() -> v.[3] <- a - - Assert.Throws(invalidIndexingAccess) |> ignore - Assert.Throws(invalidIndexingAssignment) |> ignore + (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore [ |])>] module Length = // [] - let ``Length method works`` (a, b, c) = + let ``Length method follows the pythagorean theorem`` (a, b, c) = let v = Vector3(a, b, c) let l = System.Math.Sqrt((float)(a * a + b * b + c * c)) Assert.Equal((float32)l, v.Length) [] - let ``Fast length method works`` (a, b, c) = + let ``Fast length method is the same as one divided by the fast inverse square`` (a, b, c) = let v = Vector3(a, b, c) let l = 1.0f / MathHelper.InverseSqrtFast(a * a + b * b + c * c) Assert.Equal(l, v.LengthFast) [] - let ``Length squared method works`` (a, b, c) = + let ``Length squared method returns each component squared and summed`` (a, b, c) = let v = Vector3(a, b, c) let lsq = a * a + b * b + c * c @@ -124,7 +128,7 @@ module Vector3 = module Normalization = // [] - let ``Normalization of instance, creating a new vector, works`` (a, b, c) = + let ``Normalization creates a new unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let l = v.Length @@ -137,22 +141,20 @@ module Vector3 = Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] - let ``Normalization of instance works`` (a, b, c) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let l = v.Length if not (approxEq l 0.0f) then let norm = Vector3(a, b, c) norm.Normalize() - - - + Assert.ApproximatelyEqual(v.X / l, norm.X) Assert.ApproximatelyEqual(v.Y / l, norm.Y) Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] - let ``Fast approximate normalization of instance works`` (a, b, c) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let norm = Vector3(a, b, c) norm.NormalizeFast() @@ -164,36 +166,32 @@ module Vector3 = Assert.ApproximatelyEqual(v.Z * scale, norm.Z) [] - let ``Normalization by reference works`` (a : Vector3) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) - let vRes = Vector3.Normalize(ref a) - - Assert.ApproximatelyEqual(norm, vRes) + let ``Normalization by reference is the same as division by magnitude`` (a : Vector3) = + let norm = a / a.Length + let vRes = Vector3.Normalize(ref a) + + Assert.ApproximatelyEqual(norm, vRes) [] - let ``Normalization works`` (a : Vector3) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) - - Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + let ``Normalization is the same as division by magnitude`` (a : Vector3) = + let norm = a / a.Length + + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); [] - let ``Fast approximate normalization by reference works`` (a : Vector3) = + let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector3) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + let norm = a * scale let vRes = Vector3.NormalizeFast(ref a) Assert.ApproximatelyEqual(norm, vRes) [] - let ``Fast approximate normalization works`` (a : Vector3) = + let ``Fast approximate normalization is the same as multiplication by fast inverse square`` (a : Vector3) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) - let norm = Vector3(a.X * scale, a.Y * scale, a.Z * scale) + let norm = a * scale Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a)); @@ -307,7 +305,7 @@ module Vector3 = Assert.Equal(a.Z * f,r.Z) [] - let ``Vector3-Matrix3 multiplication works for right-handed notation`` (a : Matrix3, b : Vector3) = + let ``Vector3-Matrix3 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix3, b : Vector3) = let res = a*b let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 @@ -319,7 +317,7 @@ module Vector3 = Assert.Equal(exp, res) [] - let ``Vector3-Matrix3 multiplication works for left-handed notation`` (a : Matrix3, b : Vector3) = + let ``Vector3-Matrix3 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix3, b : Vector3) = let res = b*a let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 @@ -359,7 +357,7 @@ module Vector3 = Assert.ApproximatelyEqual(a.Z / f,r.Z) [] - let ``Static Vector3-Vector3 division method works`` (a : Vector3, b : Vector3) = + let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(a, b) @@ -367,7 +365,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3-Vector3 divison method works by reference`` (a : Vector3, b : Vector3) = + let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) = let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(ref a, ref b) @@ -375,7 +373,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3-scalar division method works`` (a : Vector3, b : float32) = + let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) = let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(a, b) @@ -383,7 +381,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector3-scalar divison method works by reference`` (a : Vector3, b : float32) = + let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) = let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(ref a, b) @@ -394,7 +392,7 @@ module Vector3 = module Negation = // [] - let ``Vector negation operator works`` (x, y, z) = + let ``Vector negation operator negates all components`` (x, y, z) = let v = Vector3(x, y, z) let vNeg = -v Assert.Equal(-x, vNeg.X) @@ -405,7 +403,7 @@ module Vector3 = module Equality = // [] - let ``Vector equality operator works`` (x, y, z) = + let ``Vector equality operator is by component`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector3(x, y, z) let equality = v1 = v2 @@ -413,7 +411,7 @@ module Vector3 = Assert.True(equality) [] - let ``Vector inequality operator works`` (x, y, z) = + let ``Vector inequality operator is by component`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector3(x + (float32)1 , y + (float32)1, z + (float32)1) let inequality = v1 <> v2 @@ -421,7 +419,7 @@ module Vector3 = Assert.True(inequality) [] - let ``Vector equality method works`` (x, y, z) = + let ``Vector equality method is by component`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector3(x, y, z) let notVector = Matrix2() @@ -436,7 +434,7 @@ module Vector3 = module Swizzling = // [] - let ``Vector swizzling works`` (x, y, z) = + let ``Vector swizzling returns the correct composite for X-primary components`` (x, y, z) = let v = Vector3(x, y, z) let xyz = Vector3(x, y, z) @@ -444,26 +442,34 @@ module Vector3 = let xy = Vector2(x, y) let xz = Vector2(x, z) - let yxz = Vector3(y, x, z) - let yzx = Vector3(y, z, x) - let yx = Vector2(y, x) - let yz = Vector2(y, z) - - let zxy = Vector3(z, x, y) - let zyx = Vector3(z, y, x) - let zx = Vector2(z, x) - let zy = Vector2(z, y) - Assert.Equal(xyz, v); Assert.Equal(xzy, v.Xzy); Assert.Equal(xy, v.Xy); Assert.Equal(xz, v.Xz); + [] + let ``Vector swizzling returns the correct composite for Y-primary components`` (x, y, z) = + let v = Vector3(x, y, z) + + let yxz = Vector3(y, x, z) + let yzx = Vector3(y, z, x) + let yx = Vector2(y, x) + let yz = Vector2(y, z) + Assert.Equal(yxz, v.Yxz); Assert.Equal(yzx, v.Yzx); Assert.Equal(yx, v.Yx); Assert.Equal(yz, v.Yz); + [] + let ``Vector swizzling returns the correct composite for Z-primary components`` (x, y, z) = + let v = Vector3(x, y, z) + + let zxy = Vector3(z, x, y) + let zyx = Vector3(z, y, x) + let zx = Vector2(z, x) + let zy = Vector2(z, y); + Assert.Equal(zxy, v.Zxy); Assert.Equal(zyx, v.Zyx); Assert.Equal(zx, v.Zx); @@ -473,7 +479,7 @@ module Vector3 = module Interpolation = // [] - let ``Linear interpolation works`` (a : Vector3, b : Vector3, q) = + let ``Linear interpolation is by component`` (a : Vector3, b : Vector3, q) = let blend = q @@ -488,7 +494,7 @@ module Vector3 = Assert.Equal(vExp, vRes) [] - let ``Barycentric interpolation works`` (a : Vector3, b : Vector3, c : Vector3, u, v) = + let ``Barycentric interpolation follows the barycentric formula`` (a : Vector3, b : Vector3, c : Vector3, u, v) = let r = a + u * (b - a) + v * (c - a) @@ -501,7 +507,7 @@ module Vector3 = module ``Vector products`` = // [] - let ``Dot product works`` (a : Vector3, b : Vector3) = + let ``Dot product follows the dot product formula`` (a : Vector3, b : Vector3) = let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z Assert.Equal(dot, Vector3.Dot(a, b)); @@ -510,7 +516,7 @@ module Vector3 = Assert.Equal(dot, vRes) [] - let ``Cross product works`` (a : Vector3, b : Vector3) = + let ``Cross product follows the cross product formula`` (a : Vector3, b : Vector3) = let crossX = a.Y * b.Z - a.Z * b.Y let crossY = a.Z * b.X - a.X * b.Z let crossZ = a.X * b.Y - a.Y * b.X @@ -525,7 +531,7 @@ module Vector3 = module ``Component min and max`` = // [] - let ``Producing a new vector from the smallest components of given vectors works`` (x, y, z, u, w, q) = + let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -541,7 +547,7 @@ module Vector3 = Assert.True(vMin.Z <= v2.Z) [] - let ``Producing a new vector from the largest components of given vectors works`` (x, y, z, u, w, q) = + let ``ComponentMax producing a new vector from the largest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -557,7 +563,7 @@ module Vector3 = Assert.True(vMax.Z >= v2.Z) [] - let ``Producing a new vector from the smallest components of given vectors by reference works`` (x, y, z, u, w, q) = + let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -573,7 +579,7 @@ module Vector3 = Assert.True(vMin.Z <= v2.Z) [] - let ``Producing a new vector from the largest components of given vectors by reference works`` (x, y, z, u, w, q) = + let ``ComponentMax produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -589,7 +595,7 @@ module Vector3 = Assert.True(vMax.Z >= v2.Z) [] - let ``Selecting the lesser of two vectors works`` (x, y, z, u, w, q) = + let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -606,7 +612,7 @@ module Vector3 = Assert.True(equalsLast) [] - let ``Selecting the greater of two vectors works`` (x, y, z, u, w, q) = + let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) @@ -626,7 +632,7 @@ module Vector3 = module Clamping = // [] - let ``Clamping one vector between two other vectors works`` (a : Vector3, b : Vector3, w : Vector3) = + let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector3, b : Vector3, w : Vector3) = let res = Vector3.Clamp(w, a, b) let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X @@ -638,7 +644,7 @@ module Vector3 = Assert.Equal(expZ, res.Z) [] - let ``Clamping one vector between two other vectors works by reference`` (a : Vector3, b : Vector3, w : Vector3) = + let ``Clamping one vector between two other vectors by reference clamps all components between corresponding components`` (a : Vector3, b : Vector3, w : Vector3) = let res = Vector3.Clamp(ref w, ref a, ref b) let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index b0b9c3a5..877e1744 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -56,6 +56,20 @@ module Vector4 = Assert.Equal(z, v2.Z) Assert.Equal((float32)0, v2.W) + [] + let ``Vector3 value and scalar constructor sets all components to the correct values`` (x, y, z, w) = + let v1 = Vector3(x, y, z) + let v2 = Vector4(v1, w) + + Assert.Equal(v1.X, v2.X) + Assert.Equal(v1.Y, v2.Y) + Assert.Equal(v1.Z, v2.Z) + + Assert.Equal(x, v2.X) + Assert.Equal(y, v2.Y) + Assert.Equal(z, v2.Z) + Assert.Equal(w, v2.W) + [] let ``Vector4 value constructor sets all components to the correct values`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) @@ -84,44 +98,48 @@ module Vector4 = Assert.Equal(w, v.[3]) [] - let ``Index operator throws exception for negative indices`` (x, y, z, w) = + let ``Indexed set operator throws exception for negative indices`` (x, y, z, w) = + let mutable v = Vector4(x, y, z, w) + + (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + + [] + let ``Indexed get operator throws exception for negative indices`` (x, y, z, w) = + let mutable v = Vector4(x, y, z, w) + + (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + + [] + let ``Indexed set operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - let invalidIndexingAccess = fun() -> v.[-1] |> ignore - let invalidIndexingAssignment = fun() -> v.[-1] <- x - - Assert.Throws(invalidIndexingAccess) |> ignore - Assert.Throws(invalidIndexingAssignment) |> ignore + (fun() -> v.[4] <- x) |> Assert.Throws |> ignore [] - let ``Index operator throws exception for large indices`` (x, y, z, w) = + let ``Indexed get operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - let invalidIndexingAccess = fun() -> v.[4] |> ignore - let invalidIndexingAssignment = fun() -> v.[4] <- x - - Assert.Throws(invalidIndexingAccess) |> ignore - Assert.Throws(invalidIndexingAssignment) |> ignore + (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore [ |])>] module Length = // [] - let ``Length method works`` (x, y, z, w) = + let ``Length method follows the pythagorean theorem`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = System.Math.Sqrt((float)(x * x + y * y + z * z + w * w)) Assert.Equal((float32)l, v.Length) [] - let ``Fast length method works`` (x, y, z, w) = + let ``Fast length method is the same as one divided by the fast inverse square`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = 1.0f / MathHelper.InverseSqrtFast(x * x + y * y + z * z + w * w) Assert.Equal(l, v.LengthFast) [] - let ``Length squared method works`` (x, y, z, w) = + let ``Length squared method returns each component squared and summed`` (x, y, z, w) = let v = Vector4(x, y, z, w) let lsq = x * x + y * y + z * z + w * w @@ -131,35 +149,32 @@ module Vector4 = module Normalization = // [] - let ``Normalization of instance, creating a new vector, works`` (x, y, z, w) = + let ``Normalization creates a new unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = v.Length - - // Dividing by zero is not supported - if not (approxEq l 0.0f) then - let norm = v.Normalized() - - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + + let norm = v.Normalized() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) [] - let ``Normalization of instance works`` (x, y, z, w) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = v.Length - - if not (approxEq l 0.0f) then - let norm = Vector4(x, y, z, w) - norm.Normalize() - - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + + let norm = Vector4(x, y, z, w) + norm.Normalize() + + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) [] - let ``Fast approximate normalization of instance works`` (x, y, z, w) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let norm = Vector4(x, y, z, w) norm.NormalizeFast() @@ -171,37 +186,33 @@ module Vector4 = Assert.ApproximatelyEqual(v.Z * scale, norm.Z) Assert.ApproximatelyEqual(v.W * scale, norm.W) - [] // TODO: Eliminate coefficient calculation, rounding error - let ``Normalization by reference works`` (a : Vector4) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) - let vRes = Vector4.Normalize(ref a) - - Assert.ApproximatelyEqual(norm, vRes) + [] + let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) = + let norm = a / a.Length + let vRes = Vector4.Normalize(ref a) - [] // TODO: Eliminate coefficient calculation, rounding error - let ``Normalization works`` (a : Vector4) = - if not (approxEq a.Length 0.0f) then - let scale = 1.0f / a.Length - let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) - - Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); + Assert.ApproximatelyEqual(norm, vRes) [] - let ``Fast approximate normalization by reference works`` (a : Vector4) = + let ``Normalization is the same as division by magnitude`` (a : Vector4) = + let norm = a / a.Length + + Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); + + [] + let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) - let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + let norm = a * scale let vRes = Vector4.NormalizeFast(ref a) Assert.ApproximatelyEqual(norm, vRes) [] - let ``Fast approximate normalization works`` (a : Vector4) = + let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) - let norm = Vector4(a.X * scale, a.Y * scale, a.Z * scale, a.W * scale) + let norm = a * scale Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a)); @@ -322,7 +333,7 @@ module Vector4 = Assert.Equal(a.W * f,r.W) [] - let ``Vector4-Matrix4 multiplication works for right-handed notation`` (a : Matrix4, b : Vector4) = + let ``Vector4-Matrix4 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix4, b : Vector4) = let res = a*b let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 + b.W * a.M14 @@ -335,7 +346,7 @@ module Vector4 = Assert.Equal(exp, res) [] - let ``Vector4-Matrix4 multiplication works for left-handed notation`` (a : Matrix4, b : Vector4) = + let ``Vector4-Matrix4 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix4, b : Vector4) = let res = b*a let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 + b.W * a.M41 @@ -377,7 +388,7 @@ module Vector4 = Assert.ApproximatelyEqual(a.W / f, r.W) [] - let ``Static Vector4-Vector4 division method works`` (a : Vector4, b : Vector4) = + let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) = let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(a, b) @@ -385,7 +396,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector4-Vector4 divison method works by reference`` (a : Vector4, b : Vector4) = + let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) = let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(ref a, ref b) @@ -393,7 +404,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector4-scalar division method works`` (a : Vector4, b : float32) = + let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) = let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(a, b) @@ -401,7 +412,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) [] - let ``Static Vector4-scalar divison method works by reference`` (a : Vector4, b : float32) = + let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) = let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(ref a, b) @@ -412,7 +423,7 @@ module Vector4 = module Negation = // [] - let ``Vector negation operator works`` (x, y, z, w) = + let ``Vector negation operator negates all components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let vNeg = -v Assert.Equal(-x, vNeg.X) @@ -424,7 +435,7 @@ module Vector4 = module Equality = // [] - let ``Vector equality operator works`` (x, y, z, w) = + let ``Vector equality operator is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x, y, z, w) let equality = v1 = v2 @@ -432,7 +443,7 @@ module Vector4 = Assert.True(equality) [] - let ``Vector inequality operator works`` (x, y, z, w) = + let ``Vector inequality operator is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x + (float32)1 , y + (float32)1, z + (float32)1, w + (float32)1) let inequality = v1 <> v2 @@ -440,7 +451,7 @@ module Vector4 = Assert.True(inequality) [] - let ``Vector equality method works`` (x, y, z, w) = + let ``Vector equality method is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x, y, z, w) let notVector = Matrix2() @@ -451,11 +462,20 @@ module Vector4 = Assert.True(equality) Assert.False(inequalityByOtherType) + [] + let ``Vector equality method returns false for other classes`` (x, y, z, w) = + let v1 = Vector4(x, y, z, w) + let notVector = Matrix2() + + let inequalityByOtherType = v1.Equals(notVector) + + Assert.False(inequalityByOtherType) + [ |])>] module Swizzling = // [] - let ``Vector swizzling works for X-primary components`` (x, y, z, w) = + let ``Vector swizzling returns the correct composite for X-primary components`` (x, y, z, w) = let v = Vector4(x, y, z, w) @@ -497,7 +517,7 @@ module Vector4 = Assert.Equal(xw, v.Xw) [] - let ``Vector swizzling works for Y-primary components`` (x, y, z, w) = + let ``Vector swizzling returns the correct composite for Y-primary components`` (x, y, z, w) = let v = Vector4(x, y, z, w) @@ -543,7 +563,7 @@ module Vector4 = Assert.Equal(yw, v.Yw) [] - let ``Vector swizzling works for Z-primary components`` (x, y, z, w) = + let ``Vector swizzling returns the correct composite for Z-primary components`` (x, y, z, w) = let v = Vector4(x, y, z, w) @@ -587,7 +607,7 @@ module Vector4 = Assert.Equal(zw, v.Zw) [] - let ``Vector swizzling works for W-primary components`` (x, y, z, w) = + let ``Vector swizzling returns the correct composite for W-primary components`` (x, y, z, w) = let v = Vector4(x, y, z, w) @@ -634,7 +654,7 @@ module Vector4 = module Interpolation = // [] - let ``Linear interpolation works`` (a : Vector4, b : Vector4, q) = + let ``Linear interpolation is by component`` (a : Vector4, b : Vector4, q) = let blend = q @@ -650,7 +670,7 @@ module Vector4 = Assert.Equal(vExp, vRes) [] - let ``Barycentric interpolation works`` (a : Vector4, b : Vector4, c : Vector4, u, v) = + let ``Barycentric interpolation follows the barycentric formula`` (a : Vector4, b : Vector4, c : Vector4, u, v) = let r = a + u * (b - a) + v * (c - a) @@ -663,7 +683,7 @@ module Vector4 = module ``Vector products`` = // [] - let ``Dot product works`` (a : Vector4, b : Vector4) = + let ``Dot product method follows the dot product formula`` (a : Vector4, b : Vector4) = let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W Assert.Equal(dot, Vector4.Dot(a, b)); @@ -675,7 +695,7 @@ module Vector4 = module ``Component min and max`` = // [] - let ``Selecting the lesser of two vectors works`` (x, y, z, w, a, b, c, d) = + let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, w, a, b, c, d) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(a, b, c, d) @@ -692,7 +712,7 @@ module Vector4 = Assert.True(v2ShorterThanv1) [] - let ``Selecting the greater of two vectors works`` (x, y, z, w, a, b, c, d) = + let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, w, a, b, c, d) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(a, b, c, d) @@ -712,7 +732,7 @@ module Vector4 = module Clamping = // [] - let ``Clamping one vector between two other vectors works`` (a : Vector4, b : Vector4, w : Vector4) = + let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = let res = Vector4.Clamp(w, a, b) let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X @@ -726,7 +746,7 @@ module Vector4 = Assert.Equal(expW, res.W) [] - let ``Clamping one vector between two other vectors works by reference`` (a : Vector4, b : Vector4, w : Vector4) = + let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector4, b : Vector4, w : Vector4) = let res = Vector4.Clamp(ref w, ref a, ref b) let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X From 7d846c44592f2ddb386c7a0b5b30751dc9d54a66 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 21:12:59 +0200 Subject: [PATCH 40/66] Strip trailing spaces. --- tests/OpenTK.Tests/Assertions.fs | 24 +- tests/OpenTK.Tests/Generators.fs | 36 +- tests/OpenTK.Tests/MathHelperTests.fs | 24 +- tests/OpenTK.Tests/Matrix4Tests.fs | 118 +++---- tests/OpenTK.Tests/Vector2Tests.fs | 396 +++++++++++----------- tests/OpenTK.Tests/Vector3Tests.fs | 452 ++++++++++++------------- tests/OpenTK.Tests/Vector4Tests.fs | 454 +++++++++++++------------- 7 files changed, 752 insertions(+), 752 deletions(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index a322b4cd..8b7a292c 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -7,25 +7,25 @@ open System open OpenTK [] -module private AssertHelpers = +module private AssertHelpers = [] let private BitAccuracy = 6 - + let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) /// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal. [] -type internal Assert = - - static member ApproximatelyEqual(a : Vector2,b : Vector2) = +type internal Assert = + + static member ApproximatelyEqual(a : Vector2,b : Vector2) = if not <| approxEq a.X b.X && approxEq a.Y b.Y then raise <| new Xunit.Sdk.EqualException(a,b) - - static member ApproximatelyEqual(a : Vector3,b : Vector3) = + + static member ApproximatelyEqual(a : Vector3,b : Vector3) = if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z then raise <| new Xunit.Sdk.EqualException(a,b) - - static member ApproximatelyEqual(a : Vector4,b : Vector4) = - if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z && approxEq a.W b.W then + + static member ApproximatelyEqual(a : Vector4,b : Vector4) = + if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z && approxEq a.W b.W then raise <| new Xunit.Sdk.EqualException(a,b) - - static member ApproximatelyEqual(a : float32,b : float32) = + + static member ApproximatelyEqual(a : float32,b : float32) = if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs index a57424f8..e7496c44 100644 --- a/tests/OpenTK.Tests/Generators.fs +++ b/tests/OpenTK.Tests/Generators.fs @@ -7,62 +7,62 @@ open System open OpenTK [] -module private Generators = +module private Generators = let private isValidFloat f = not (Single.IsNaN f || Single.IsInfinity f || Single.IsInfinity (f * f) || f = Single.MinValue || f = Single.MaxValue ) let private isValidDouble d = not (Double.IsNaN d || Double.IsInfinity d || Double.IsInfinity (d * d)|| d = Double.MinValue || d = Double.MaxValue) let singleArb = Arb.Default.Float32() |> Arb.toGen |> Gen.filter isValidFloat let single = singleArb |> Arb.fromGen - - let double = + + let double = Arb.Default.Float() |> Arb.toGen |> Gen.filter isValidDouble |> Arb.fromGen - - let vec2 = + + let vec2 = singleArb |> Gen.two |> Gen.map Vector2 |> Arb.fromGen - - let vec3 = + + let vec3 = singleArb |> Gen.three |> Gen.map Vector3 |> Arb.fromGen - - let vec4 = + + let vec4 = singleArb |> Gen.four |> Gen.map Vector4 |> Arb.fromGen - - let quat = + + let quat = singleArb |> Gen.four |> Gen.map Quaternion |> Arb.fromGen - - let mat2 = + + let mat2 = singleArb |> Gen.four |> Gen.map Matrix2 |> Arb.fromGen - - let mat3 = + + let mat3 = vec3 |> Arb.toGen |> Gen.three |> Gen.map Matrix3 |> Arb.fromGen - - let mat4 = + + let mat4 = vec4 |> Arb.toGen |> Gen.four |> Gen.map Matrix4 |> Arb.fromGen -type OpenTKGen = +type OpenTKGen = static member Single() = single static member float32() = single static member Double() = double diff --git a/tests/OpenTK.Tests/MathHelperTests.fs b/tests/OpenTK.Tests/MathHelperTests.fs index 7c37a25f..e1270176 100644 --- a/tests/OpenTK.Tests/MathHelperTests.fs +++ b/tests/OpenTK.Tests/MathHelperTests.fs @@ -7,48 +7,48 @@ open System open OpenTK [ |])>] -module MathHelper = +module MathHelper = /// This test ensures that approximately equal can never get it 'wrong' about the values. [] - let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) = + let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) = let clamped = max 0 (min bits 24) let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) let areExactlyEqual = a = b let isWrong = areExactlyEqual && not areApproxEqual Assert.False(isWrong) - + [] - let ``ApproximatelyEqual can return true if some values are not exactly equal`` (a : float32,b : float32,bits : int32) = + let ``ApproximatelyEqual can return true if some values are not exactly equal`` (a : float32,b : float32,bits : int32) = let clamped = max 0 (min bits 24) let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) let areExactlyEqual = a = b let isWrong = areExactlyEqual && not areApproxEqual let p = new PropertyAttribute() Assert.False(isWrong) - + [] - let ``ApproximatelyEqual correctly approximates equality``() = + let ``ApproximatelyEqual correctly approximates equality``() = let a = 0.000000001f let b = 0.0000000010000001f Assert.NotEqual(a,b) [ 1..24 ] |> List.iter (fun i -> Assert.True(MathHelper.ApproximatelyEqual(a,b,i))) - + [] - let ``ApproximatelyEqual reports very different values as non-equal even with high bit count``() = + let ``ApproximatelyEqual reports very different values as non-equal even with high bit count``() = let a = 2.0f let b = 1.0f Assert.NotEqual(a,b) Assert.False(MathHelper.ApproximatelyEqual(a,b,10)) - + [] - let ``ApproximatelyEqual works with single zero value``() = + let ``ApproximatelyEqual works with single zero value``() = let a = 1.0f let b = 0.0f Assert.NotEqual(a,b) Assert.False(MathHelper.ApproximatelyEqual(a,b,0)) - + [] - let ``ApproximatelyEqual works with both zero values``() = + let ``ApproximatelyEqual works with both zero values``() = let a = 0.0f let b = 0.0f Assert.Equal(a,b) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 5a589d64..52b5d6b1 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -6,14 +6,14 @@ open FsCheck.Xunit open System open OpenTK -module Matrix4 = +module Matrix4 = [ |])>] - module Constructors = + module Constructors = // [] - let ``Sixteen value constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let ``Sixteen value constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + Assert.Equal(a, A.M11) Assert.Equal(b, A.M12) Assert.Equal(c, A.M13) @@ -33,12 +33,12 @@ module Matrix4 = Assert.Equal(n, A.M42) Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - + [] - let ``Matrix3 partial constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i) = + let ``Matrix3 partial constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i) = let B = Matrix3(a, b, c, d, e, f, g, h, i) let A = Matrix4(B) - + Assert.Equal(a, A.M11) Assert.Equal(b, A.M12) Assert.Equal(c, A.M13) @@ -58,16 +58,16 @@ module Matrix4 = Assert.Equal((float32)0, A.M42) Assert.Equal((float32)0, A.M43) Assert.Equal((float32)1, A.M44) - + [] - let ``Four-vector4 constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = + let ``Four-vector4 constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let v1 = Vector4(a, b, c, d) let v2 = Vector4(e, f, g, h) let v3 = Vector4(i, j, k, l) let v4 = Vector4(m, n, o, p) - + let A = Matrix4(v1, v2, v3, v4) - + Assert.Equal(a, A.M11) Assert.Equal(b, A.M12) Assert.Equal(c, A.M13) @@ -87,52 +87,52 @@ module Matrix4 = Assert.Equal(n, A.M42) Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - + [ |])>] - module Equality = + module Equality = // [] let ``Two matrices with identical values are equal`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let equality = A = B - + Assert.True(equality) - + [] let ``A matrix is not equal to an object which is not a matrix`` (a : Matrix4, b : Vector3) = Assert.False(a.Equals(b)) [ |])>] - module Multiplication = + module Multiplication = // [] let ``Matrix multiplication is done by row/column multiplication and summation`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let R11 = a*a + b*e + c*i + d*m let R12 = a*b + b*f + c*j + d*n let R13 = a*c + b*g + c*k + d*o let R14 = a*d + b*h + c*l + d*p - + let R21 = e*a + f*e + g*i + h*m let R22 = e*b + f*f + g*j + h*n let R23 = e*c + f*g + g*k + h*o let R24 = e*d + f*h + g*l + h*p - + let R31 = i*a + j*e + k*i + l*m let R32 = i*b + j*f + k*j + l*n let R33 = i*c + j*g + k*k + l*o let R34 = i*d + j*h + k*l + l*p - + let R41 = m*a + n*e + o*i + p*m let R42 = m*b + n*f + o*j + p*n let R43 = m*c + n*g + o*k + p*o let R44 = m*d + n*h + o*l + p*p - + let AB = A*B - + Assert.Equal(R11, AB.M11) Assert.Equal(R12, AB.M12) Assert.Equal(R13, AB.M13) @@ -152,66 +152,66 @@ module Matrix4 = Assert.Equal(R42, AB.M42) Assert.Equal(R43, AB.M43) Assert.Equal(R44, AB.M44) - + [] let ``Matrix multiplication by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let R1 = Vector4(a, b, c, d) * scalar let R2 = Vector4(e, f, g, h) * scalar let R3 = Vector4(i, j, k, l) * scalar let R4 = Vector4(m, n, o, p) * scalar - + let AScaled = A * scalar - + Assert.Equal(R1, AScaled.Row0) Assert.Equal(R2, AScaled.Row1) Assert.Equal(R3, AScaled.Row2) Assert.Equal(R4, AScaled.Row3) - + [] let ``Static method matrix multiplication by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let R1 = Vector4(a, b, c, d) * scalar let R2 = Vector4(e, f, g, h) * scalar let R3 = Vector4(i, j, k, l) * scalar let R4 = Vector4(m, n, o, p) * scalar - + let AScaled = Matrix4.Mult(A, scalar) - + Assert.Equal(R1, AScaled.Row0) Assert.Equal(R2, AScaled.Row1) Assert.Equal(R3, AScaled.Row2) Assert.Equal(R4, AScaled.Row3) - + [] let ``Static method matrix multiplication by reference by scalar is the same as row multiplication by scalar`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, scalar : float32) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let R1 = Vector4(a, b, c, d) * scalar let R2 = Vector4(e, f, g, h) * scalar let R3 = Vector4(i, j, k, l) * scalar let R4 = Vector4(m, n, o, p) * scalar - + let AScaled = Matrix4.Mult(ref A, scalar) - + Assert.Equal(R1, AScaled.Row0) Assert.Equal(R2, AScaled.Row1) Assert.Equal(R3, AScaled.Row2) Assert.Equal(R4, AScaled.Row3) - - + + [ |])>] - module Addition = + module Addition = // [] let ``Matrix addition adds corresponding components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let sum = A + B - + Assert.Equal(a + a, sum.M11) Assert.Equal(b + b, sum.M12) Assert.Equal(c + c, sum.M13) @@ -231,17 +231,17 @@ module Matrix4 = Assert.Equal(n + n, sum.M42) Assert.Equal(o + o, sum.M43) Assert.Equal(p + p, sum.M44) - + [ |])>] - module Subtraction = + module Subtraction = // [] let ``Matrix subtraction subtracts corresponding components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) let B = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let sub = A - B - + Assert.Equal(a - a, sub.M11) Assert.Equal(b - b, sub.M12) Assert.Equal(c - c, sub.M13) @@ -261,34 +261,34 @@ module Matrix4 = Assert.Equal(n - n, sub.M42) Assert.Equal(o - o, sub.M43) Assert.Equal(p - p, sub.M44) - + [ |])>] - module Indexing = + module Indexing = // [] let ``Matrix set indexing sets correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let mutable A = Matrix4() - + A.[0, 0] <- a A.[0, 1] <- b A.[0, 2] <- c A.[0, 3] <- d - + A.[1, 0] <- e A.[1, 1] <- f A.[1, 2] <- g A.[1, 3] <- h - + A.[2, 0] <- i A.[2, 1] <- j A.[2, 2] <- k A.[2, 3] <- l - + A.[3, 0] <- m A.[3, 1] <- n A.[3, 2] <- o A.[3, 3] <- p - + Assert.Equal(a, A.M11) Assert.Equal(b, A.M12) Assert.Equal(c, A.M13) @@ -308,11 +308,11 @@ module Matrix4 = Assert.Equal(n, A.M42) Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - + [] let ``Matrix get indexing accesses the correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + Assert.Equal(a, A.[0, 0]) Assert.Equal(b, A.[0, 1]) Assert.Equal(c, A.[0, 2]) @@ -341,7 +341,7 @@ module Matrix4 = (fun() -> a.[-1, -2] <- x) |> Assert.Throws |> ignore [] - let ``Indexed get operator throws exception for negative indices`` (a : Matrix4) = + let ``Indexed get operator throws exception for negative indices`` (a : Matrix4) = (fun() -> a.[-1, 2] |> ignore) |> Assert.Throws |> ignore (fun() -> a.[1, -2] |> ignore) |> Assert.Throws |> ignore (fun() -> a.[-1, -2] |> ignore) |> Assert.Throws |> ignore @@ -352,25 +352,25 @@ module Matrix4 = (fun() -> b.[5, 2] <- x) |> Assert.Throws |> ignore (fun() -> b.[1, 6] <- x) |> Assert.Throws |> ignore (fun() -> b.[7, 12] <- x) |> Assert.Throws |> ignore - + [] - let ``Indexed get operator throws exception for large indices`` (a : Matrix4) = + let ``Indexed get operator throws exception for large indices`` (a : Matrix4) = (fun() -> a.[5, 2] |> ignore) |> Assert.Throws |> ignore (fun() -> a.[1, 6] |> ignore) |> Assert.Throws |> ignore (fun() -> a.[7, 12] |> ignore) |> Assert.Throws |> ignore - + [ |])>] - module ``Row and column properties`` = + module ``Row and column properties`` = // [] let ``Matrix row properties return the correct components`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = let A = Matrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) - + let R0 = A.Row0 let R1 = A.Row1 let R2 = A.Row2 let R3 = A.Row3 - + Assert.Equal(a, R0.X) Assert.Equal(b, R0.Y) Assert.Equal(c, R0.Z) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 3a3c3bd6..adb4ab70 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -7,18 +7,18 @@ open System open System.Runtime.InteropServices open OpenTK -module Vector2 = +module Vector2 = [ |])>] - module Constructors = + module Constructors = // [] - let ``Single value constructor sets all components to the same value`` (f : float32) = + let ``Single value constructor sets all components to the same value`` (f : float32) = let v = Vector2(f) Assert.Equal(f,v.X) Assert.Equal(f,v.Y) - + [] - let ``Two value constructor sets all components correctly`` (x,y) = + let ``Two value constructor sets all components correctly`` (x,y) = let v = Vector2(x,y) Assert.Equal(x,v.X) Assert.Equal(y,v.Y) @@ -29,269 +29,269 @@ module Vector2 = [] let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector2, b : Vector2, w : Vector2) = let res = Vector2.Clamp(w, a, b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) - + [] let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector2, b : Vector2, w : Vector2) = let res = Vector2.Clamp(ref w, ref a, ref b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) - + [ |])>] - module Length = + module Length = // [] - let ``Length is always >= 0`` (a : Vector2) = + let ``Length is always >= 0`` (a : Vector2) = // Assert.True(a.Length >= 0.0f) - + [] - let ``Length follows the pythagorean theorem`` (a, b) = + let ``Length follows the pythagorean theorem`` (a, b) = let v = Vector2(a, b) let l = System.Math.Sqrt((float)(a * a + b * b)) - + Assert.Equal((float32)l, v.Length) - + [] - let ``Fast length method works`` (a, b) = + let ``Fast length method works`` (a, b) = let v = Vector2(a, b) let l = 1.0f / MathHelper.InverseSqrtFast(a * a + b * b) - + Assert.Equal(l, v.LengthFast) - + [] - let ``Length squared method works`` (a, b) = + let ``Length squared method works`` (a, b) = let v = Vector2(a, b) let lsq = a * a + b * b - + Assert.Equal(lsq, v.LengthSquared) - + [ |])>] - module ``Unit vectors and perpendicularity`` = + module ``Unit vectors and perpendicularity`` = // [] - let ``Perpendicular vector to the right is correct`` (a, b) = + let ``Perpendicular vector to the right is correct`` (a, b) = let v = Vector2(a, b) let perp = Vector2(b, -a) - + Assert.Equal(perp, v.PerpendicularRight) - + [] - let ``Perpendicular vector to the left is correct`` (a, b) = + let ``Perpendicular vector to the left is correct`` (a, b) = let v = Vector2(a, b) let perp = Vector2(-b, a) - + Assert.Equal(perp, v.PerpendicularLeft) - + [ |])>] - module Indexing = + module Indexing = // [] - let ``Index operator accesses the correct components`` (x, y) = + let ``Index operator accesses the correct components`` (x, y) = let v = Vector2(x, y) - + Assert.Equal(x, v.[0]) Assert.Equal(y, v.[1]) - + [] - let ``Indexed set operator throws exception for negative indices`` (x, y) = + let ``Indexed set operator throws exception for negative indices`` (x, y) = let mutable v = Vector2(x, y) (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore [] - let ``Indexed get operator throws exception for negative indices`` (x, y) = + let ``Indexed get operator throws exception for negative indices`` (x, y) = let mutable v = Vector2(x, y) (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore [] - let ``Indexed set operator throws exception for large indices`` (x, y) = + let ``Indexed set operator throws exception for large indices`` (x, y) = let mutable v = Vector2(x, y) - + (fun() -> v.[2] <- x) |> Assert.Throws |> ignore - + [] - let ``Indexed get operator throws exception for large indices`` (x, y) = + let ``Indexed get operator throws exception for large indices`` (x, y) = let mutable v = Vector2(x, y) - + (fun() -> v.[2] |> ignore) |> Assert.Throws |> ignore - + [ |])>] - module ``Simple Properties`` = + module ``Simple Properties`` = // [] - let ``Vector equality is by component`` (a : Vector2,b : Vector2) = + let ``Vector equality is by component`` (a : Vector2,b : Vector2) = // Assert.Equal((a.X = b.X && a.Y = b.Y),(a = b)) - + [] - let ``Vector length is always >= 0`` (a : Vector2) = + let ``Vector length is always >= 0`` (a : Vector2) = // Assert.True(a.Length >= 0.0f) - + [ |])>] - module Addition = + module Addition = // [] - let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = + let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = let c = a + b Assert.ApproximatelyEqual(a.X + b.X,c.X) Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) - + [] - let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = + let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = let c = a + b let c2 = b + a Assert.ApproximatelyEqual(c,c2) - + [] - let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = + let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = let r1 = (a + b) + c let r2 = a + (b + c) Assert.ApproximatelyEqual(r1,r2) - + [] - let ``Static Vector2 addition method is the same as component addition`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 addition method is the same as component addition`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X + b.X, a.Y + b.Y) let sum = Vector2.Add(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2 addition method by reference is the same as component addition`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 addition method by reference is the same as component addition`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X + b.X, a.Y + b.Y) let sum = Vector2.Add(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Multiplication = + module Multiplication = // [] - let ``Vector2 multiplication is the same as component multiplication`` (a : Vector2, b : Vector2) = + let ``Vector2 multiplication is the same as component multiplication`` (a : Vector2, b : Vector2) = let c = a * b Assert.Equal(a.X * b.X,c.X) Assert.Equal(a.Y * b.Y,c.Y) - + [] - let ``Vector2 multiplication is commutative`` (a : Vector2, b : Vector2) = + let ``Vector2 multiplication is commutative`` (a : Vector2, b : Vector2) = let r1 = a * b let r2 = b * a Assert.Equal(r1,r2) - + [] - let ``Left-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = + let ``Left-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = let r = a * f - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - + [] - let ``Right-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = + let ``Right-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = let r = f * a Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - + [] - let ``Static Vector2 multiplication method is the same as component multiplication`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 multiplication method is the same as component multiplication`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X * b.X, a.Y * b.Y) let sum = Vector2.Multiply(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2 multiplication method by reference is the same as component multiplication`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 multiplication method by reference is the same as component multiplication`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X * b.X, a.Y * b.Y) let sum = Vector2.Multiply(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static method Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = + let ``Static method Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = let r = Vector2.Multiply(a, f) - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - + [ |])>] - module Subtraction = + module Subtraction = // [] - let ``Vector2 subtraction is the same as component subtraction`` (a : Vector2, b : Vector2) = + let ``Vector2 subtraction is the same as component subtraction`` (a : Vector2, b : Vector2) = let c = a - b Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) - + [] - let ``Static Vector2 subtraction method is the same as component addition`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 subtraction method is the same as component addition`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X - b.X, a.Y - b.Y) let sum = Vector2.Subtract(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2 subtraction method by reference is the same as component addition`` (a : Vector2, b : Vector2) = - + let ``Static Vector2 subtraction method by reference is the same as component addition`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X - b.X, a.Y - b.Y) let sum = Vector2.Subtract(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Division = + module Division = // [] - let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = + let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = let r = a / f - + Assert.ApproximatelyEqual(a.X / f,r.X) Assert.ApproximatelyEqual(a.Y / f,r.Y) - + [] - let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) = - + let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) = - + let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) = + let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) = - + let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) = + let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) = - + let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) = + let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(ref a, b) - + Assert.ApproximatelyEqual(v1, sum) [ |])>] @@ -303,7 +303,7 @@ module Vector2 = let vNeg = -v Assert.Equal(-x, vNeg.X) Assert.Equal(-y, vNeg.Y) - + [ |])>] module Equality = // @@ -312,29 +312,29 @@ module Vector2 = let v1 = Vector2(x, y) let v2 = Vector2(x, y) let equality = v1 = v2 - + Assert.True(equality) - + [] let ``Vector inequality operator is by component`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(x + (float32)1 , y + (float32)1) let inequality = v1 <> v2 - + Assert.True(inequality) - + [] let ``Vector equality method is by component`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(x, y) let notVector = Matrix2() - + let equality = v1.Equals(v2) let inequalityByOtherType = v1.Equals(notVector) - + Assert.True(equality) Assert.False(inequalityByOtherType) - + [ |])>] module Swizzling = // @@ -342,7 +342,7 @@ module Vector2 = let ``Vector swizzling returns the correct composites`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector2(y, x) - + let v1yx = v1.Yx; Assert.Equal(v2, v1yx); @@ -353,76 +353,76 @@ module Vector2 = let ``Linear interpolation is by component`` (a : Vector2, b : Vector2, q) = let blend = q - - let rX = blend * (b.X - a.X) + a.X + + let rX = blend * (b.X - a.X) + a.X let rY = blend * (b.Y - a.Y) + a.Y let vExp = Vector2(rX, rY) - + Assert.Equal(vExp, Vector2.Lerp(a, b, q)) - + let vRes = Vector2.Lerp(ref a, ref b, q) Assert.Equal(vExp, vRes) - + [] let ``Barycentric interpolation follows the barycentric formula`` (a : Vector2, b : Vector2, c : Vector2, u, v) = let r = a + u * (b - a) + v * (c - a) - + Assert.Equal(r, Vector2.BaryCentric(a, b, c, u, v)) - + let vRes = Vector2.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - + [ |])>] module ``Vector products`` = // [] let ``Dot product follows the dot product formula`` (a : Vector2, b : Vector2) = let dot = a.X * b.X + a.Y * b.Y - + Assert.Equal(dot, Vector2.Dot(a, b)); - + let vRes = Vector2.Dot(ref a, ref b) Assert.Equal(dot, vRes) - + [] let ``Perpendicular dot product follows the perpendicular dot product formula`` (a : Vector2, b : Vector2) = let perpDot = a.X * b.Y - a.Y * b.X - + Assert.Equal(perpDot, Vector2.PerpDot(a, b)); - + let vRes = Vector2.PerpDot(ref a, ref b) Assert.Equal(perpDot, vRes) - + [ |])>] - module Normalization = + module Normalization = // [] - let ``Normalization creates a new unit length vector with the correct components`` (a, b) = + let ``Normalization creates a new unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let l = v.Length - + // Dividing by zero is not supported if not (approxEq l 0.0f) then let norm = v.Normalized() - + Assert.ApproximatelyEqual(v.X / l, norm.X) Assert.ApproximatelyEqual(v.Y / l, norm.Y) [] - let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let l = v.Length - + if not (approxEq l 0.0f) then let norm = Vector2(a, b) norm.Normalize() - + Assert.ApproximatelyEqual(v.X / l, norm.X) Assert.ApproximatelyEqual(v.Y / l, norm.Y) [] - let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = let v = Vector2(a, b) let norm = Vector2(a, b) norm.NormalizeFast() @@ -431,37 +431,37 @@ module Vector2 = Assert.ApproximatelyEqual(v.X * scale, norm.X) Assert.ApproximatelyEqual(v.Y * scale, norm.Y) - + [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector2) = let norm = a / a.Length let vRes = Vector2.Normalize(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Normalization is the same as division by magnitude`` (a : Vector2) = let norm = a / a.Length - + Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); - + [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) - + let norm = a * scale let vRes = Vector2.NormalizeFast(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector2) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y) - + let norm = a * scale - + Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); - + [ |])>] module ``Component min and max`` = // @@ -469,117 +469,117 @@ module Vector2 = let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let vMin = Vector2.ComponentMin(v1, v2) - + Assert.True(vMin.X <= v1.X) Assert.True(vMin.X <= v2.X) - + Assert.True(vMin.Y <= v1.Y) Assert.True(vMin.Y <= v2.Y) - + [] let ``ComponentMax produces a new vector from the largest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let vMax = Vector2.ComponentMax(v1, v2) - + Assert.True(vMax.X >= v1.X) Assert.True(vMax.X >= v2.X) - + Assert.True(vMax.Y >= v1.Y) Assert.True(vMax.Y >= v2.Y) - + [] let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let vMin = Vector2.ComponentMin(ref v1, ref v2) - + Assert.True(vMin.X <= v1.X) Assert.True(vMin.X <= v2.X) - + Assert.True(vMin.Y <= v1.Y) Assert.True(vMin.Y <= v2.Y) - + [] let ``ComponentMax by reference produces a new vector from the largest components of the given vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let vMax = Vector2.ComponentMax(ref v1, ref v2) - + Assert.True(vMax.X >= v1.X) Assert.True(vMax.X >= v2.X) - + Assert.True(vMax.Y >= v1.Y) Assert.True(vMax.Y >= v2.Y) - + [] let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector2.Min(v1, v2) - + if l1 < l2 then - let equalsFirst = vMin = v1 + let equalsFirst = vMin = v1 Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + [] let ``Max selects the vector with greater magnitude given two vectors`` (x, y, u, w) = let v1 = Vector2(x, y) let v2 = Vector2(u, w) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector2.Max(v1, v2) - + if l1 >= l2 then - let equalsFirst = vMin = v1 + let equalsFirst = vMin = v1 Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) [ |])>] - module Transformation = + module Transformation = // [] - let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = + let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) let inverse = Quaternion.Invert(q) - + let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - + Assert.Equal(transformedVector, Vector2.Transform(v, q)) - + [] - let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = + let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) let inverse = Quaternion.Invert(q) - + let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - + Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) - + [ |])>] - module Serialization = + module Serialization = // [] - let ``The absolute size of a Vector2 is always the size of its components`` (v : Vector2) = + let ``The absolute size of a Vector2 is always the size of its components`` (v : Vector2) = let expectedSize = sizeof * 2 - + Assert.Equal(expectedSize, Vector2.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector2())) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 81edaa24..9c879b68 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -7,28 +7,28 @@ open System open System.Runtime.InteropServices open OpenTK -module Vector3 = +module Vector3 = [ |])>] - module Constructors = + module Constructors = // [] - let ``Triple value constructor sets all components to the correct values`` (a, b, c) = + let ``Triple value constructor sets all components to the correct values`` (a, b, c) = let v = Vector3(a, b, c) Assert.Equal(a, v.X) Assert.Equal(b, v.Y) Assert.Equal(c, v.Z) - + [] - let ``Single value constructor sets all components to the correct values`` (a : float32) = + let ``Single value constructor sets all components to the correct values`` (a : float32) = let v = Vector3(a) Assert.Equal(a, v.X) Assert.Equal(a, v.Y) Assert.Equal(a, v.Z) - + [] - let ``Vector2 value constructor sets all components to the correct values`` (a, b) = + let ``Vector2 value constructor sets all components to the correct values`` (a, b) = let v1 = Vector2(a, b) let v2 = Vector3(v1) @@ -38,9 +38,9 @@ module Vector3 = Assert.Equal(a, v2.X) Assert.Equal(b, v2.Y) Assert.Equal((float32)0, v2.Z) - + [] - let ``Vector3 value constructor sets all components to the correct values`` (a, b, c) = + let ``Vector3 value constructor sets all components to the correct values`` (a, b, c) = let v1 = Vector3(a, b, c) let v2 = Vector3(v1) @@ -51,9 +51,9 @@ module Vector3 = Assert.Equal(a, v2.X) Assert.Equal(b, v2.Y) Assert.Equal(c, v2.Z) - + [] - let ``Vector4 value constructor sets all components to the correct values`` (a, b, c, d) = + let ``Vector4 value constructor sets all components to the correct values`` (a, b, c, d) = let v1 = Vector4(a, b, c, d) let v2 = Vector3(v1) @@ -64,87 +64,87 @@ module Vector3 = Assert.Equal(a, v2.X) Assert.Equal(b, v2.Y) Assert.Equal(c, v2.Z) - + [ |])>] - module Indexing = + module Indexing = // [] - let ``Index operator accesses the correct components`` (x, y, z) = + let ``Index operator accesses the correct components`` (x, y, z) = let v = Vector3(x, y, z) - + Assert.Equal(x, v.[0]) Assert.Equal(y, v.[1]) Assert.Equal(z, v.[2]) - + [] - let ``Indexed set operator throws exception for negative indices`` (x, y, z) = + let ``Indexed set operator throws exception for negative indices`` (x, y, z) = let mutable v = Vector3(x, y, z) (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore [] - let ``Indexed get operator throws exception for negative indices`` (x, y, z) = + let ``Indexed get operator throws exception for negative indices`` (x, y, z) = let mutable v = Vector3(x, y, z) (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore [] - let ``Indexed set operator throws exception for large indices`` (x, y, z) = + let ``Indexed set operator throws exception for large indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - + (fun() -> v.[4] <- x) |> Assert.Throws |> ignore - + [] - let ``Indexed get operator throws exception for large indices`` (x, y, z) = + let ``Indexed get operator throws exception for large indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - + (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore - + [ |])>] - module Length = + module Length = // [] - let ``Length method follows the pythagorean theorem`` (a, b, c) = + let ``Length method follows the pythagorean theorem`` (a, b, c) = let v = Vector3(a, b, c) let l = System.Math.Sqrt((float)(a * a + b * b + c * c)) - + Assert.Equal((float32)l, v.Length) - + [] - let ``Fast length method is the same as one divided by the fast inverse square`` (a, b, c) = + let ``Fast length method is the same as one divided by the fast inverse square`` (a, b, c) = let v = Vector3(a, b, c) let l = 1.0f / MathHelper.InverseSqrtFast(a * a + b * b + c * c) - + Assert.Equal(l, v.LengthFast) - + [] - let ``Length squared method returns each component squared and summed`` (a, b, c) = + let ``Length squared method returns each component squared and summed`` (a, b, c) = let v = Vector3(a, b, c) let lsq = a * a + b * b + c * c - + Assert.Equal(lsq, v.LengthSquared) - + [ |])>] - module Normalization = + module Normalization = // [] - let ``Normalization creates a new unit length vector with the correct components`` (a, b, c) = + let ``Normalization creates a new unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let l = v.Length - + // Dividing by zero is not supported if not (approxEq l 0.0f) then let norm = v.Normalized() - + Assert.ApproximatelyEqual(v.X / l, norm.X) Assert.ApproximatelyEqual(v.Y / l, norm.Y) Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] - let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let l = v.Length - + if not (approxEq l 0.0f) then let norm = Vector3(a, b, c) norm.Normalize() @@ -154,7 +154,7 @@ module Vector3 = Assert.ApproximatelyEqual(v.Z / l, norm.Z) [] - let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = let v = Vector3(a, b, c) let norm = Vector3(a, b, c) norm.NormalizeFast() @@ -164,230 +164,230 @@ module Vector3 = Assert.ApproximatelyEqual(v.X * scale, norm.X) Assert.ApproximatelyEqual(v.Y * scale, norm.Y) Assert.ApproximatelyEqual(v.Z * scale, norm.Z) - + [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector3) = let norm = a / a.Length let vRes = Vector3.Normalize(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Normalization is the same as division by magnitude`` (a : Vector3) = let norm = a / a.Length - + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); - + [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector3) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) - + let norm = a * scale let vRes = Vector3.NormalizeFast(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Fast approximate normalization is the same as multiplication by fast inverse square`` (a : Vector3) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z) - + let norm = a * scale - + Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a)); [ |])>] - module Addition = + module Addition = // [] - let ``Vector3 addition is the same as component addition`` (a : Vector3, b : Vector3) = + let ``Vector3 addition is the same as component addition`` (a : Vector3, b : Vector3) = let c = a + b - + Assert.ApproximatelyEqual(a.X + b.X,c.X) Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) - + [] - let ``Vector3 addition is commutative`` (a : Vector3, b : Vector3) = + let ``Vector3 addition is commutative`` (a : Vector3, b : Vector3) = let c = a + b let c2 = b + a - + Assert.ApproximatelyEqual(c, c2) - + [] - let ``Vector3 addition is associative`` (a : Vector3, b : Vector3, c : Vector3) = + let ``Vector3 addition is associative`` (a : Vector3, b : Vector3, c : Vector3) = let r1 = (a + b) + c let r2 = a + (b + c) - + Assert.ApproximatelyEqual(r1, r2) - + [] - let ``Static Vector3 addition method is the same as component addition`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 addition method is the same as component addition`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3 addition method by reference is the same as component addition`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 addition method by reference is the same as component addition`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Subtraction = + module Subtraction = // [] - let ``Vector3 subtraction is the same as component subtraction`` (a : Vector3, b : Vector3) = + let ``Vector3 subtraction is the same as component subtraction`` (a : Vector3, b : Vector3) = let c = a - b - + Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) Assert.Equal(a.Z - b.Z,c.Z) - + [] - let ``Static Vector3 subtraction method is the same as component addition`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 subtraction method is the same as component addition`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3 subtraction method by reference is the same as component addition`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 subtraction method by reference is the same as component addition`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Multiplication = + module Multiplication = // [] - let ``Vector3 multiplication is the same as component multiplication`` (a : Vector3, b : Vector3) = + let ``Vector3 multiplication is the same as component multiplication`` (a : Vector3, b : Vector3) = let c = a * b - + Assert.Equal(a.X * b.X,c.X) Assert.Equal(a.Y * b.Y,c.Y) Assert.Equal(a.Z * b.Z,c.Z) - + [] - let ``Vector3 multiplication is commutative`` (a : Vector3, b : Vector3) = + let ``Vector3 multiplication is commutative`` (a : Vector3, b : Vector3) = let r1 = a * b let r2 = b * a - + Assert.Equal(r1, r2) - + [] - let ``Left-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = + let ``Left-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = let r = a * f - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) - + [] - let ``Right-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = + let ``Right-handed Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = let r = f * a Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) - + [] - let ``Static method Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = + let ``Static method Vector3-scalar multiplication is the same as component-scalar multiplication`` (a : Vector3, f : float32) = let r = Vector3.Multiply(a, f) - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) - + [] - let ``Vector3-Matrix3 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix3, b : Vector3) = + let ``Vector3-Matrix3 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix3, b : Vector3) = let res = a*b - + let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 let c2 = b.X * a.M21 + b.Y * a.M22 + b.Z * a.M23 let c3 = b.X * a.M31 + b.Y * a.M32 + b.Z * a.M33 - + let exp = Vector3(c1, c2, c3) - + Assert.Equal(exp, res) - + [] - let ``Vector3-Matrix3 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix3, b : Vector3) = + let ``Vector3-Matrix3 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix3, b : Vector3) = let res = b*a - + let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 let c2 = b.X * a.M12 + b.Y * a.M22 + b.Z * a.M32 let c3 = b.X * a.M13 + b.Y * a.M23 + b.Z * a.M33 - + let exp = Vector3(c1, c2, c3) - + Assert.Equal(exp, res) - + [] - let ``Static Vector3 multiplication method is the same as component multiplication`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 multiplication method is the same as component multiplication`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3 multiplication method by reference is the same as component multiplication`` (a : Vector3, b : Vector3) = - + let ``Static Vector3 multiplication method by reference is the same as component multiplication`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Division = + module Division = // [] - let ``Vector3-float division is the same as component-float division`` (a : Vector3, f : float32) = + let ``Vector3-float division is the same as component-float division`` (a : Vector3, f : float32) = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f - + Assert.ApproximatelyEqual(a.X / f,r.X) Assert.ApproximatelyEqual(a.Y / f,r.Y) Assert.ApproximatelyEqual(a.Z / f,r.Z) - + [] - let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) = - + let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) = - + let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) = + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) = - + let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) = + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) = - + let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) = + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(ref a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] module Negation = // @@ -398,7 +398,7 @@ module Vector3 = Assert.Equal(-x, vNeg.X) Assert.Equal(-y, vNeg.Y) Assert.Equal(-z, vNeg.Z) - + [ |])>] module Equality = // @@ -407,74 +407,74 @@ module Vector3 = let v1 = Vector3(x, y, z) let v2 = Vector3(x, y, z) let equality = v1 = v2 - + Assert.True(equality) - + [] let ``Vector inequality operator is by component`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector3(x + (float32)1 , y + (float32)1, z + (float32)1) let inequality = v1 <> v2 - + Assert.True(inequality) - + [] let ``Vector equality method is by component`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector3(x, y, z) let notVector = Matrix2() - + let equality = v1.Equals(v2) let inequalityByOtherType = v1.Equals(notVector) - + Assert.True(equality) Assert.False(inequalityByOtherType) - + [ |])>] module Swizzling = // [] let ``Vector swizzling returns the correct composite for X-primary components`` (x, y, z) = let v = Vector3(x, y, z) - + let xyz = Vector3(x, y, z) let xzy = Vector3(x, z, y) let xy = Vector2(x, y) let xz = Vector2(x, z) - + Assert.Equal(xyz, v); Assert.Equal(xzy, v.Xzy); Assert.Equal(xy, v.Xy); Assert.Equal(xz, v.Xz); - + [] let ``Vector swizzling returns the correct composite for Y-primary components`` (x, y, z) = let v = Vector3(x, y, z) - + let yxz = Vector3(y, x, z) let yzx = Vector3(y, z, x) let yx = Vector2(y, x) let yz = Vector2(y, z) - + Assert.Equal(yxz, v.Yxz); Assert.Equal(yzx, v.Yzx); Assert.Equal(yx, v.Yx); Assert.Equal(yz, v.Yz); - + [] let ``Vector swizzling returns the correct composite for Z-primary components`` (x, y, z) = let v = Vector3(x, y, z) - + let zxy = Vector3(z, x, y) let zyx = Vector3(z, y, x) let zx = Vector2(z, x) let zy = Vector2(z, y); - + Assert.Equal(zxy, v.Zxy); Assert.Equal(zyx, v.Zyx); Assert.Equal(zx, v.Zx); Assert.Equal(zy, v.Zy); - + [ |])>] module Interpolation = // @@ -482,51 +482,51 @@ module Vector3 = let ``Linear interpolation is by component`` (a : Vector3, b : Vector3, q) = let blend = q - - let rX = blend * (b.X - a.X) + a.X + + let rX = blend * (b.X - a.X) + a.X let rY = blend * (b.Y - a.Y) + a.Y let rZ = blend * (b.Z - a.Z) + a.Z let vExp = Vector3(rX, rY, rZ) - + Assert.Equal(vExp, Vector3.Lerp(a, b, q)) - + let vRes = Vector3.Lerp(ref a, ref b, q) Assert.Equal(vExp, vRes) - + [] let ``Barycentric interpolation follows the barycentric formula`` (a : Vector3, b : Vector3, c : Vector3, u, v) = let r = a + u * (b - a) + v * (c - a) - + Assert.Equal(r, Vector3.BaryCentric(a, b, c, u, v)) - + let vRes = Vector3.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - + [ |])>] module ``Vector products`` = // [] let ``Dot product follows the dot product formula`` (a : Vector3, b : Vector3) = let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z - + Assert.Equal(dot, Vector3.Dot(a, b)); - + let vRes = Vector3.Dot(ref a, ref b) Assert.Equal(dot, vRes) - + [] let ``Cross product follows the cross product formula`` (a : Vector3, b : Vector3) = let crossX = a.Y * b.Z - a.Z * b.Y let crossY = a.Z * b.X - a.X * b.Z let crossZ = a.X * b.Y - a.Y * b.X let cross = Vector3(crossX, crossY, crossZ) - + Assert.Equal(cross, Vector3.Cross(a, b)); - + let vRes = Vector3.Cross(ref a, ref b) Assert.Equal(cross, vRes) - + [ |])>] module ``Component min and max`` = // @@ -534,166 +534,166 @@ module Vector3 = let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let vMin = Vector3.ComponentMin(v1, v2) - + Assert.True(vMin.X <= v1.X) Assert.True(vMin.X <= v2.X) - + Assert.True(vMin.Y <= v1.Y) Assert.True(vMin.Y <= v2.Y) - + Assert.True(vMin.Z <= v1.Z) Assert.True(vMin.Z <= v2.Z) - + [] let ``ComponentMax producing a new vector from the largest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let vMax = Vector3.ComponentMax(v1, v2) - + Assert.True(vMax.X >= v1.X) Assert.True(vMax.X >= v2.X) - + Assert.True(vMax.Y >= v1.Y) Assert.True(vMax.Y >= v2.Y) - + Assert.True(vMax.Z >= v1.Z) Assert.True(vMax.Z >= v2.Z) - + [] let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let vMin = Vector3.ComponentMin(ref v1, ref v2) - + Assert.True(vMin.X <= v1.X) Assert.True(vMin.X <= v2.X) - + Assert.True(vMin.Y <= v1.Y) Assert.True(vMin.Y <= v2.Y) - + Assert.True(vMin.Z <= v1.Z) Assert.True(vMin.Z <= v2.Z) - + [] let ``ComponentMax produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let vMax = Vector3.ComponentMax(ref v1, ref v2) - + Assert.True(vMax.X >= v1.X) Assert.True(vMax.X >= v2.X) - + Assert.True(vMax.Y >= v1.Y) Assert.True(vMax.Y >= v2.Y) - + Assert.True(vMax.Z >= v1.Z) Assert.True(vMax.Z >= v2.Z) - + [] let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector3.Min(v1, v2) - + if l1 < l2 then - let equalsFirst = vMin = v1 + let equalsFirst = vMin = v1 Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + [] let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, u, w, q) = let v1 = Vector3(x, y, z) let v2 = Vector3(u, w, q) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector3.Max(v1, v2) - + if l1 >= l2 then - let equalsFirst = vMin = v1 + let equalsFirst = vMin = v1 Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - + else + let equalsLast = vMin = v2 + Assert.True(equalsLast) + [ |])>] module Clamping = // [] let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector3, b : Vector3, w : Vector3) = let res = Vector3.Clamp(w, a, b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) - + [] let ``Clamping one vector between two other vectors by reference clamps all components between corresponding components`` (a : Vector3, b : Vector3, w : Vector3) = let res = Vector3.Clamp(ref w, ref a, ref b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) - + [ |])>] - module ``Unit vectors``= + module ``Unit vectors``= // [] - let ``Unit X is correct`` = + let ``Unit X is correct`` = let unitX = Vector3((float32)1, (float32)0, (float32)0) - + Assert.Equal(Vector3.UnitX, unitX) - + [] - let ``Unit Y is correct`` = + let ``Unit Y is correct`` = let unitY = Vector3((float32)0, (float32)1, (float32)0) - + Assert.Equal(Vector3.UnitY, unitY) - + [] - let ``Unit Z is correct`` = + let ``Unit Z is correct`` = let unitZ = Vector3((float32)0, (float32)0, (float32)1) - + Assert.Equal(Vector3.UnitZ, unitZ) - + [] - let ``Unit zero is correct`` = + let ``Unit zero is correct`` = let unitZero = Vector3((float32)0, (float32)0, (float32)0) - + Assert.Equal(Vector3.Zero, unitZero) - + [] - let ``Unit one is correct`` = + let ``Unit one is correct`` = let unitOne = Vector3((float32)1, (float32)1, (float32)1) - + Assert.Equal(Vector3.One, unitOne) - + [ |])>] - module Serialization = + module Serialization = // [] - let ``The absolute size of a Vector3 is always the size of its components`` (v : Vector3) = + let ``The absolute size of a Vector3 is always the size of its components`` (v : Vector3) = let expectedSize = sizeof * 3 - + Assert.Equal(expectedSize, Vector3.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 877e1744..7033f2a7 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -7,30 +7,30 @@ open System open System.Runtime.InteropServices open OpenTK -module Vector4 = +module Vector4 = [ |])>] - module Constructors = + module Constructors = // [] - let ``Triple value constructor sets all components to the correct values`` (x, y, z, w) = + let ``Triple value constructor sets all components to the correct values`` (x, y, z, w) = let v = Vector4(x, y, z, w) Assert.Equal(x, v.X) Assert.Equal(y, v.Y) Assert.Equal(z, v.Z) Assert.Equal(w, v.W) - + [] - let ``Single value constructor sets all components to the correct values`` (a : float32) = + let ``Single value constructor sets all components to the correct values`` (a : float32) = let v = Vector4(a) Assert.Equal(a, v.X) Assert.Equal(a, v.Y) Assert.Equal(a, v.Z) Assert.Equal(a, v.W) - + [] - let ``Vector2 value constructor sets all components to the correct values`` (x, y) = + let ``Vector2 value constructor sets all components to the correct values`` (x, y) = let v1 = Vector2(x, y) let v2 = Vector4(v1) @@ -41,9 +41,9 @@ module Vector4 = Assert.Equal(y, v2.Y) Assert.Equal((float32)0, v2.Z) Assert.Equal((float32)0, v2.W) - + [] - let ``Vector3 value constructor sets all components to the correct values`` (x, y, z) = + let ``Vector3 value constructor sets all components to the correct values`` (x, y, z) = let v1 = Vector3(x, y, z) let v2 = Vector4(v1) @@ -55,9 +55,9 @@ module Vector4 = Assert.Equal(y, v2.Y) Assert.Equal(z, v2.Z) Assert.Equal((float32)0, v2.W) - + [] - let ``Vector3 value and scalar constructor sets all components to the correct values`` (x, y, z, w) = + let ``Vector3 value and scalar constructor sets all components to the correct values`` (x, y, z, w) = let v1 = Vector3(x, y, z) let v2 = Vector4(v1, w) @@ -69,9 +69,9 @@ module Vector4 = Assert.Equal(y, v2.Y) Assert.Equal(z, v2.Z) Assert.Equal(w, v2.W) - + [] - let ``Vector4 value constructor sets all components to the correct values`` (x, y, z, w) = + let ``Vector4 value constructor sets all components to the correct values`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(v1) @@ -84,72 +84,72 @@ module Vector4 = Assert.Equal(y, v2.Y) Assert.Equal(z, v2.Z) Assert.Equal(w, v2.W) - + [ |])>] - module Indexing = + module Indexing = // [] - let ``Index operator accesses the correct components`` (x, y, z, w) = + let ``Index operator accesses the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) - + Assert.Equal(x, v.[0]) Assert.Equal(y, v.[1]) Assert.Equal(z, v.[2]) Assert.Equal(w, v.[3]) - + [] - let ``Indexed set operator throws exception for negative indices`` (x, y, z, w) = + let ``Indexed set operator throws exception for negative indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore [] - let ``Indexed get operator throws exception for negative indices`` (x, y, z, w) = + let ``Indexed get operator throws exception for negative indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore [] - let ``Indexed set operator throws exception for large indices`` (x, y, z, w) = + let ``Indexed set operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - + (fun() -> v.[4] <- x) |> Assert.Throws |> ignore - + [] - let ``Indexed get operator throws exception for large indices`` (x, y, z, w) = + let ``Indexed get operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - + (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore - + [ |])>] - module Length = + module Length = // [] - let ``Length method follows the pythagorean theorem`` (x, y, z, w) = + let ``Length method follows the pythagorean theorem`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = System.Math.Sqrt((float)(x * x + y * y + z * z + w * w)) - + Assert.Equal((float32)l, v.Length) - + [] - let ``Fast length method is the same as one divided by the fast inverse square`` (x, y, z, w) = + let ``Fast length method is the same as one divided by the fast inverse square`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = 1.0f / MathHelper.InverseSqrtFast(x * x + y * y + z * z + w * w) - + Assert.Equal(l, v.LengthFast) - + [] - let ``Length squared method returns each component squared and summed`` (x, y, z, w) = + let ``Length squared method returns each component squared and summed`` (x, y, z, w) = let v = Vector4(x, y, z, w) let lsq = x * x + y * y + z * z + w * w - + Assert.Equal(lsq, v.LengthSquared) - + [ |])>] - module Normalization = + module Normalization = // [] - let ``Normalization creates a new unit length vector with the correct components`` (x, y, z, w) = + let ``Normalization creates a new unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = v.Length @@ -161,7 +161,7 @@ module Vector4 = Assert.ApproximatelyEqual(v.W / l, norm.W) [] - let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = + let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = v.Length @@ -174,7 +174,7 @@ module Vector4 = Assert.ApproximatelyEqual(v.W / l, norm.W) [] - let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = + let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let norm = Vector4(x, y, z, w) norm.NormalizeFast() @@ -185,240 +185,240 @@ module Vector4 = Assert.ApproximatelyEqual(v.Y * scale, norm.Y) Assert.ApproximatelyEqual(v.Z * scale, norm.Z) Assert.ApproximatelyEqual(v.W * scale, norm.W) - + [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) = let norm = a / a.Length let vRes = Vector4.Normalize(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Normalization is the same as division by magnitude`` (a : Vector4) = let norm = a / a.Length - + Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); - + [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) - + let norm = a * scale let vRes = Vector4.NormalizeFast(ref a) - + Assert.ApproximatelyEqual(norm, vRes) - + [] let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) - + let norm = a * scale - + Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a)); [ |])>] - module Addition = + module Addition = // [] - let ``Vector4 addition is the same as component addition`` (a : Vector4, b : Vector4) = + let ``Vector4 addition is the same as component addition`` (a : Vector4, b : Vector4) = let c = a + b - + Assert.ApproximatelyEqual(a.X + b.X,c.X) Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) Assert.ApproximatelyEqual(a.W + b.W,c.W) - + [] - let ``Vector4 addition is commutative`` (a : Vector4, b : Vector4) = + let ``Vector4 addition is commutative`` (a : Vector4, b : Vector4) = let c = a + b let c2 = b + a - + Assert.ApproximatelyEqual(c, c2) - + [] - let ``Vector4 addition is associative`` (a : Vector4, b : Vector4, c : Vector4) = + let ``Vector4 addition is associative`` (a : Vector4, b : Vector4, c : Vector4) = let r1 = (a + b) + c let r2 = a + (b + c) - + Assert.ApproximatelyEqual(r1, r2) - + [] - let ``Static Vector4 addition method is the same as component addition`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 addition method is the same as component addition`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) let sum = Vector4.Add(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4 addition method by reference is the same as component addition`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 addition method by reference is the same as component addition`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) let sum = Vector4.Add(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Subtraction = + module Subtraction = // [] - let ``Vector4 subtraction is the same as component subtraction`` (a : Vector4, b : Vector4) = + let ``Vector4 subtraction is the same as component subtraction`` (a : Vector4, b : Vector4) = let c = a - b - + Assert.Equal(a.X - b.X,c.X) Assert.Equal(a.Y - b.Y,c.Y) Assert.Equal(a.Z - b.Z,c.Z) Assert.Equal(a.W - b.W,c.W) - + [] - let ``Static Vector4 subtraction method is the same as component addition`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 subtraction method is the same as component addition`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) let sum = Vector4.Subtract(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4 subtraction method by reference is the same as component addition`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 subtraction method by reference is the same as component addition`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) let sum = Vector4.Subtract(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Multiplication = + module Multiplication = // [] - let ``Vector4 multiplication is the same as component multiplication`` (a : Vector4, b : Vector4) = + let ``Vector4 multiplication is the same as component multiplication`` (a : Vector4, b : Vector4) = let c = a * b - + Assert.Equal(a.X * b.X,c.X) Assert.Equal(a.Y * b.Y,c.Y) Assert.Equal(a.Z * b.Z,c.Z) Assert.Equal(a.W * b.W,c.W) - + [] - let ``Vector4 multiplication is commutative`` (a : Vector4, b : Vector4) = + let ``Vector4 multiplication is commutative`` (a : Vector4, b : Vector4) = let r1 = a * b let r2 = b * a - + Assert.Equal(r1, r2) - + [] - let ``Left-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let ``Left-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = let r = a * f - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) Assert.Equal(a.W * f,r.W) - + [] - let ``Right-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let ``Right-handed Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = let r = f * a Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) Assert.Equal(a.W * f,r.W) - + [] - let ``Static method Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = + let ``Static method Vector4-scalar multiplication is the same as component-scalar multiplication`` (a : Vector4, f : float32) = let r = Vector4.Multiply(a, f) - + Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) Assert.Equal(a.Z * f,r.Z) Assert.Equal(a.W * f,r.W) - + [] - let ``Vector4-Matrix4 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix4, b : Vector4) = + let ``Vector4-Matrix4 multiplication using right-handed notation is the same as vector/row multiplication and summation`` (a : Matrix4, b : Vector4) = let res = a*b - + let c1 = b.X * a.M11 + b.Y * a.M12 + b.Z * a.M13 + b.W * a.M14 let c2 = b.X * a.M21 + b.Y * a.M22 + b.Z * a.M23 + b.W * a.M24 let c3 = b.X * a.M31 + b.Y * a.M32 + b.Z * a.M33 + b.W * a.M34 let c4 = b.X * a.M41 + b.Y * a.M42 + b.Z * a.M43 + b.W * a.M44 - + let exp = Vector4(c1, c2, c3, c4) - + Assert.Equal(exp, res) - + [] - let ``Vector4-Matrix4 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix4, b : Vector4) = + let ``Vector4-Matrix4 multiplication using left-handed notation is the same as vector/column multiplication and summation`` (a : Matrix4, b : Vector4) = let res = b*a - + let c1 = b.X * a.M11 + b.Y * a.M21 + b.Z * a.M31 + b.W * a.M41 let c2 = b.X * a.M12 + b.Y * a.M22 + b.Z * a.M32 + b.W * a.M42 let c3 = b.X * a.M13 + b.Y * a.M23 + b.Z * a.M33 + b.W * a.M43 let c4 = b.X * a.M14 + b.Y * a.M24 + b.Z * a.M34 + b.W * a.M44 - + let exp = Vector4(c1, c2, c3, c4) - + Assert.Equal(exp, res) - + [] - let ``Static Vector4 multiplication method is the same as component multiplication`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 multiplication method is the same as component multiplication`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) let sum = Vector4.Multiply(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4 multiplication method by reference is the same as component multiplication`` (a : Vector4, b : Vector4) = - + let ``Static Vector4 multiplication method by reference is the same as component multiplication`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) let sum = Vector4.Multiply(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] - module Division = + module Division = // [] - let ``Vector4-float division is the same as component-float division`` (a : Vector4, f : float32) = + let ``Vector4-float division is the same as component-float division`` (a : Vector4, f : float32) = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f - + Assert.ApproximatelyEqual(a.X / f, r.X) Assert.ApproximatelyEqual(a.Y / f, r.Y) Assert.ApproximatelyEqual(a.Z / f, r.Z) Assert.ApproximatelyEqual(a.W / f, r.W) - + [] - let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) = - + let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) = - + let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) = + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(ref a, ref b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) = - + let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) = + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [] - let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) = - + let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) = + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(ref a, b) - + Assert.ApproximatelyEqual(v1, sum) - + [ |])>] module Negation = // @@ -430,7 +430,7 @@ module Vector4 = Assert.Equal(-y, vNeg.Y) Assert.Equal(-z, vNeg.Z) Assert.Equal(-w, vNeg.W) - + [ |])>] module Equality = // @@ -439,64 +439,64 @@ module Vector4 = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x, y, z, w) let equality = v1 = v2 - + Assert.True(equality) - + [] let ``Vector inequality operator is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x + (float32)1 , y + (float32)1, z + (float32)1, w + (float32)1) let inequality = v1 <> v2 - + Assert.True(inequality) - + [] let ``Vector equality method is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(x, y, z, w) let notVector = Matrix2() - + let equality = v1.Equals(v2) let inequalityByOtherType = v1.Equals(notVector) - + Assert.True(equality) Assert.False(inequalityByOtherType) - + [] let ``Vector equality method returns false for other classes`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) let notVector = Matrix2() - + let inequalityByOtherType = v1.Equals(notVector) - + Assert.False(inequalityByOtherType) - + [ |])>] module Swizzling = // [] let ``Vector swizzling returns the correct composite for X-primary components`` (x, y, z, w) = - + let v = Vector4(x, y, z, w) - + let xyzw = v let xywz = Vector4(x, y, w, z) let xzyw = Vector4(x, z, y, w) let xzwy = Vector4(x, z, w, y) let xwyz = Vector4(x, w, y, z) let xwzy = Vector4(x, w, z, y) - + let xyz = Vector3(x, y, z) let xyw = Vector3(x, y, w) let xzy = Vector3(x, z, y) let xzw = Vector3(x, z, w) let xwy = Vector3(x, w, y) let xwz = Vector3(x, w, z) - + let xy = Vector2(x, y) let xz = Vector2(x, z) let xw = Vector2(x, w) - + // X primary Assert.Equal(xyzw, v) Assert.Equal(xywz, v.Xywz) @@ -504,23 +504,23 @@ module Vector4 = Assert.Equal(xzwy, v.Xzwy) Assert.Equal(xwyz, v.Xwyz) Assert.Equal(xwzy, v.Xwzy) - + Assert.Equal(xyz, v.Xyz) Assert.Equal(xyw, v.Xyw) Assert.Equal(xzy, v.Xzy) Assert.Equal(xzw, v.Xzw) Assert.Equal(xwy, v.Xwy) Assert.Equal(xwz, v.Xwz) - + Assert.Equal(xy, v.Xy) Assert.Equal(xz, v.Xz) Assert.Equal(xw, v.Xw) - + [] let ``Vector swizzling returns the correct composite for Y-primary components`` (x, y, z, w) = - + let v = Vector4(x, y, z, w) - + let yxzw = Vector4(y, x, z, w) let yxwz = Vector4(y, x, w, z) let yyzw = Vector4(y, y, z, w) @@ -529,18 +529,18 @@ module Vector4 = let yzwx = Vector4(y, z, w, x) let ywxz = Vector4(y, w, x, z) let ywzx = Vector4(y, w, z, x) - + let yxz = Vector3(y, x, z) let yxw = Vector3(y, x, w) let yzx = Vector3(y, z, x) let yzw = Vector3(y, z, w) let ywx = Vector3(y, w, x) let ywz = Vector3(y, w, z) - + let yx = Vector2(y, x) let yz = Vector2(y, z) let yw = Vector2(y, w) - + // Y primary Assert.Equal(yxzw, v.Yxzw) Assert.Equal(yxwz, v.Yxwz) @@ -550,23 +550,23 @@ module Vector4 = Assert.Equal(yzwx, v.Yzwx) Assert.Equal(ywxz, v.Ywxz) Assert.Equal(ywzx, v.Ywzx) - + Assert.Equal(yxz, v.Yxz) Assert.Equal(yxw, v.Yxw) Assert.Equal(yzx, v.Yzx) Assert.Equal(yzw, v.Yzw) Assert.Equal(ywx, v.Ywx) Assert.Equal(ywz, v.Ywz) - + Assert.Equal(yx, v.Yx) Assert.Equal(yz, v.Yz) Assert.Equal(yw, v.Yw) - + [] let ``Vector swizzling returns the correct composite for Z-primary components`` (x, y, z, w) = - + let v = Vector4(x, y, z, w) - + let zxyw = Vector4(z, x, y, w) let zxwy = Vector4(z, x, w, y) let zyxw = Vector4(z, y, x, w) @@ -574,18 +574,18 @@ module Vector4 = let zwxy = Vector4(z, w, x, y) let zwyx = Vector4(z, w, y, x) let zwzy = Vector4(z, w, z, y) - + let zxy = Vector3(z, x, y) let zxw = Vector3(z, x, w) let zyx = Vector3(z, y, x) let zyw = Vector3(z, y, w) let zwx = Vector3(z, w, x) let zwy = Vector3(z, w, y) - + let zx = Vector2(z, x) let zy = Vector2(z, y) let zw = Vector2(z, w) - + // Z primary Assert.Equal(zxyw, v.Zxyw) Assert.Equal(zxwy, v.Zxwy) @@ -594,21 +594,21 @@ module Vector4 = Assert.Equal(zwxy, v.Zwxy) Assert.Equal(zwyx, v.Zwyx) Assert.Equal(zwzy, v.Zwzy) - + Assert.Equal(zxy, v.Zxy) Assert.Equal(zxw, v.Zxw) Assert.Equal(zyx, v.Zyx) Assert.Equal(zyw, v.Zyw) Assert.Equal(zwx, v.Zwx) Assert.Equal(zwy, v.Zwy) - + Assert.Equal(zx, v.Zx) Assert.Equal(zy, v.Zy) Assert.Equal(zw, v.Zw) - + [] let ``Vector swizzling returns the correct composite for W-primary components`` (x, y, z, w) = - + let v = Vector4(x, y, z, w) let wxyz = Vector4(w, x, y, z) @@ -618,14 +618,14 @@ module Vector4 = let wzxy = Vector4(w, z, x, y) let wzyx = Vector4(w, z, y, x) let wzyw = Vector4(w, z, y, w) - + let wxy = Vector3(w, x, y) let wxz = Vector3(w, x, z) let wyx = Vector3(w, y, x) let wyz = Vector3(w, y, z) let wzx = Vector3(w, z, x) let wzy = Vector3(w, z, y) - + let wx = Vector2(w, x) let wy = Vector2(w, y) let wz = Vector2(w, z) @@ -638,18 +638,18 @@ module Vector4 = Assert.Equal(wzxy, v.Wzxy) Assert.Equal(wzyx, v.Wzyx) Assert.Equal(wzyw, v.Wzyw) - + Assert.Equal(wxy, v.Wxy) Assert.Equal(wxz, v.Wxz) Assert.Equal(wyx, v.Wyx) Assert.Equal(wyz, v.Wyz) Assert.Equal(wzx, v.Wzx) Assert.Equal(wzy, v.Wzy) - + Assert.Equal(wx, v.Wx) Assert.Equal(wy, v.Wy) Assert.Equal(wz, v.Wz) - + [ |])>] module Interpolation = // @@ -657,40 +657,40 @@ module Vector4 = let ``Linear interpolation is by component`` (a : Vector4, b : Vector4, q) = let blend = q - - let rX = blend * (b.X - a.X) + a.X + + let rX = blend * (b.X - a.X) + a.X let rY = blend * (b.Y - a.Y) + a.Y let rZ = blend * (b.Z - a.Z) + a.Z let rW = blend * (b.W - a.W) + a.W let vExp = Vector4(rX, rY, rZ, rW) - + Assert.Equal(vExp, Vector4.Lerp(a, b, q)) - + let vRes = Vector4.Lerp(ref a, ref b, q) Assert.Equal(vExp, vRes) - + [] let ``Barycentric interpolation follows the barycentric formula`` (a : Vector4, b : Vector4, c : Vector4, u, v) = let r = a + u * (b - a) + v * (c - a) - + Assert.Equal(r, Vector4.BaryCentric(a, b, c, u, v)) - + let vRes = Vector4.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - + [ |])>] module ``Vector products`` = // [] let ``Dot product method follows the dot product formula`` (a : Vector4, b : Vector4) = let dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W - + Assert.Equal(dot, Vector4.Dot(a, b)); - + let vRes = Vector4.Dot(ref a, ref b) Assert.Equal(dot, vRes) - + [ |])>] module ``Component min and max`` = // @@ -698,112 +698,112 @@ module Vector4 = let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, w, a, b, c, d) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(a, b, c, d) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector4.Min(v1, v2) - + if vMin = v1 then let v1ShorterThanv2 = l1 < l2 Assert.True(v1ShorterThanv2) - else + else let v2ShorterThanv1 = l2 < l1 - Assert.True(v2ShorterThanv1) - + Assert.True(v2ShorterThanv1) + [] let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, w, a, b, c, d) = let v1 = Vector4(x, y, z, w) let v2 = Vector4(a, b, c, d) - + let l1 = v1.LengthSquared let l2 = v2.LengthSquared - + let vMin = Vector4.Max(v1, v2) - + if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 + let v1LongerThanOrEqualTov2 = l1 >= l2 Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) - + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + [ |])>] module Clamping = // [] let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = let res = Vector4.Clamp(w, a, b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) - + [] let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector4, b : Vector4, w : Vector4) = let res = Vector4.Clamp(ref w, ref a, ref b) - + let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W - + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) - + [ |])>] - module ``Unit vectors``= + module ``Unit vectors``= // [] - let ``Unit X is correct`` = + let ``Unit X is correct`` = let unitX = Vector4((float32)1, (float32)0, (float32)0, (float32)0) - + Assert.Equal(Vector4.UnitX, unitX) - + [] - let ``Unit Y is correct`` = + let ``Unit Y is correct`` = let unitY = Vector4((float32)0, (float32)1, (float32)0, (float32)0) - + Assert.Equal(Vector4.UnitY, unitY) - + [] - let ``Unit Z is correct`` = + let ``Unit Z is correct`` = let unitZ = Vector4((float32)0, (float32)0, (float32)1, (float32)0) - + Assert.Equal(Vector4.UnitZ, unitZ) - + [] - let ``Unit W is correct`` = + let ``Unit W is correct`` = let unitW = Vector4((float32)0, (float32)0, (float32)0, (float32)1) - + Assert.Equal(Vector4.UnitW, unitW) - + [] - let ``Unit zero is correct`` = + let ``Unit zero is correct`` = let unitZero = Vector4((float32)0, (float32)0, (float32)0, (float32)0) - + Assert.Equal(Vector4.Zero, unitZero) - + [] - let ``Unit one is correct`` = + let ``Unit one is correct`` = let unitOne = Vector4((float32)1, (float32)1, (float32)1, (float32)1) - + Assert.Equal(Vector4.One, unitOne) - + [ |])>] - module Serialization = + module Serialization = // [] - let ``The absolute size of a Vector4 is always the size of its components`` (v : Vector4) = + let ``The absolute size of a Vector4 is always the size of its components`` (v : Vector4) = let expectedSize = sizeof * 4 - + Assert.Equal(expectedSize, Vector4.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) \ No newline at end of file From a2a9c922d4f36c45a15bce9f79d79472285bf6fd Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 21:26:34 +0200 Subject: [PATCH 41/66] Added transformation by quaternion test. --- tests/OpenTK.Tests/Vector3Tests.fs | 27 +++++++++++++++++++++++++-- tests/OpenTK.Tests/Vector4Tests.fs | 25 ++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 9c879b68..2d5b3cab 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -684,7 +684,7 @@ module Vector3 = [] let ``Unit one is correct`` = - let unitOne = Vector3((float32)1, (float32)1, (float32)1) + let unitOne = Vector3(1.0f, 1.0f, 1.0f) Assert.Equal(Vector3.One, unitOne) @@ -696,4 +696,27 @@ module Vector3 = let expectedSize = sizeof * 3 Assert.Equal(expectedSize, Vector3.SizeInBytes) - Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) \ No newline at end of file + Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) + + [ |])>] + module Transformation = + // + [] + let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, 0.0f) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector3(transformedQuat.X, transformedQuat.Y, transformedQuat.Z) + + Assert.Equal(transformedVector, Vector3.Transform(v, q)) + + [] + let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, 0.0f) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector3(transformedQuat.X, transformedQuat.Y,transformedQuat.Z) + + Assert.Equal(transformedVector, Vector3.Transform(ref v, ref q)) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 7033f2a7..2abb7bb7 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -806,4 +806,27 @@ module Vector4 = let expectedSize = sizeof * 4 Assert.Equal(expectedSize, Vector4.SizeInBytes) - Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) \ No newline at end of file + Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) + + [ |])>] + module Transformation = + // + [] + let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) + + Assert.Equal(transformedVector, Vector4.Transform(v, q)) + + [] + let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y,transformedQuat.Z, transformedQuat.W) + + Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) \ No newline at end of file From 5c4ef39c92c340de8147d7bd91676fbf9e890351 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 22:09:04 +0200 Subject: [PATCH 42/66] Removed fake casts. --- tests/OpenTK.Tests/Matrix4Tests.fs | 14 +++++++------- tests/OpenTK.Tests/Vector2Tests.fs | 6 +++--- tests/OpenTK.Tests/Vector3Tests.fs | 16 ++++++++-------- tests/OpenTK.Tests/Vector4Tests.fs | 20 ++++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 52b5d6b1..a025d7ea 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -42,22 +42,22 @@ module Matrix4 = Assert.Equal(a, A.M11) Assert.Equal(b, A.M12) Assert.Equal(c, A.M13) - Assert.Equal((float32)0, A.M14) + Assert.Equal(0.0f, A.M14) Assert.Equal(d, A.M21) Assert.Equal(e, A.M22) Assert.Equal(f, A.M23) - Assert.Equal((float32)0, A.M24) + Assert.Equal(0.0f, A.M24) Assert.Equal(g, A.M31) Assert.Equal(h, A.M32) Assert.Equal(i, A.M33) - Assert.Equal((float32)0, A.M34) + Assert.Equal(0.0f, A.M34) - Assert.Equal((float32)0, A.M41) - Assert.Equal((float32)0, A.M42) - Assert.Equal((float32)0, A.M43) - Assert.Equal((float32)1, A.M44) + Assert.Equal(0.0f, A.M41) + Assert.Equal(0.0f, A.M42) + Assert.Equal(0.0f, A.M43) + Assert.Equal(1.0f, A.M44) [] let ``Four-vector4 constructor sets all components to the correct values`` (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) = diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index adb4ab70..0bf0b30e 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -318,7 +318,7 @@ module Vector2 = [] let ``Vector inequality operator is by component`` (x, y) = let v1 = Vector2(x, y) - let v2 = Vector2(x + (float32)1 , y + (float32)1) + let v2 = Vector2(x + 1.0f , y + 1.0f) let inequality = v1 <> v2 Assert.True(inequality) @@ -556,7 +556,7 @@ module Vector2 = // [] let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = - let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) + let vectorQuat = Quaternion(v.X, v.Y, 0.0f, 0.0f) let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse @@ -566,7 +566,7 @@ module Vector2 = [] let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = - let vectorQuat = Quaternion(v.X, v.Y, (float32)0, (float32)0) + let vectorQuat = Quaternion(v.X, v.Y, 0.0f, 0.0f) let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 2d5b3cab..14cf0422 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -37,7 +37,7 @@ module Vector3 = Assert.Equal(a, v2.X) Assert.Equal(b, v2.Y) - Assert.Equal((float32)0, v2.Z) + Assert.Equal(0.0f, v2.Z) [] let ``Vector3 value constructor sets all components to the correct values`` (a, b, c) = @@ -413,7 +413,7 @@ module Vector3 = [] let ``Vector inequality operator is by component`` (x, y, z) = let v1 = Vector3(x, y, z) - let v2 = Vector3(x + (float32)1 , y + (float32)1, z + (float32)1) + let v2 = Vector3(x + 1.0f , y + 1.0f, z + 1.0f) let inequality = v1 <> v2 Assert.True(inequality) @@ -660,25 +660,25 @@ module Vector3 = // [] let ``Unit X is correct`` = - let unitX = Vector3((float32)1, (float32)0, (float32)0) + let unitX = Vector3(1.0f, 0.0f, 0.0f) Assert.Equal(Vector3.UnitX, unitX) [] let ``Unit Y is correct`` = - let unitY = Vector3((float32)0, (float32)1, (float32)0) + let unitY = Vector3(0.0f, 1.0f, 0.0f) Assert.Equal(Vector3.UnitY, unitY) [] let ``Unit Z is correct`` = - let unitZ = Vector3((float32)0, (float32)0, (float32)1) + let unitZ = Vector3(0.0f, 0.0f, 1.0f) Assert.Equal(Vector3.UnitZ, unitZ) [] let ``Unit zero is correct`` = - let unitZero = Vector3((float32)0, (float32)0, (float32)0) + let unitZero = Vector3(0.0f, 0.0f, 0.0f) Assert.Equal(Vector3.Zero, unitZero) @@ -707,7 +707,7 @@ module Vector3 = let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse - let transformedVector = Vector3(transformedQuat.X, transformedQuat.Y, transformedQuat.Z) + let transformedVector = transformedQuat.Xyz Assert.Equal(transformedVector, Vector3.Transform(v, q)) @@ -717,6 +717,6 @@ module Vector3 = let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse - let transformedVector = Vector3(transformedQuat.X, transformedQuat.Y,transformedQuat.Z) + let transformedVector = transformedQuat.Xyz Assert.Equal(transformedVector, Vector3.Transform(ref v, ref q)) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 2abb7bb7..ea6e0720 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -39,8 +39,8 @@ module Vector4 = Assert.Equal(x, v2.X) Assert.Equal(y, v2.Y) - Assert.Equal((float32)0, v2.Z) - Assert.Equal((float32)0, v2.W) + Assert.Equal(0.0f, v2.Z) + Assert.Equal(0.0f, v2.W) [] let ``Vector3 value constructor sets all components to the correct values`` (x, y, z) = @@ -54,7 +54,7 @@ module Vector4 = Assert.Equal(x, v2.X) Assert.Equal(y, v2.Y) Assert.Equal(z, v2.Z) - Assert.Equal((float32)0, v2.W) + Assert.Equal(0.0f, v2.W) [] let ``Vector3 value and scalar constructor sets all components to the correct values`` (x, y, z, w) = @@ -445,7 +445,7 @@ module Vector4 = [] let ``Vector inequality operator is by component`` (x, y, z, w) = let v1 = Vector4(x, y, z, w) - let v2 = Vector4(x + (float32)1 , y + (float32)1, z + (float32)1, w + (float32)1) + let v2 = Vector4(x + 1.0f , y + 1.0f, z + 1.0f, w + 1.0f) let inequality = v1 <> v2 Assert.True(inequality) @@ -764,37 +764,37 @@ module Vector4 = // [] let ``Unit X is correct`` = - let unitX = Vector4((float32)1, (float32)0, (float32)0, (float32)0) + let unitX = Vector4(1.0f, 0.0f, 0.0f, 0.0f) Assert.Equal(Vector4.UnitX, unitX) [] let ``Unit Y is correct`` = - let unitY = Vector4((float32)0, (float32)1, (float32)0, (float32)0) + let unitY = Vector4(0.0f, 1.0f, 0.0f, 0.0f) Assert.Equal(Vector4.UnitY, unitY) [] let ``Unit Z is correct`` = - let unitZ = Vector4((float32)0, (float32)0, (float32)1, (float32)0) + let unitZ = Vector4(0.0f, 0.0f, 1.0f, 0.0f) Assert.Equal(Vector4.UnitZ, unitZ) [] let ``Unit W is correct`` = - let unitW = Vector4((float32)0, (float32)0, (float32)0, (float32)1) + let unitW = Vector4(0.0f, 0.0f, 0.0f, 1.0f) Assert.Equal(Vector4.UnitW, unitW) [] let ``Unit zero is correct`` = - let unitZero = Vector4((float32)0, (float32)0, (float32)0, (float32)0) + let unitZero = Vector4(0.0f, 0.0f, 0.0f, 0.0f) Assert.Equal(Vector4.Zero, unitZero) [] let ``Unit one is correct`` = - let unitOne = Vector4((float32)1, (float32)1, (float32)1, (float32)1) + let unitOne = Vector4(1.0f, 1.0f, 1.0f, 1.0f) Assert.Equal(Vector4.One, unitOne) From c64327b8a9148b86aae6052381a226e9e1bd5179 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Thu, 1 Jun 2017 23:22:57 +0200 Subject: [PATCH 43/66] Increased delta bits and changed quaternion generator. --- tests/OpenTK.Tests/Assertions.fs | 2 +- tests/OpenTK.Tests/Generators.fs | 4 ++-- tests/OpenTK.Tests/Vector3Tests.fs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index 8b7a292c..e4e1c412 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 6 + let private BitAccuracy = 9 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs index e7496c44..ec19a3c1 100644 --- a/tests/OpenTK.Tests/Generators.fs +++ b/tests/OpenTK.Tests/Generators.fs @@ -38,8 +38,8 @@ module private Generators = let quat = singleArb - |> Gen.four - |> Gen.map Quaternion + |> Gen.three + |> Gen.map (fun (x,y,z) -> Quaternion(x,y,z,0.0f) |> Quaternion.Normalize) |> Arb.fromGen let mat2 = diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 14cf0422..37bac293 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -709,7 +709,7 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.Equal(transformedVector, Vector3.Transform(v, q)) + Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(v, q)) [] let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = @@ -719,4 +719,17 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.Equal(transformedVector, Vector3.Transform(ref v, ref q)) \ No newline at end of file + Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(ref v, ref q)) + + [] + let ``Transformation by identity quaternion does not alter vector`` (v : Vector3) = + let q = Quaternion.Identity + let vectorQuat = Quaternion(v.X, v.Y, v.Z, 0.0f) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = transformedQuat.Xyz + + Assert.ApproximatelyEqual(v, transformedVector) + Assert.ApproximatelyEqual(v, Vector3.Transform(v, q)) + Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(v, q)) \ No newline at end of file From c12eefa0cf0260160341ff616d69ba505e58eade Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 10:39:13 +0200 Subject: [PATCH 44/66] Added extra filtering to generated Quaternions. --- tests/OpenTK.Tests/Generators.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs index ec19a3c1..cbcdd929 100644 --- a/tests/OpenTK.Tests/Generators.fs +++ b/tests/OpenTK.Tests/Generators.fs @@ -40,6 +40,7 @@ module private Generators = singleArb |> Gen.three |> Gen.map (fun (x,y,z) -> Quaternion(x,y,z,0.0f) |> Quaternion.Normalize) + |> Gen.filter (fun q -> not <| (Single.IsNaN q.Length || Single.IsInfinity q.Length )) |> Arb.fromGen let mat2 = From 0cd47f2c3c9e791dbafa1f09565f22cc31dfff52 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 10:56:02 +0200 Subject: [PATCH 45/66] Added test of multiplication operators. --- tests/OpenTK.Tests/Vector2Tests.fs | 11 +++++++++++ tests/OpenTK.Tests/Vector3Tests.fs | 10 ++++++++++ tests/OpenTK.Tests/Vector4Tests.fs | 16 +++++++++++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 0bf0b30e..fccdbc63 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -574,6 +574,17 @@ module Vector2 = Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) +// TODO: Implement multiplication operator for Vector2 and Quaternion +// [] +// let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = +// let vectorQuat = Quaternion(v.X, v.Y, 0.0f, 0.0f) +// let inverse = Quaternion.Invert(q) +// +// let transformedQuat = q * vectorQuat * inverse +// let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) +// +// Assert.Equal(transformedVector, q * v) + [ |])>] module Serialization = // diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 37bac293..851358cc 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -721,6 +721,16 @@ module Vector3 = Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(ref v, ref q)) + [] + let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, 0.0f) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = transformedQuat.Xyz + + Assert.ApproximatelyEqual(transformedVector, q * v) + [] let ``Transformation by identity quaternion does not alter vector`` (v : Vector3) = let q = Quaternion.Identity diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index ea6e0720..0cf78ad0 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -812,7 +812,7 @@ module Vector4 = module Transformation = // [] - let ``Transformation by quaternion is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let ``Transformation by quaternion with static method is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) let inverse = Quaternion.Invert(q) @@ -822,11 +822,21 @@ module Vector4 = Assert.Equal(transformedVector, Vector4.Transform(v, q)) [] - let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let ``Transformation by quaternion with static method by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) let inverse = Quaternion.Invert(q) let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y,transformedQuat.Z, transformedQuat.W) - Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) \ No newline at end of file + Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) + + [] + let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = + let vectorQuat = Quaternion(v.X, v.Y, v.Z, v.W) + let inverse = Quaternion.Invert(q) + + let transformedQuat = q * vectorQuat * inverse + let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) + + Assert.Equal(transformedVector, q * v) \ No newline at end of file From 87dcb3144a85e5c397c188b17c7a2f50d46cf3ca Mon Sep 17 00:00:00 2001 From: varon Date: Fri, 2 Jun 2017 13:48:29 +0200 Subject: [PATCH 46/66] Fix compile inference error under VS2015 --- tests/OpenTK.Tests/Assertions.fs | 3 +++ tests/OpenTK.Tests/Matrix4Tests.fs | 28 ++++++++++++++++------------ tests/OpenTK.Tests/Vector2Tests.fs | 19 ++++--------------- tests/OpenTK.Tests/Vector3Tests.fs | 8 ++++---- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index e4e1c412..f47e7ee1 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -29,3 +29,6 @@ type internal Assert = static member ApproximatelyEqual(a : float32,b : float32) = if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b) + + + static member ThrowsIndexExn(f:unit -> unit) = Assert.Throws(f) |> ignore diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index a025d7ea..706a839e 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -333,31 +333,35 @@ module Matrix4 = Assert.Equal(o, A.[3, 2]) Assert.Equal(p, A.[3, 3]) + [] let ``Indexed set operator throws exception for negative indices`` (b : Matrix4, x : float32) = let mutable a = b - (fun() -> a.[-1, 2] <- x) |> Assert.Throws |> ignore - (fun() -> a.[1, -2] <- x) |> Assert.Throws |> ignore - (fun() -> a.[-1, -2] <- x) |> Assert.Throws |> ignore + + + + (fun() -> a.[-1, 2] <- x) |> Assert.ThrowsIndexExn + (fun() -> a.[1, -2] <- x) |> Assert.ThrowsIndexExn + (fun() -> a.[-1, -2] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for negative indices`` (a : Matrix4) = - (fun() -> a.[-1, 2] |> ignore) |> Assert.Throws |> ignore - (fun() -> a.[1, -2] |> ignore) |> Assert.Throws |> ignore - (fun() -> a.[-1, -2] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[-1, 2] |> ignore) |> Assert.ThrowsIndexExn + (fun() -> a.[1, -2] |> ignore) |> Assert.ThrowsIndexExn + (fun() -> a.[-1, -2] |> ignore) |> Assert.ThrowsIndexExn [] let ``Indexed set operator throws exception for large indices`` (a : Matrix4, x : float32) = let mutable b = a - (fun() -> b.[5, 2] <- x) |> Assert.Throws |> ignore - (fun() -> b.[1, 6] <- x) |> Assert.Throws |> ignore - (fun() -> b.[7, 12] <- x) |> Assert.Throws |> ignore + (fun() -> b.[5, 2] <- x) |> Assert.ThrowsIndexExn + (fun() -> b.[1, 6] <- x) |> Assert.ThrowsIndexExn + (fun() -> b.[7, 12] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for large indices`` (a : Matrix4) = - (fun() -> a.[5, 2] |> ignore) |> Assert.Throws |> ignore - (fun() -> a.[1, 6] |> ignore) |> Assert.Throws |> ignore - (fun() -> a.[7, 12] |> ignore) |> Assert.Throws |> ignore + (fun() -> a.[5, 2] |> ignore) |> Assert.ThrowsIndexExn + (fun() -> a.[1, 6] |> ignore) |> Assert.ThrowsIndexExn + (fun() -> a.[7, 12] |> ignore) |> Assert.ThrowsIndexExn [ |])>] module ``Row and column properties`` = diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index fccdbc63..724bc553 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -106,25 +106,25 @@ module Vector2 = let ``Indexed set operator throws exception for negative indices`` (x, y) = let mutable v = Vector2(x, y) - (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + (fun() -> v.[-1] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for negative indices`` (x, y) = let mutable v = Vector2(x, y) - (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[-1] |> ignore) |> Assert.ThrowsIndexExn [] let ``Indexed set operator throws exception for large indices`` (x, y) = let mutable v = Vector2(x, y) - (fun() -> v.[2] <- x) |> Assert.Throws |> ignore + (fun() -> v.[2] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for large indices`` (x, y) = let mutable v = Vector2(x, y) - (fun() -> v.[2] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[2] |> ignore) |> Assert.ThrowsIndexExn [ |])>] module ``Simple Properties`` = @@ -574,17 +574,6 @@ module Vector2 = Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) -// TODO: Implement multiplication operator for Vector2 and Quaternion -// [] -// let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = -// let vectorQuat = Quaternion(v.X, v.Y, 0.0f, 0.0f) -// let inverse = Quaternion.Invert(q) -// -// let transformedQuat = q * vectorQuat * inverse -// let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) -// -// Assert.Equal(transformedVector, q * v) - [ |])>] module Serialization = // diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 851358cc..9f89ba48 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -80,25 +80,25 @@ module Vector3 = let ``Indexed set operator throws exception for negative indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + (fun() -> v.[-1] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for negative indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[-1] |> ignore) |> Assert.ThrowsIndexExn [] let ``Indexed set operator throws exception for large indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - (fun() -> v.[4] <- x) |> Assert.Throws |> ignore + (fun() -> v.[4] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for large indices`` (x, y, z) = let mutable v = Vector3(x, y, z) - (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn [ |])>] module Length = From 92d4c942f40dc4a483010af3d33159491a721d9a Mon Sep 17 00:00:00 2001 From: varon Date: Fri, 2 Jun 2017 13:56:11 +0200 Subject: [PATCH 47/66] Fix additional compile inference errors under VS2015 --- tests/OpenTK.Tests/Vector4Tests.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 0cf78ad0..4a6fada3 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -101,25 +101,25 @@ module Vector4 = let ``Indexed set operator throws exception for negative indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - (fun() -> v.[-1] <- x) |> Assert.Throws |> ignore + (fun() -> v.[-1] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for negative indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - (fun() -> v.[-1] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[-1] |> ignore) |> Assert.ThrowsIndexExn [] let ``Indexed set operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - (fun() -> v.[4] <- x) |> Assert.Throws |> ignore + (fun() -> v.[4] <- x) |> Assert.ThrowsIndexExn [] let ``Indexed get operator throws exception for large indices`` (x, y, z, w) = let mutable v = Vector4(x, y, z, w) - (fun() -> v.[4] |> ignore) |> Assert.Throws |> ignore + (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn [ |])>] module Length = From 7c298cc43d56fe868a13d341ac893f15f040ea8b Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 19:32:22 +0200 Subject: [PATCH 48/66] Eliminated additional step for division operations. --- src/OpenTK/Math/Vector2.cs | 9 ++++----- src/OpenTK/Math/Vector2d.cs | 9 ++++----- src/OpenTK/Math/Vector3.cs | 17 ++++++++--------- src/OpenTK/Math/Vector3d.cs | 13 ++++++------- src/OpenTK/Math/Vector4.cs | 31 ++++++++++++++----------------- src/OpenTK/Math/Vector4d.cs | 15 +++++++-------- 6 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index d7f81427..463296aa 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -623,7 +623,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2 vector, float scale, out Vector2 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1074,7 +1074,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides the specified instance by a scalar. /// @@ -1083,9 +1083,8 @@ namespace OpenTK /// Result of the division. public static Vector2 operator /(Vector2 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; + vec.X /= scale; + vec.Y /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index 3993aafa..82822658 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -541,7 +541,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2d vector, double scale, out Vector2d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -936,7 +936,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides an instance by a scalar. /// @@ -945,9 +945,8 @@ namespace OpenTK /// The result of the operation. public static Vector2d operator /(Vector2d vec, double f) { - double mult = 1.0 / f; - vec.X *= mult; - vec.Y *= mult; + vec.X /= f; + vec.Y /= f; return vec; } diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index 000a3698..d47bfdff 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -629,7 +629,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3 vector, float scale, out Vector3 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1270,10 +1270,10 @@ namespace OpenTK { Vector4 result; - result.X = - vector.X * worldViewProjection.M11 + - vector.Y * worldViewProjection.M21 + - vector.Z * worldViewProjection.M31 + + result.X = + vector.X * worldViewProjection.M11 + + vector.Y * worldViewProjection.M21 + + vector.Z * worldViewProjection.M31 + worldViewProjection.M41; result.Y = @@ -1574,10 +1574,9 @@ namespace OpenTK /// The result of the calculation. public static Vector3 operator /(Vector3 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 556b9ab9..d05a0c60 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -627,7 +627,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3d vector, double scale, out Vector3d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1372,7 +1372,7 @@ namespace OpenTK vec.Z *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1386,7 +1386,7 @@ namespace OpenTK vec.Z *= scale.Z; return vec; } - + /// /// Divides an instance by a scalar. /// @@ -1395,10 +1395,9 @@ namespace OpenTK /// The result of the calculation. public static Vector3d operator /(Vector3d vec, double scale) { - double mult = 1 / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index a821031e..6ccac390 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -514,11 +514,10 @@ namespace OpenTK /// Result of the division public static Vector4 Div(Vector4 a, float f) { - float mult = 1.0f / f; - a.X *= mult; - a.Y *= mult; - a.Z *= mult; - a.W *= mult; + a.X /= f; + a.Y /= f; + a.Z /= f; + a.W /= f; return a; } @@ -530,11 +529,10 @@ namespace OpenTK /// Result of the division public static void Div(ref Vector4 a, float f, out Vector4 result) { - float mult = 1.0f / f; - result.X = a.X * mult; - result.Y = a.Y * mult; - result.Z = a.Z * mult; - result.W = a.W * mult; + result.X = a.X / f; + result.Y = a.Y / f; + result.Z = a.Z / f; + result.W = a.W / f; } #endregion @@ -667,7 +665,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4 vector, float scale, out Vector4 result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1514,7 +1512,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1577,11 +1575,10 @@ namespace OpenTK /// The result of the calculation. public static Vector4 operator /(Vector4 vec, float scale) { - float mult = 1.0f / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; - vec.W *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; + vec.W /= scale; return vec; } diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index facc329d..427291cc 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -175,7 +175,7 @@ namespace OpenTK #endregion #region Public Members - + /// /// Gets or sets the value at the index of the Vector. /// @@ -669,7 +669,7 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4d vector, double scale, out Vector4d result) { - Multiply(ref vector, 1 / scale, out result); + result = vector / scale; } /// @@ -1493,7 +1493,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1517,11 +1517,10 @@ namespace OpenTK /// The result of the calculation. public static Vector4d operator /(Vector4d vec, double scale) { - double mult = 1 / scale; - vec.X *= mult; - vec.Y *= mult; - vec.Z *= mult; - vec.W *= mult; + vec.X /= scale; + vec.Y /= scale; + vec.Z /= scale; + vec.W /= scale; return vec; } From bea15cd250ed7961dfc4c6d9b5703e2cecf7659c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 19:42:08 +0200 Subject: [PATCH 49/66] Obsoleted Min/Max methods. --- src/OpenTK/Math/Vector2.cs | 4 +++- src/OpenTK/Math/Vector2d.cs | 6 +++++- src/OpenTK/Math/Vector3.cs | 10 ++++++---- src/OpenTK/Math/Vector3d.cs | 6 ++++-- src/OpenTK/Math/Vector4.cs | 6 +++++- src/OpenTK/Math/Vector4d.cs | 8 ++++++-- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index d7f81427..60474396 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -717,6 +717,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector2 Min(Vector2 left, Vector2 right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -732,6 +733,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector2 Max(Vector2 left, Vector2 right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1074,7 +1076,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides the specified instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index 3993aafa..a57f18e9 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -577,6 +577,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector2d Min(Vector2d a, Vector2d b) { a.X = a.X < b.X ? a.X : b.X; @@ -590,6 +591,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector2d a, ref Vector2d b, out Vector2d result) { result.X = a.X < b.X ? a.X : b.X; @@ -606,6 +608,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector2d Max(Vector2d a, Vector2d b) { a.X = a.X > b.X ? a.X : b.X; @@ -619,6 +622,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector2d a, ref Vector2d b, out Vector2d result) { result.X = a.X > b.X ? a.X : b.X; @@ -936,7 +940,7 @@ namespace OpenTK vec.Y *= scale.Y; return vec; } - + /// /// Divides an instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index 000a3698..e7eb009d 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -727,6 +727,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector3 Min(Vector3 left, Vector3 right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -742,6 +743,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector3 Max(Vector3 left, Vector3 right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1270,10 +1272,10 @@ namespace OpenTK { Vector4 result; - result.X = - vector.X * worldViewProjection.M11 + - vector.Y * worldViewProjection.M21 + - vector.Z * worldViewProjection.M31 + + result.X = + vector.X * worldViewProjection.M11 + + vector.Y * worldViewProjection.M21 + + vector.Z * worldViewProjection.M31 + worldViewProjection.M41; result.Y = diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 556b9ab9..76202870 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -725,6 +725,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMin() instead.")] public static Vector3d Min(Vector3d left, Vector3d right) { return left.LengthSquared < right.LengthSquared ? left : right; @@ -740,6 +741,7 @@ namespace OpenTK /// Left operand /// Right operand /// The minimum Vector3 + [Obsolete("Use MagnitudeMax() instead.")] public static Vector3d Max(Vector3d left, Vector3d right) { return left.LengthSquared >= right.LengthSquared ? left : right; @@ -1372,7 +1374,7 @@ namespace OpenTK vec.Z *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// @@ -1386,7 +1388,7 @@ namespace OpenTK vec.Z *= scale.Z; return vec; } - + /// /// Divides an instance by a scalar. /// diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index a821031e..ff09f987 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -703,6 +703,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector4 Min(Vector4 a, Vector4 b) { a.X = a.X < b.X ? a.X : b.X; @@ -718,6 +719,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector4 a, ref Vector4 b, out Vector4 result) { result.X = a.X < b.X ? a.X : b.X; @@ -736,6 +738,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector4 Max(Vector4 a, Vector4 b) { a.X = a.X > b.X ? a.X : b.X; @@ -751,6 +754,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector4 a, ref Vector4 b, out Vector4 result) { result.X = a.X > b.X ? a.X : b.X; @@ -1514,7 +1518,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index facc329d..03801497 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -175,7 +175,7 @@ namespace OpenTK #endregion #region Public Members - + /// /// Gets or sets the value at the index of the Vector. /// @@ -705,6 +705,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static Vector4d Min(Vector4d a, Vector4d b) { a.X = a.X < b.X ? a.X : b.X; @@ -720,6 +721,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise minimum + [Obsolete("Use ComponentMin() instead.")] public static void Min(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X < b.X ? a.X : b.X; @@ -738,6 +740,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static Vector4d Max(Vector4d a, Vector4d b) { a.X = a.X > b.X ? a.X : b.X; @@ -753,6 +756,7 @@ namespace OpenTK /// First operand /// Second operand /// The component-wise maximum + [Obsolete("Use ComponentMax() instead.")] public static void Max(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X > b.X ? a.X : b.X; @@ -1493,7 +1497,7 @@ namespace OpenTK vec.W *= scale; return vec; } - + /// /// Component-wise multiplication between the specified instance by a scale vector. /// From 809e7b4379ebeaebe547e63f88bcaff94e5391d4 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:31:54 +0200 Subject: [PATCH 50/66] Improved documentation. --- src/OpenTK/Math/Vector2.cs | 58 +++++++++++++++++ src/OpenTK/Math/Vector2d.cs | 112 ++++++++++++++++++++++++++++++++ src/OpenTK/Math/Vector3.cs | 58 +++++++++++++++++ src/OpenTK/Math/Vector3d.cs | 54 ++++++++++++++++ src/OpenTK/Math/Vector4.cs | 124 ++++++++++++++++++++++++++++++++++++ src/OpenTK/Math/Vector4d.cs | 120 ++++++++++++++++++++++++++++++++++ 6 files changed, 526 insertions(+) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index 60474396..c1e2c2ae 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -709,6 +709,64 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector2 + public static Vector2 MagnitudeMin(Vector2 left, Vector2 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector2 + public static void MagnitudeMin(ref Vector2 left, ref Vector2 right, out Vector2 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector2 + public static Vector2 MagnitudeMax(Vector2 left, Vector2 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector2 + public static void MagnitudeMax(ref Vector2 left, ref Vector2 right, out Vector2 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index a57f18e9..df2abedb 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -631,6 +631,118 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector2d ComponentMin(Vector2d a, Vector2d b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector2d ComponentMax(Vector2d a, Vector2d b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector2d a, ref Vector2d b, out Vector2d result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector2d + public static Vector2d MagnitudeMin(Vector2d left, Vector2d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector2d + public static void MagnitudeMin(ref Vector2d left, ref Vector2d right, out Vector2d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector2d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector2d + public static Vector2d MagnitudeMax(Vector2d left, Vector2d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector2d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector2d + public static void MagnitudeMax(ref Vector2d left, ref Vector2d right, out Vector2d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index e7eb009d..b2301f7e 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -719,6 +719,64 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector3 + public static Vector3 MagnitudeMin(Vector3 left, Vector3 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector3 + public static void MagnitudeMin(ref Vector3 left, ref Vector3 right, out Vector3 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector3 + public static Vector3 MagnitudeMax(Vector3 left, Vector3 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector3 + public static void MagnitudeMax(ref Vector3 left, ref Vector3 right, out Vector3 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 76202870..67f307e0 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -717,6 +717,60 @@ namespace OpenTK #endregion + #region MagnitudeMin + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector3d + public static Vector3d MagnitudeMin(Vector3d left, Vector3d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector3d + public static void MagnitudeMin(ref Vector3d left, ref Vector3d right, out Vector3d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector3d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector3d + public static Vector3d MagnitudeMax(Vector3d left, Vector3d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector3d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector3d + public static void MagnitudeMax(ref Vector3d left, ref Vector3d right, out Vector3d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Min /// diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index ff09f987..b2f13fb3 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -765,6 +765,130 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector4 ComponentMin(Vector4 a, Vector4 b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + a.Z = a.Z < b.Z ? a.Z : b.Z; + a.W = a.W < b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + result.Z = a.Z < b.Z ? a.Z : b.Z; + result.W = a.W < b.W ? a.W : b.W; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector4 ComponentMax(Vector4 a, Vector4 b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + a.Z = a.Z > b.Z ? a.Z : b.Z; + a.W = a.W > b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector4 a, ref Vector4 b, out Vector4 result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + result.Z = a.Z > b.Z ? a.Z : b.Z; + result.W = a.W > b.W ? a.W : b.W; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector4 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The minimum Vector4 + public static Vector4 MagnitudeMin(Vector4 left, Vector4 right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4 with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector4 + public static void MagnitudeMin(ref Vector4 left, ref Vector4 right, out Vector4 result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector4 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The maximum Vector4 + public static Vector4 MagnitudeMax(Vector4 left, Vector4 right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4 with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector4 + public static void MagnitudeMax(ref Vector4 left, ref Vector4 right, out Vector4 result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index 03801497..a9d385dd 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -767,6 +767,126 @@ namespace OpenTK #endregion + #region ComponentMin + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static Vector4d ComponentMin(Vector4d a, Vector4d b) + { + a.X = a.X < b.X ? a.X : b.X; + a.Y = a.Y < b.Y ? a.Y : b.Y; + a.Z = a.Z < b.Z ? a.Z : b.Z; + a.W = a.W < b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise minimum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise minimum + public static void ComponentMin(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result.X = a.X < b.X ? a.X : b.X; + result.Y = a.Y < b.Y ? a.Y : b.Y; + result.Z = a.Z < b.Z ? a.Z : b.Z; + result.W = a.W < b.W ? a.W : b.W; + } + + #endregion + + #region ComponentMax + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static Vector4d ComponentMax(Vector4d a, Vector4d b) + { + a.X = a.X > b.X ? a.X : b.X; + a.Y = a.Y > b.Y ? a.Y : b.Y; + a.Z = a.Z > b.Z ? a.Z : b.Z; + a.W = a.W > b.W ? a.W : b.W; + return a; + } + + /// + /// Calculate the component-wise maximum of two vectors + /// + /// First operand + /// Second operand + /// The component-wise maximum + public static void ComponentMax(ref Vector4d a, ref Vector4d b, out Vector4d result) + { + result.X = a.X > b.X ? a.X : b.X; + result.Y = a.Y > b.Y ? a.Y : b.Y; + result.Z = a.Z > b.Z ? a.Z : b.Z; + result.W = a.W > b.W ? a.W : b.W; + } + + #endregion + + #region MagnitudeMin + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector4d + public static Vector4d MagnitudeMin(Vector4d left, Vector4d right) + { + return left.LengthSquared < right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise minimum + /// The minimum Vector4d + public static void MagnitudeMin(ref Vector4d left, ref Vector4d right, out Vector4d result) + { + result = left.LengthSquared < right.LengthSquared ? left : right; + } + + #endregion + + #region MagnitudeMax + + /// + /// Returns the Vector4d with the minimum magnitude + /// + /// Left operand + /// Right operand + /// The minimum Vector4d + public static Vector4d MagnitudeMax(Vector4d left, Vector4d right) + { + return left.LengthSquared >= right.LengthSquared ? left : right; + } + + /// + /// Returns the Vector4d with the maximum magnitude + /// + /// Left operand + /// Right operand + /// The magnitude-wise maximum + /// The maximum Vector4d + public static void MagnitudeMax(ref Vector4d left, ref Vector4d right, out Vector4d result) + { + result = left.LengthSquared >= right.LengthSquared ? left : right; + } + + #endregion + #region Clamp /// From 28bede6ca1d1dc63f56a0af98588e6c61c7e9cd8 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:32:16 +0200 Subject: [PATCH 51/66] Added filtering for vector generation to only produce valid vectors. --- tests/OpenTK.Tests/Generators.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/OpenTK.Tests/Generators.fs b/tests/OpenTK.Tests/Generators.fs index cbcdd929..39200f5b 100644 --- a/tests/OpenTK.Tests/Generators.fs +++ b/tests/OpenTK.Tests/Generators.fs @@ -22,18 +22,21 @@ module private Generators = singleArb |> Gen.two |> Gen.map Vector2 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let vec3 = singleArb |> Gen.three |> Gen.map Vector3 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let vec4 = singleArb |> Gen.four |> Gen.map Vector4 + |> Gen.filter (fun v -> not <| (Single.IsNaN v.Length || Single.IsInfinity v.Length )) |> Arb.fromGen let quat = From c3fa66eb15da1f58145315ac7e21d8a5ff467d58 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:33:00 +0200 Subject: [PATCH 52/66] Implemented all ComponentMin/Max and MagnitudeMin/Max tests. --- tests/OpenTK.Tests/Vector2Tests.fs | 145 +++++++++++++------------- tests/OpenTK.Tests/Vector3Tests.fs | 161 ++++++++++++++--------------- tests/OpenTK.Tests/Vector4Tests.fs | 88 ++++++++++++++-- 3 files changed, 231 insertions(+), 163 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index fccdbc63..fd9fb6e3 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -462,94 +462,99 @@ module Vector2 = Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); + [ |])>] + module ``Magnitude min and max`` = + // + [] + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMin(v1, v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMax(v1, v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector2.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + [ |])>] module ``Component min and max`` = // [] - let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMin = Vector2.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) [] - let ``ComponentMax produces a new vector from the largest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMax = Vector2.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) [] - let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMin = Vector2.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) [] - let ``ComponentMax by reference produces a new vector from the largest components of the given vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector2, v2: Vector2) = let vMax = Vector2.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector2.Min(v1, v2) - - if l1 < l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - - [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, u, w) = - let v1 = Vector2(x, y) - let v2 = Vector2(u, w) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector2.Max(v1, v2) - - if l1 >= l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) [ |])>] module Transformation = diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 851358cc..36713dd9 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -527,106 +527,103 @@ module Vector3 = let vRes = Vector3.Cross(ref a, ref b) Assert.Equal(cross, vRes) + [ |])>] + module ``Magnitude min and max`` = + // + [] + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMin(v1, v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMax(v1, v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector3.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + [ |])>] module ``Component min and max`` = // [] - let ``ComponentMin produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMin = Vector3.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) - - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) [] - let ``ComponentMax producing a new vector from the largest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMax = Vector3.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) [] - let ``ComponentMin by reference produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMin = Vector3.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) - - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) - - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) [] - let ``ComponentMax produces a new vector from the smallest components of the given vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector3, v2: Vector3) = let vMax = Vector3.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) - - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) - - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) - - [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector3.Min(v1, v2) - - if l1 < l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) - - [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, u, w, q) = - let v1 = Vector3(x, y, z) - let v2 = Vector3(u, w, q) - - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared - - let vMin = Vector3.Max(v1, v2) - - if l1 >= l2 then - let equalsFirst = vMin = v1 - Assert.True(equalsFirst) - else - let equalsLast = vMin = v2 - Assert.True(equalsLast) + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) [ |])>] module Clamping = diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 0cf78ad0..90babe05 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -692,17 +692,14 @@ module Vector4 = Assert.Equal(dot, vRes) [ |])>] - module ``Component min and max`` = + module ``Magnitude min and max`` = // [] - let ``Min selects the vector with lesser magnitude given two vectors`` (x, y, z, w, a, b, c, d) = - let v1 = Vector4(x, y, z, w) - let v2 = Vector4(a, b, c, d) - + let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = let l1 = v1.LengthSquared let l2 = v2.LengthSquared - let vMin = Vector4.Min(v1, v2) + let vMin = Vector4.MagnitudeMin(v1, v2) if vMin = v1 then let v1ShorterThanv2 = l1 < l2 @@ -712,14 +709,11 @@ module Vector4 = Assert.True(v2ShorterThanv1) [] - let ``Max selects the vector with greater magnitude given two vectors`` (x, y, z, w, a, b, c, d) = - let v1 = Vector4(x, y, z, w) - let v2 = Vector4(a, b, c, d) - + let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = let l1 = v1.LengthSquared let l2 = v2.LengthSquared - let vMin = Vector4.Max(v1, v2) + let vMin = Vector4.MagnitudeMax(v1, v2) if vMin = v1 then let v1LongerThanOrEqualTov2 = l1 >= l2 @@ -728,6 +722,78 @@ module Vector4 = let v2LongerThanv1 = l2 > l1 Assert.True(v2LongerThanv1) + [] + let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.MagnitudeMin(ref v1, ref v2) + + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) + + [] + let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared + + let vMin = Vector4.MagnitudeMax(ref v1, ref v2) + + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) + + [ |])>] + module ``Component min and max`` = + // + [] + let ``ComponentMin creates a new vector from the smallest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMin = Vector4.ComponentMin(v1, v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 + + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) + Assert.True(isComponentSmallest vMin.W v1.W v2.W) + + [] + let ``ComponentMax creates a new vector from the greatest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMax = Vector4.ComponentMax(v1, v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 + + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) + Assert.True(isComponentLargest vMax.W v1.W v2.W) + + [] + let ``ComponentMin by reference creates a new vector from the smallest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMin = Vector4.ComponentMin(ref v1, ref v2) + let isComponentSmallest smallComp comp1 comp2 = smallComp <= comp1 && smallComp <= comp2 + + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) + Assert.True(isComponentSmallest vMin.Z v1.Z v2.Z) + Assert.True(isComponentSmallest vMin.W v1.W v2.W) + + [] + let ``ComponentMax by reference creates a new vector from the greatest components of given vectors`` (v1 : Vector4, v2: Vector4) = + let vMax = Vector4.ComponentMax(ref v1, ref v2) + let isComponentLargest largeComp comp1 comp2 = largeComp >= comp1 && largeComp >= comp2 + + Assert.True(isComponentLargest vMax.X v1.X v2.X) + Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) + Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) + Assert.True(isComponentLargest vMax.W v1.W v2.W) + + [ |])>] module Clamping = // From 5191491cdb042b5e3924df02108e8f12b2cf5021 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:34:13 +0200 Subject: [PATCH 53/66] Fixed MagnitudeMin test. --- tests/OpenTK.Tests/Vector4Tests.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 90babe05..9221adaa 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -705,8 +705,8 @@ module Vector4 = let v1ShorterThanv2 = l1 < l2 Assert.True(v1ShorterThanv2) else - let v2ShorterThanv1 = l2 < l1 - Assert.True(v2ShorterThanv1) + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = From 0438a0325ac355d9941634209b925204f06ca21c Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:35:14 +0200 Subject: [PATCH 54/66] Decreased approximation sensitivity again. --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index e4e1c412..62c9171f 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 9 + let private BitAccuracy = 10 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From b26242d1db425860b6b3bf612352d28a15e18c82 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:44:30 +0200 Subject: [PATCH 55/66] Decreased approximation sensitivity even more. --- tests/OpenTK.Tests/Assertions.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index 62c9171f..68eb2759 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,7 +9,7 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 10 + let private BitAccuracy = 13 let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) From d27a4671a53797a7e33f1704127438d363f6950f Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 22:25:44 +0200 Subject: [PATCH 56/66] Improved test name. --- tests/OpenTK.Tests/Vector4Tests.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 9221adaa..b4f48b38 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -799,27 +799,27 @@ module Vector4 = // [] let ``Clamping one vector between two other vectors clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = - let res = Vector4.Clamp(w, a, b) - let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + let res = Vector4.Clamp(w, a, b) + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) [] - let ``Clamping one vector between two other vectors by reference clamps all components`` (a : Vector4, b : Vector4, w : Vector4) = - let res = Vector4.Clamp(ref w, ref a, ref b) - + let ``Clamping one vector between two other vectors by reference clamps all components between corresponding components`` (a : Vector4, b : Vector4, w : Vector4) = let expX = if w.X < a.X then a.X else if w.X > b.X then b.X else w.X let expY = if w.Y < a.Y then a.Y else if w.Y > b.Y then b.Y else w.Y let expZ = if w.Z < a.Z then a.Z else if w.Z > b.Z then b.Z else w.Z let expW = if w.W < a.W then a.W else if w.W > b.W then b.W else w.W + let res = Vector4.Clamp(ref w, ref a, ref b) + Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) From 18976c898afce3041118c9bcd3b8f1ce36ece697 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 22:59:24 +0200 Subject: [PATCH 57/66] Improve comments. --- src/OpenTK/Math/Vector2d.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index df2abedb..f443a824 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -692,7 +692,8 @@ namespace OpenTK #region MagnitudeMin /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. /// /// Left operand /// Right operand @@ -703,7 +704,8 @@ namespace OpenTK } /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the second vector + /// is selected. /// /// Left operand /// Right operand @@ -719,7 +721,8 @@ namespace OpenTK #region MagnitudeMax /// - /// Returns the Vector2d with the minimum magnitude + /// Returns the Vector2d with the minimum magnitude. If the magnitudes are equal, the first vector + /// is selected. /// /// Left operand /// Right operand @@ -730,7 +733,8 @@ namespace OpenTK } /// - /// Returns the Vector2d with the maximum magnitude + /// Returns the Vector2d with the maximum magnitude. If the magnitudes are equal, the first vector + /// is selected. /// /// Left operand /// Right operand From 076d016648debe9237ee7c35aa03953957be483e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 23:09:27 +0200 Subject: [PATCH 58/66] Alter division by reference to be by component and not by operator. --- src/OpenTK/Math/Vector2.cs | 3 ++- src/OpenTK/Math/Vector2d.cs | 3 ++- src/OpenTK/Math/Vector3.cs | 4 +++- src/OpenTK/Math/Vector3d.cs | 4 +++- src/OpenTK/Math/Vector4.cs | 5 ++++- src/OpenTK/Math/Vector4d.cs | 5 ++++- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index 463296aa..29e6f970 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -623,7 +623,8 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2 vector, float scale, out Vector2 result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; } /// diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index 82822658..930d5f82 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -541,7 +541,8 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector2d vector, double scale, out Vector2d result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; } /// diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index d47bfdff..478a30fc 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -629,7 +629,9 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3 vector, float scale, out Vector3 result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; + result.Z = vector.Z / scale; } /// diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index d05a0c60..71f54cf6 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -627,7 +627,9 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector3d vector, double scale, out Vector3d result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; + result.Z = vector.Z / scale; } /// diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index 6ccac390..1ad97f05 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -665,7 +665,10 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4 vector, float scale, out Vector4 result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; + result.Z = vector.Z / scale; + result.W = vector.W / scale; } /// diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index 427291cc..57876cf0 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -669,7 +669,10 @@ namespace OpenTK /// Result of the operation. public static void Divide(ref Vector4d vector, double scale, out Vector4d result) { - result = vector / scale; + result.X = vector.X / scale; + result.Y = vector.Y / scale; + result.Z = vector.Z / scale; + result.W = vector.W / scale; } /// From 4f50ea8bee392237de221ccce6690d266fbce8ce Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sat, 3 Jun 2017 15:14:39 +0200 Subject: [PATCH 59/66] Improved ComponentMin/Max documentation. --- src/OpenTK/Math/Vector2.cs | 8 ++++---- src/OpenTK/Math/Vector2d.cs | 8 ++++---- src/OpenTK/Math/Vector3.cs | 8 ++++---- src/OpenTK/Math/Vector3d.cs | 8 ++++---- src/OpenTK/Math/Vector4.cs | 8 ++++---- src/OpenTK/Math/Vector4d.cs | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/OpenTK/Math/Vector2.cs b/src/OpenTK/Math/Vector2.cs index c1e2c2ae..b24f8d67 100644 --- a/src/OpenTK/Math/Vector2.cs +++ b/src/OpenTK/Math/Vector2.cs @@ -654,7 +654,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -667,7 +667,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -683,7 +683,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -696,7 +696,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector2d.cs b/src/OpenTK/Math/Vector2d.cs index f443a824..069ac10c 100644 --- a/src/OpenTK/Math/Vector2d.cs +++ b/src/OpenTK/Math/Vector2d.cs @@ -634,7 +634,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -647,7 +647,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -663,7 +663,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -676,7 +676,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector3.cs b/src/OpenTK/Math/Vector3.cs index b2301f7e..e0abc54e 100644 --- a/src/OpenTK/Math/Vector3.cs +++ b/src/OpenTK/Math/Vector3.cs @@ -660,7 +660,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -674,7 +674,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -691,7 +691,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -705,7 +705,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector3d.cs b/src/OpenTK/Math/Vector3d.cs index 67f307e0..0be7f1c9 100644 --- a/src/OpenTK/Math/Vector3d.cs +++ b/src/OpenTK/Math/Vector3d.cs @@ -658,7 +658,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -672,7 +672,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -689,7 +689,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -703,7 +703,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector4.cs b/src/OpenTK/Math/Vector4.cs index b2f13fb3..7f605dd3 100644 --- a/src/OpenTK/Math/Vector4.cs +++ b/src/OpenTK/Math/Vector4.cs @@ -768,7 +768,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -783,7 +783,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -801,7 +801,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -816,7 +816,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand diff --git a/src/OpenTK/Math/Vector4d.cs b/src/OpenTK/Math/Vector4d.cs index a9d385dd..67a4af8b 100644 --- a/src/OpenTK/Math/Vector4d.cs +++ b/src/OpenTK/Math/Vector4d.cs @@ -770,7 +770,7 @@ namespace OpenTK #region ComponentMin /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -785,7 +785,7 @@ namespace OpenTK } /// - /// Calculate the component-wise minimum of two vectors + /// Returns a vector created from the smallest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -803,7 +803,7 @@ namespace OpenTK #region ComponentMax /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand @@ -818,7 +818,7 @@ namespace OpenTK } /// - /// Calculate the component-wise maximum of two vectors + /// Returns a vector created from the largest of the corresponding components of the given vectors. /// /// First operand /// Second operand From 4ae58b30733b41eb06377cbe662d47f86c82a590 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sat, 3 Jun 2017 22:42:39 +0200 Subject: [PATCH 60/66] Changed some Equals to ApproximatelyEquals. --- tests/OpenTK.Tests/Vector2Tests.fs | 4 ++-- tests/OpenTK.Tests/Vector4Tests.fs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index f9e741e3..a77d2796 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -567,7 +567,7 @@ module Vector2 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - Assert.Equal(transformedVector, Vector2.Transform(v, q)) + Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(v, q)) [] let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = @@ -577,7 +577,7 @@ module Vector2 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - Assert.Equal(transformedVector, Vector2.Transform(ref v, ref q)) + Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(ref v, ref q)) [ |])>] module Serialization = diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index 193c77c5..addc1608 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -885,7 +885,7 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) - Assert.Equal(transformedVector, Vector4.Transform(v, q)) + Assert.ApproximatelyEqual(transformedVector, Vector4.Transform(v, q)) [] let ``Transformation by quaternion with static method by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = @@ -895,7 +895,7 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y,transformedQuat.Z, transformedQuat.W) - Assert.Equal(transformedVector, Vector4.Transform(ref v, ref q)) + Assert.ApproximatelyEqual(transformedVector, Vector4.Transform(ref v, ref q)) [] let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = @@ -905,4 +905,4 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) - Assert.Equal(transformedVector, q * v) \ No newline at end of file + Assert.ApproximatelyEqual(transformedVector, q * v) \ No newline at end of file From 6d0f3eb973d06e43dd131650e28f3ba4954ec04e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 4 Jun 2017 19:05:43 +0200 Subject: [PATCH 61/66] Added new and improved floating-point equality tester. --- tests/OpenTK.Tests/Assertions.fs | 41 +++- tests/OpenTK.Tests/MathHelperTests.fs | 335 ++++++++++++++++++++++---- tests/OpenTK.Tests/Matrix4Tests.fs | 16 +- tests/OpenTK.Tests/Vector2Tests.fs | 173 +++++++------ tests/OpenTK.Tests/Vector3Tests.fs | 164 +++++++------ tests/OpenTK.Tests/Vector4Tests.fs | 191 ++++++++------- 6 files changed, 625 insertions(+), 295 deletions(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index b6fdfc8e..72673de7 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -9,9 +9,19 @@ open OpenTK [] module private AssertHelpers = [] - let private BitAccuracy = 13 + let private BitAccuracy = 16 - let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) + //let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) + let approxEq a b = MathHelper.ApproximatelyEqualEpsilon(a,b,0.0001f) + let approxEqSingleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001f) + let approxEqDoubleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001) + + let approxEqSingleEpsilonWithError (a, b, c : float32) = MathHelper.ApproximatelyEqualEpsilon(a, b, c) + let approxEqDoubleEpsilonWithError (a, b, c : float) = MathHelper.ApproximatelyEqualEpsilon(a, b, c) + + let anyZero2 (a : Vector2) = (approxEq a.X 0.0f || approxEq a.Y 0.0f) + let anyZero3 (a : Vector3) = (approxEq a.X 0.0f || approxEq a.Y 0.0f || approxEq a.Z 0.0f) + let anyZero4 (a : Vector4) = (approxEq a.X 0.0f || approxEq a.Y 0.0f || approxEq a.Z 0.0f || approxEq a.W 0.0f) /// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal. [] @@ -31,4 +41,31 @@ type internal Assert = if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b) + static member ApproximatelyEqualEpsilon(a : float32, b : float32) = + if not <| approxEqSingleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b) + + static member ApproximatelyEqualEpsilon(a : float32, b : float32, c : float32) = + if not <| approxEqSingleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b) + + + static member ApproximatelyEqualEpsilon(a : float, b : float) = + if not <| approxEqDoubleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b) + + static member ApproximatelyEqualEpsilon(a : float, b : float, c : float) = + if not <| approxEqDoubleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b) + + + static member NotApproximatelyEqualEpsilon(a : float32, b : float32) = + if approxEqSingleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b) + + static member NotApproximatelyEqualEpsilon(a : float32, b : float32, c : float32) = + if approxEqSingleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b) + + + static member NotApproximatelyEqualEpsilon(a : float, b : float) = + if approxEqDoubleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b) + + static member NotApproximatelyEqualEpsilon(a : float, b : float, c : float) = + if approxEqDoubleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b) + static member ThrowsIndexExn(f:unit -> unit) = Assert.Throws(f) |> ignore diff --git a/tests/OpenTK.Tests/MathHelperTests.fs b/tests/OpenTK.Tests/MathHelperTests.fs index e1270176..554341af 100644 --- a/tests/OpenTK.Tests/MathHelperTests.fs +++ b/tests/OpenTK.Tests/MathHelperTests.fs @@ -6,50 +6,303 @@ open FsCheck.Xunit open System open OpenTK -[ |])>] module MathHelper = - /// This test ensures that approximately equal can never get it 'wrong' about the values. - [] - let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) = - let clamped = max 0 (min bits 24) - let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) - let areExactlyEqual = a = b - let isWrong = areExactlyEqual && not areApproxEqual - Assert.False(isWrong) + [ |], MaxTest = 10000)>] + module ``ApproximatelyEqual (delta)`` = + /// This test ensures that approximately equal can never get it 'wrong' about the values. + [] + let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) = + let clamped = max 0 (min bits 24) + let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) + let areExactlyEqual = a = b + let isWrong = areExactlyEqual && not areApproxEqual + Assert.False(isWrong) - [] - let ``ApproximatelyEqual can return true if some values are not exactly equal`` (a : float32,b : float32,bits : int32) = - let clamped = max 0 (min bits 24) - let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) - let areExactlyEqual = a = b - let isWrong = areExactlyEqual && not areApproxEqual - let p = new PropertyAttribute() - Assert.False(isWrong) + [] + let ``ApproximatelyEqual can return true if some values are not exactly equal`` (a : float32,b : float32,bits : int32) = + let clamped = max 0 (min bits 24) + let areApproxEqual = MathHelper.ApproximatelyEqual(a,b,clamped) + let areExactlyEqual = a = b + let isWrong = areExactlyEqual && not areApproxEqual + let p = new PropertyAttribute() + Assert.False(isWrong) - [] - let ``ApproximatelyEqual correctly approximates equality``() = - let a = 0.000000001f - let b = 0.0000000010000001f - Assert.NotEqual(a,b) - [ 1..24 ] |> List.iter (fun i -> Assert.True(MathHelper.ApproximatelyEqual(a,b,i))) + [] + let ``ApproximatelyEqual correctly approximates equality``() = + let a = 0.000000001f + let b = 0.0000000010000001f + Assert.NotEqual(a,b) + [ 1..24 ] |> List.iter (fun i -> Assert.True(MathHelper.ApproximatelyEqual(a,b,i))) - [] - let ``ApproximatelyEqual reports very different values as non-equal even with high bit count``() = - let a = 2.0f - let b = 1.0f - Assert.NotEqual(a,b) - Assert.False(MathHelper.ApproximatelyEqual(a,b,10)) + [] + let ``ApproximatelyEqual reports very different values as non-equal even with high bit count``() = + let a = 2.0f + let b = 1.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEqual(a,b,10)) - [] - let ``ApproximatelyEqual works with single zero value``() = - let a = 1.0f - let b = 0.0f - Assert.NotEqual(a,b) - Assert.False(MathHelper.ApproximatelyEqual(a,b,0)) + [] + let ``ApproximatelyEqual works with single zero value``() = + let a = 1.0f + let b = 0.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEqual(a,b,0)) - [] - let ``ApproximatelyEqual works with both zero values``() = - let a = 0.0f - let b = 0.0f - Assert.Equal(a,b) - Assert.True(MathHelper.ApproximatelyEqual(a,b,0)) + [] + let ``ApproximatelyEqual works with both zero values``() = + let a = 0.0f + let b = 0.0f + Assert.Equal(a,b) + Assert.True(MathHelper.ApproximatelyEqual(a,b,0)) + + [ |], MaxTest = 10000)>] + module ``ApproximatelyEqual (single-precision epsilon)`` = + // + [] + let ``ApproximatelyEqual (single precision) is correct for large positive values``() = + Assert.ApproximatelyEqualEpsilon(1000000.0f, 1000001.0f); + Assert.ApproximatelyEqualEpsilon(1000001.0f, 1000000.0f); + Assert.NotApproximatelyEqualEpsilon(10000.0f, 10001.0f); + Assert.NotApproximatelyEqualEpsilon(10001.0f, 10000.0f); + + [] + let ``ApproximatelyEqual (single precision) is correct for large negative values``() = + Assert.ApproximatelyEqualEpsilon(-1000000.0f, -1000001.0f); + Assert.ApproximatelyEqualEpsilon(-1000001.0f, -1000000.0f); + Assert.NotApproximatelyEqualEpsilon(-10000.0f, -10001.0f); + Assert.NotApproximatelyEqualEpsilon(-10001.0f, -10000.0f); + + [] + let ``ApproximatelyEqual (single precision) is correct for positive values around 1``() = + Assert.ApproximatelyEqualEpsilon(1.0000001f, 1.0000002f); + Assert.ApproximatelyEqualEpsilon(1.0000002f, 1.0000001f); + Assert.NotApproximatelyEqualEpsilon(1.0002f, 1.0001f); + Assert.NotApproximatelyEqualEpsilon(1.0001f, 1.0002f); + + [] + let ``ApproximatelyEqual (single precision) is correct for negative values around -1``() = + Assert.ApproximatelyEqualEpsilon(-1.000001f, -1.000002f); + Assert.ApproximatelyEqualEpsilon(-1.000002f, -1.000001f); + Assert.NotApproximatelyEqualEpsilon(-1.0001f, -1.0002f); + Assert.NotApproximatelyEqualEpsilon(-1.0002f, -1.0001f); + + [] + let ``ApproximatelyEqual (single precision) is correct for values between 1 and 0``() = + Assert.ApproximatelyEqualEpsilon(0.000000001000001f, 0.000000001000002f); + Assert.ApproximatelyEqualEpsilon(0.000000001000002f, 0.000000001000001f); + Assert.NotApproximatelyEqualEpsilon(0.000000000001002f, 0.000000000001001f); + Assert.NotApproximatelyEqualEpsilon(0.000000000001001f, 0.000000000001002f); + + [] + let ``ApproximatelyEqual (single precision) is correct for values between -1 and 0``() = + Assert.ApproximatelyEqualEpsilon(-0.000000001000001f, -0.000000001000002f); + Assert.ApproximatelyEqualEpsilon(-0.000000001000002f, -0.000000001000001f); + Assert.NotApproximatelyEqualEpsilon(-0.000000000001002f, -0.000000000001001f); + Assert.NotApproximatelyEqualEpsilon(-0.000000000001001f, -0.000000000001002f); + + [] + let ``ApproximatelyEqual (single precision) is correct for comparisons involving 0``() = + Assert.ApproximatelyEqualEpsilon(0.0f, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, -0.0f); + Assert.ApproximatelyEqualEpsilon(-0.0f, -0.0f); + Assert.NotApproximatelyEqualEpsilon(0.00000001f, 0.0f); + Assert.NotApproximatelyEqualEpsilon(0.0f, 0.00000001f); + Assert.NotApproximatelyEqualEpsilon(-0.00000001f, 0.0f); + Assert.NotApproximatelyEqualEpsilon(0.0f, -0.00000001f); + + Assert.ApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.01f); + Assert.ApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.01f); + Assert.NotApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.000001f); + Assert.NotApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.000001f); + + Assert.ApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.1f); + Assert.ApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.1f); + Assert.NotApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.00000001f); + Assert.NotApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.00000001f); + + [] + let ``ApproximatelyEqual (single precision) is correct for extreme values with overflow potential``() = + Assert.ApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue / 2.0f); + Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue / 2.0f); + Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue / 2.0f); + + [] + let ``ApproximatelyEqual (single precision) is correct for values involving infinities``() = + Assert.ApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity); + Assert.ApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.PositiveInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, -System.Single.MaxValue); + + [] + let ``ApproximatelyEqual (single precision) is correct for values involving NaN``() = + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, 0.0f); + Assert.NotApproximatelyEqualEpsilon(-0.0f, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -0.0f); + Assert.NotApproximatelyEqualEpsilon(0.0f, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.PositiveInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.NegativeInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -System.Single.MaxValue); + Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.Epsilon); + Assert.NotApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -System.Single.Epsilon); + Assert.NotApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.NaN); + + [] + let ``ApproximatelyEqual (single precision) is correct for values on opposite sides of 0``() = + Assert.NotApproximatelyEqualEpsilon(1.000000001f, -1.0f); + Assert.NotApproximatelyEqualEpsilon(-1.0f, 1.000000001f); + Assert.NotApproximatelyEqualEpsilon(-1.000000001f, 1.0f); + Assert.NotApproximatelyEqualEpsilon(1.0f, -1.000000001f); + Assert.ApproximatelyEqualEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon); + Assert.NotApproximatelyEqualEpsilon(10000.0f * System.Single.Epsilon, 10000.0f * -System.Single.Epsilon); + + [] + let ``ApproximatelyEqual (single precision) is correct for values very close to 0``() = + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, -System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, -System.Single.Epsilon); + + Assert.NotApproximatelyEqualEpsilon(0.000000001f, -System.Single.Epsilon); + Assert.NotApproximatelyEqualEpsilon(0.000000001f, System.Single.Epsilon); + Assert.NotApproximatelyEqualEpsilon(System.Single.Epsilon, 0.000000001f); + Assert.NotApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.000000001f); + + [ |], MaxTest = 10000)>] + module ``ApproximatelyEqual (double-precision epsilon)`` = + // + [] + let ``ApproximatelyEqual (double precision) is correct for large positive values``() = + Assert.ApproximatelyEqualEpsilon(1000000.0, 1000001.0); + Assert.ApproximatelyEqualEpsilon(1000001.0, 1000000.0); + Assert.NotApproximatelyEqualEpsilon(10000.0, 10001.0); + Assert.NotApproximatelyEqualEpsilon(10001.0, 10000.0); + + [] + let ``ApproximatelyEqual (double precision) is correct for large negative values``() = + Assert.ApproximatelyEqualEpsilon(-1000000.0, -1000001.0); + Assert.ApproximatelyEqualEpsilon(-1000001.0, -1000000.0); + Assert.NotApproximatelyEqualEpsilon(-10000.0, -10001.0); + Assert.NotApproximatelyEqualEpsilon(-10001.0, -10000.0); + + [] + let ``ApproximatelyEqual (double precision) is correct for positive values around 1``() = + Assert.ApproximatelyEqualEpsilon(1.0000001, 1.0000002); + Assert.ApproximatelyEqualEpsilon(1.0000002, 1.0000001); + Assert.NotApproximatelyEqualEpsilon(1.0002, 1.0001); + Assert.NotApproximatelyEqualEpsilon(1.0001, 1.0002); + + [] + let ``ApproximatelyEqual (double precision) is correct for negative values around -1``() = + Assert.ApproximatelyEqualEpsilon(-1.000001, -1.000002); + Assert.ApproximatelyEqualEpsilon(-1.000002, -1.000001); + Assert.NotApproximatelyEqualEpsilon(-1.0001, -1.0002); + Assert.NotApproximatelyEqualEpsilon(-1.0002, -1.0001); + + [] + let ``ApproximatelyEqual (double precision) is correct for values between 1 and 0``() = + Assert.ApproximatelyEqualEpsilon(0.000000001000001, 0.000000001000002); + Assert.ApproximatelyEqualEpsilon(0.000000001000002, 0.000000001000001); + Assert.NotApproximatelyEqualEpsilon(0.000000000001002, 0.000000000001001); + Assert.NotApproximatelyEqualEpsilon(0.000000000001001, 0.000000000001002); + + [] + let ``ApproximatelyEqual (double precision) is correct for values between -1 and 0``() = + Assert.ApproximatelyEqualEpsilon(-0.000000001000001, -0.000000001000002); + Assert.ApproximatelyEqualEpsilon(-0.000000001000002, -0.000000001000001); + Assert.NotApproximatelyEqualEpsilon(-0.000000000001002, -0.000000000001001); + Assert.NotApproximatelyEqualEpsilon(-0.000000000001001, -0.000000000001002); + + [] + let ``ApproximatelyEqual (double precision) is correct for comparisons involving 0``() = + Assert.ApproximatelyEqualEpsilon(0.0, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, -0.0); + Assert.ApproximatelyEqualEpsilon(-0.0, -0.0); + Assert.NotApproximatelyEqualEpsilon(0.00000001, 0.0); + Assert.NotApproximatelyEqualEpsilon(0.0, 0.00000001); + Assert.NotApproximatelyEqualEpsilon(-0.00000001, 0.0); + Assert.NotApproximatelyEqualEpsilon(0.0, -0.00000001); + + Assert.ApproximatelyEqualEpsilon(0.0, 1e-310, 0.01); + Assert.ApproximatelyEqualEpsilon(1e-310, 0.0, 0.01); + Assert.NotApproximatelyEqualEpsilon(1e-310, 0.0, 0.000001); + Assert.NotApproximatelyEqualEpsilon(0.0, 1e-310, 0.000001); + + Assert.ApproximatelyEqualEpsilon(0.0, -1e-310, 0.1); + Assert.ApproximatelyEqualEpsilon(-1e-310, 0.0, 0.1); + Assert.NotApproximatelyEqualEpsilon(-1e-310, 0.0, 0.00000001); + Assert.NotApproximatelyEqualEpsilon(0.0, -1e-310, 0.00000001); + + [] + let ``ApproximatelyEqual (double precision) is correct for extreme values with overflow potential``() = + Assert.ApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue / 2.0); + Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue / 2.0); + Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue / 2.0); + + [] + let ``ApproximatelyEqual (double precision) is correct for values involving infinities``() = + Assert.ApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity); + Assert.ApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.PositiveInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, -System.Double.MaxValue); + + [] + let ``ApproximatelyEqual (double precision) is correct for values involving NaN``() = + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, 0.0); + Assert.NotApproximatelyEqualEpsilon(-0.0, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -0.0); + Assert.NotApproximatelyEqualEpsilon(0.0, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.PositiveInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.NegativeInfinity); + Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -System.Double.MaxValue); + Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.Epsilon); + Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.NaN); + Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -System.Double.Epsilon); + Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.NaN); + + [] + let ``ApproximatelyEqual (double precision) is correct for values on opposite sides of 0``() = + Assert.NotApproximatelyEqualEpsilon(1.000000001, -1.0); + Assert.NotApproximatelyEqualEpsilon(-1.0, 1.000000001); + Assert.NotApproximatelyEqualEpsilon(-1.000000001, 1.0); + Assert.NotApproximatelyEqualEpsilon(1.0, -1.000000001); + Assert.ApproximatelyEqualEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon); + Assert.NotApproximatelyEqualEpsilon(100000000000.0 * System.Double.Epsilon, 100000000000.0 * -System.Double.Epsilon); + + [] + let ``ApproximatelyEqual (double precision) is correct for values very close to 0``() = + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, -System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, -System.Double.Epsilon); + + Assert.NotApproximatelyEqualEpsilon(0.000000001, -System.Double.Epsilon); + Assert.NotApproximatelyEqualEpsilon(0.000000001, System.Double.Epsilon); + Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, 0.000000001); + Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.000000001); \ No newline at end of file diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 706a839e..43dc471c 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -7,7 +7,7 @@ open System open OpenTK module Matrix4 = - [ |])>] + [ |], MaxTest = 10000)>] module Constructors = // [] @@ -88,7 +88,7 @@ module Matrix4 = Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - [ |])>] + [ |], MaxTest = 10000)>] module Equality = // [] @@ -103,7 +103,7 @@ module Matrix4 = let ``A matrix is not equal to an object which is not a matrix`` (a : Matrix4, b : Vector3) = Assert.False(a.Equals(b)) - [ |])>] + [ |], MaxTest = 10000)>] module Multiplication = // [] @@ -202,7 +202,7 @@ module Matrix4 = Assert.Equal(R4, AScaled.Row3) - [ |])>] + [ |], MaxTest = 10000)>] module Addition = // [] @@ -232,7 +232,7 @@ module Matrix4 = Assert.Equal(o + o, sum.M43) Assert.Equal(p + p, sum.M44) - [ |])>] + [ |], MaxTest = 10000)>] module Subtraction = // [] @@ -262,7 +262,7 @@ module Matrix4 = Assert.Equal(o - o, sub.M43) Assert.Equal(p - p, sub.M44) - [ |])>] + [ |], MaxTest = 10000)>] module Indexing = // [] @@ -338,7 +338,7 @@ module Matrix4 = let ``Indexed set operator throws exception for negative indices`` (b : Matrix4, x : float32) = let mutable a = b - + (fun() -> a.[-1, 2] <- x) |> Assert.ThrowsIndexExn (fun() -> a.[1, -2] <- x) |> Assert.ThrowsIndexExn @@ -363,7 +363,7 @@ module Matrix4 = (fun() -> a.[1, 6] |> ignore) |> Assert.ThrowsIndexExn (fun() -> a.[7, 12] |> ignore) |> Assert.ThrowsIndexExn - [ |])>] + [ |], MaxTest = 10000)>] module ``Row and column properties`` = // [] diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index a77d2796..ae595064 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector2 = - [ |])>] + [ |], MaxTest = 10000)>] module Constructors = // [] @@ -23,7 +23,7 @@ module Vector2 = Assert.Equal(x,v.X) Assert.Equal(y,v.Y) - [ |])>] + [ |], MaxTest = 10000)>] module Clamping = // [] @@ -46,7 +46,7 @@ module Vector2 = Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) - [ |])>] + [ |], MaxTest = 10000)>] module Length = // [] @@ -75,7 +75,7 @@ module Vector2 = Assert.Equal(lsq, v.LengthSquared) - [ |])>] + [ |], MaxTest = 10000)>] module ``Unit vectors and perpendicularity`` = // [] @@ -92,7 +92,7 @@ module Vector2 = Assert.Equal(perp, v.PerpendicularLeft) - [ |])>] + [ |], MaxTest = 10000)>] module Indexing = // [] @@ -126,7 +126,7 @@ module Vector2 = (fun() -> v.[2] |> ignore) |> Assert.ThrowsIndexExn - [ |])>] + [ |], MaxTest = 10000)>] module ``Simple Properties`` = // [] @@ -139,7 +139,7 @@ module Vector2 = // Assert.True(a.Length >= 0.0f) - [ |])>] + [ |], MaxTest = 10000)>] module Addition = // [] @@ -176,7 +176,7 @@ module Vector2 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Multiplication = // [] @@ -227,7 +227,7 @@ module Vector2 = Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - [ |])>] + [ |], MaxTest = 10000)>] module Subtraction = // [] @@ -252,49 +252,50 @@ module Vector2 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Division = // [] let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) = - let r = a / f + if not (approxEq f 0.0f) then + let r = a / f - Assert.ApproximatelyEqual(a.X / f,r.X) - Assert.ApproximatelyEqual(a.Y / f,r.Y) + Assert.ApproximatelyEqual(a.X / f,r.X) + Assert.ApproximatelyEqual(a.Y / f,r.Y) [] let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) = + if not (anyZero2 a || anyZero2 b) then + let v1 = Vector2(a.X / b.X, a.Y / b.Y) + let sum = Vector2.Divide(a, b) - let v1 = Vector2(a.X / b.X, a.Y / b.Y) - let sum = Vector2.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) = + if not (anyZero2 a || anyZero2 b) then + let v1 = Vector2(a.X / b.X, a.Y / b.Y) + let sum = Vector2.Divide(ref a, ref b) - let v1 = Vector2(a.X / b.X, a.Y / b.Y) - let sum = Vector2.Divide(ref a, ref b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) = + if not (approxEq b 0.0f) then + let v1 = Vector2(a.X / b, a.Y / b) + let sum = Vector2.Divide(a, b) - let v1 = Vector2(a.X / b, a.Y / b) - let sum = Vector2.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) = + if not (approxEq b 0.0f) then + let v1 = Vector2(a.X / b, a.Y / b) + let sum = Vector2.Divide(ref a, b) - let v1 = Vector2(a.X / b, a.Y / b) - let sum = Vector2.Divide(ref a, b) + Assert.ApproximatelyEqual(v1, sum) - Assert.ApproximatelyEqual(v1, sum) - - [ |])>] + [ |], MaxTest = 10000)>] module Negation = // [] @@ -304,7 +305,7 @@ module Vector2 = Assert.Equal(-x, vNeg.X) Assert.Equal(-y, vNeg.Y) - [ |])>] + [ |], MaxTest = 10000)>] module Equality = // [] @@ -335,7 +336,7 @@ module Vector2 = Assert.True(equality) Assert.False(inequalityByOtherType) - [ |])>] + [ |], MaxTest = 10000)>] module Swizzling = // [] @@ -346,7 +347,7 @@ module Vector2 = let v1yx = v1.Yx; Assert.Equal(v2, v1yx); - [ |])>] + [ |], MaxTest = 10000)>] module Interpolation = // [] @@ -373,7 +374,7 @@ module Vector2 = let vRes = Vector2.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module ``Vector products`` = // [] @@ -394,7 +395,7 @@ module Vector2 = let vRes = Vector2.PerpDot(ref a, ref b) Assert.Equal(perpDot, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module Normalization = // [] @@ -434,16 +435,20 @@ module Vector2 = [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector2) = - let norm = a / a.Length - let vRes = Vector2.Normalize(ref a) + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length + let vRes = Vector2.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEqual(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector2) = - let norm = a / a.Length + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); + Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector2) = @@ -462,66 +467,74 @@ module Vector2 = Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); - [ |])>] + [ |], MaxTest = 10000)>] module ``Magnitude min and max`` = // [] let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector2.MagnitudeMin(v1, v2) + let vMin = Vector2.MagnitudeMin(v1, v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector2.MagnitudeMax(v1, v2) + let vMin = Vector2.MagnitudeMax(v1, v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) [] let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector2.MagnitudeMin(ref v1, ref v2) + let vMin = Vector2.MagnitudeMin(ref v1, ref v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax by reference selects the vector with equal greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector2.MagnitudeMax(ref v1, ref v2) + let vMin = Vector2.MagnitudeMax(ref v1, ref v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) - [ |])>] + [ |], MaxTest = 10000)>] module ``Component min and max`` = // [] @@ -556,7 +569,7 @@ module Vector2 = Assert.True(isComponentLargest vMax.X v1.X v2.X) Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) - [ |])>] + [ |], MaxTest = 10000)>] module Transformation = // [] @@ -579,7 +592,7 @@ module Vector2 = Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(ref v, ref q)) - [ |])>] + [ |], MaxTest = 10000)>] module Serialization = // [] diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 8987c9f7..6428684e 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector3 = - [ |])>] + [ |], MaxTest = 10000)>] module Constructors = // [] @@ -65,7 +65,7 @@ module Vector3 = Assert.Equal(b, v2.Y) Assert.Equal(c, v2.Z) - [ |])>] + [ |], MaxTest = 10000)>] module Indexing = // [] @@ -100,7 +100,7 @@ module Vector3 = (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn - [ |])>] + [ |], MaxTest = 10000)>] module Length = // [] @@ -124,7 +124,7 @@ module Vector3 = Assert.Equal(lsq, v.LengthSquared) - [ |])>] + [ |], MaxTest = 10000)>] module Normalization = // [] @@ -167,16 +167,20 @@ module Vector3 = [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector3) = - let norm = a / a.Length - let vRes = Vector3.Normalize(ref a) + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length + let vRes = Vector3.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEqual(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector3) = - let norm = a / a.Length + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector3) = @@ -195,7 +199,7 @@ module Vector3 = Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a)); - [ |])>] + [ |], MaxTest = 10000)>] module Addition = // [] @@ -236,7 +240,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Subtraction = // [] @@ -263,7 +267,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Multiplication = // [] @@ -344,7 +348,7 @@ module Vector3 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Division = // [] @@ -358,37 +362,37 @@ module Vector3 = [] let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) = + if not (anyZero3 a || anyZero3 b) then + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) + let sum = Vector3.Divide(a, b) - let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) - let sum = Vector3.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) = + if not (anyZero3 a || anyZero3 b) then + let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) + let sum = Vector3.Divide(ref a, ref b) - let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) - let sum = Vector3.Divide(ref a, ref b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) = + if not (approxEq b 0.0f) then // we don't support diving by zero. + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) + let sum = Vector3.Divide(a, b) - let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) - let sum = Vector3.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) = + if not (approxEq b 0.0f) then // we don't support diving by zero. + let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) + let sum = Vector3.Divide(ref a, b) - let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) - let sum = Vector3.Divide(ref a, b) + Assert.ApproximatelyEqual(v1, sum) - Assert.ApproximatelyEqual(v1, sum) - - [ |])>] + [ |], MaxTest = 10000)>] module Negation = // [] @@ -399,7 +403,7 @@ module Vector3 = Assert.Equal(-y, vNeg.Y) Assert.Equal(-z, vNeg.Z) - [ |])>] + [ |], MaxTest = 10000)>] module Equality = // [] @@ -430,7 +434,7 @@ module Vector3 = Assert.True(equality) Assert.False(inequalityByOtherType) - [ |])>] + [ |], MaxTest = 10000)>] module Swizzling = // [] @@ -475,7 +479,7 @@ module Vector3 = Assert.Equal(zx, v.Zx); Assert.Equal(zy, v.Zy); - [ |])>] + [ |], MaxTest = 10000)>] module Interpolation = // [] @@ -503,7 +507,7 @@ module Vector3 = let vRes = Vector3.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module ``Vector products`` = // [] @@ -527,66 +531,74 @@ module Vector3 = let vRes = Vector3.Cross(ref a, ref b) Assert.Equal(cross, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module ``Magnitude min and max`` = // [] let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector3.MagnitudeMin(v1, v2) + let vMin = Vector3.MagnitudeMin(v1, v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector3.MagnitudeMax(v1, v2) + let vMin = Vector3.MagnitudeMax(v1, v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) [] let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector3.MagnitudeMin(ref v1, ref v2) + let vMin = Vector3.MagnitudeMin(ref v1, ref v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector3.MagnitudeMax(ref v1, ref v2) + let vMin = Vector3.MagnitudeMax(ref v1, ref v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) - [ |])>] + [ |], MaxTest = 10000)>] module ``Component min and max`` = // [] @@ -625,7 +637,7 @@ module Vector3 = Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) - [ |])>] + [ |], MaxTest = 10000)>] module Clamping = // [] @@ -652,7 +664,7 @@ module Vector3 = Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) - [ |])>] + [ |], MaxTest = 10000)>] module ``Unit vectors``= // [] @@ -685,7 +697,7 @@ module Vector3 = Assert.Equal(Vector3.One, unitOne) - [ |])>] + [ |], MaxTest = 10000)>] module Serialization = // [] @@ -695,7 +707,7 @@ module Vector3 = Assert.Equal(expectedSize, Vector3.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) - [ |])>] + [ |], MaxTest = 10000)>] module Transformation = // [] diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index addc1608..df8a9b6e 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector4 = - [ |])>] + [ |], MaxTest = 10000)>] module Constructors = // [] @@ -85,7 +85,7 @@ module Vector4 = Assert.Equal(z, v2.Z) Assert.Equal(w, v2.W) - [ |])>] + [ |], MaxTest = 10000)>] module Indexing = // [] @@ -121,7 +121,7 @@ module Vector4 = (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn - [ |])>] + [ |], MaxTest = 10000)>] module Length = // [] @@ -145,7 +145,7 @@ module Vector4 = Assert.Equal(lsq, v.LengthSquared) - [ |])>] + [ |], MaxTest = 10000)>] module Normalization = // [] @@ -153,25 +153,29 @@ module Vector4 = let v = Vector4(x, y, z, w) let l = v.Length - let norm = v.Normalized() + // Zero-length vectors can't be normalized + if not (approxEq l 0.0f) then + let norm = v.Normalized() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) [] let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = let v = Vector4(x, y, z, w) let l = v.Length - let norm = Vector4(x, y, z, w) - norm.Normalize() + // Zero-length vectors can't be normalized + if not (approxEq l 0.0f) then + let norm = Vector4(x, y, z, w) + norm.Normalize() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + Assert.ApproximatelyEqual(v.X / l, norm.X) + Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEqual(v.W / l, norm.W) [] let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = @@ -188,16 +192,20 @@ module Vector4 = [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) = - let norm = a / a.Length - let vRes = Vector4.Normalize(ref a) + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length + let vRes = Vector4.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEqual(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector4) = - let norm = a / a.Length + // Zero-length vectors can't be normalized + if not (approxEq a.Length 0.0f) then + let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); + Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector4) = @@ -211,12 +219,11 @@ module Vector4 = [] let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) - let norm = a * scale Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a)); - [ |])>] + [ |], MaxTest = 10000)>] module Addition = // [] @@ -258,7 +265,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Subtraction = // [] @@ -286,7 +293,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Multiplication = // [] @@ -374,7 +381,7 @@ module Vector4 = Assert.ApproximatelyEqual(v1, sum) - [ |])>] + [ |], MaxTest = 10000)>] module Division = // [] @@ -389,37 +396,37 @@ module Vector4 = [] let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) = + if not (anyZero4 a || anyZero4 b) then + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) + let sum = Vector4.Divide(a, b) - let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) - let sum = Vector4.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) = + if not (anyZero4 a || anyZero4 b) then + let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) + let sum = Vector4.Divide(ref a, ref b) - let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) - let sum = Vector4.Divide(ref a, ref b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) = + if not (approxEq b 0.0f) then // we don't support diving by zero. + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) + let sum = Vector4.Divide(a, b) - let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) - let sum = Vector4.Divide(a, b) - - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEqual(v1, sum) [] let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) = + if not (approxEq b 0.0f) then // we don't support diving by zero. + let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) + let sum = Vector4.Divide(ref a, b) - let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) - let sum = Vector4.Divide(ref a, b) + Assert.ApproximatelyEqual(v1, sum) - Assert.ApproximatelyEqual(v1, sum) - - [ |])>] + [ |], MaxTest = 10000)>] module Negation = // [] @@ -431,7 +438,7 @@ module Vector4 = Assert.Equal(-z, vNeg.Z) Assert.Equal(-w, vNeg.W) - [ |])>] + [ |], MaxTest = 10000)>] module Equality = // [] @@ -471,7 +478,7 @@ module Vector4 = Assert.False(inequalityByOtherType) - [ |])>] + [ |], MaxTest = 10000)>] module Swizzling = // [] @@ -650,7 +657,7 @@ module Vector4 = Assert.Equal(wy, v.Wy) Assert.Equal(wz, v.Wz) - [ |])>] + [ |], MaxTest = 10000)>] module Interpolation = // [] @@ -679,7 +686,7 @@ module Vector4 = let vRes = Vector4.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module ``Vector products`` = // [] @@ -691,66 +698,74 @@ module Vector4 = let vRes = Vector4.Dot(ref a, ref b) Assert.Equal(dot, vRes) - [ |])>] + [ |], MaxTest = 10000)>] module ``Magnitude min and max`` = // [] let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector4.MagnitudeMin(v1, v2) + let vMin = Vector4.MagnitudeMin(v1, v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector4.MagnitudeMax(v1, v2) + let vMin = Vector4.MagnitudeMax(v1, v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) [] let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector4.MagnitudeMin(ref v1, ref v2) + let vMin = Vector4.MagnitudeMin(ref v1, ref v2) - if vMin = v1 then - let v1ShorterThanv2 = l1 < l2 - Assert.True(v1ShorterThanv2) - else - let v2ShorterThanOrEqualTov1 = l2 <= l1 - Assert.True(v2ShorterThanOrEqualTov1) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) = - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + // Results do not matter for equal vectors + if not (v1 = v2) then + let l1 = v1.LengthSquared + let l2 = v2.LengthSquared - let vMin = Vector4.MagnitudeMax(ref v1, ref v2) + let vMin = Vector4.MagnitudeMax(ref v1, ref v2) - if vMin = v1 then - let v1LongerThanOrEqualTov2 = l1 >= l2 - Assert.True(v1LongerThanOrEqualTov2) - else - let v2LongerThanv1 = l2 > l1 - Assert.True(v2LongerThanv1) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) - [ |])>] + [ |], MaxTest = 10000)>] module ``Component min and max`` = // [] @@ -794,7 +809,7 @@ module Vector4 = Assert.True(isComponentLargest vMax.W v1.W v2.W) - [ |])>] + [ |], MaxTest = 10000)>] module Clamping = // [] @@ -825,7 +840,7 @@ module Vector4 = Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) - [ |])>] + [ |], MaxTest = 10000)>] module ``Unit vectors``= // [] @@ -864,7 +879,7 @@ module Vector4 = Assert.Equal(Vector4.One, unitOne) - [ |])>] + [ |], MaxTest = 10000)>] module Serialization = // [] @@ -874,7 +889,7 @@ module Vector4 = Assert.Equal(expectedSize, Vector4.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) - [ |])>] + [ |], MaxTest = 10000)>] module Transformation = // [] From fb71ebcffe50b26dfa116396d29432b3a7f3ad4e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 4 Jun 2017 19:06:03 +0200 Subject: [PATCH 62/66] Added new and improved floating-point equality tester. --- src/OpenTK/Math/MathHelper.cs | 70 ++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/OpenTK/Math/MathHelper.cs b/src/OpenTK/Math/MathHelper.cs index f1effe6e..c13cd893 100644 --- a/src/OpenTK/Math/MathHelper.cs +++ b/src/OpenTK/Math/MathHelper.cs @@ -3,13 +3,14 @@ * Copyright (c) 2006-2008 the OpenTK Team. * This notice may not be removed from any source distribution. * See license.txt for licensing detailed licensing details. - * + * * Contributions by Andy Gill, James Talton and Georg Wächter. */ #endregion using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Text; namespace OpenTK @@ -354,6 +355,73 @@ namespace OpenTK return intDiff <= (1 << maxDeltaBits); } + /// + /// Approximates double-precision floating point equality by an epsilon (maximum error) value. + /// This method is designed as a "fits-all" solution and attempts to handle as many cases as possible. + /// + /// The first float. + /// The second float. + /// The maximum error between the two. + /// true if the values are approximately equal within the error margin; otherwise, false. + [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] + public static bool ApproximatelyEqualEpsilon(double a, double b, double epsilon) + { + const double doubleNormal = (1L << 52) * double.Epsilon; + double absA = Math.Abs(a); + double absB = Math.Abs(b); + double diff = Math.Abs(a - b); + + if (a == b) + { + // Shortcut, handles infinities + return true; + } + + if (a == 0.0f || b == 0.0f || diff < doubleNormal) + { + // a or b is zero, or both are extremely close to it. + // relative error is less meaningful here + return diff < (epsilon * doubleNormal); + } + + // use relative error + return diff / Math.Min((absA + absB), double.MaxValue) < epsilon; + } + + /// + /// Approximates single-precision floating point equality by an epsilon (maximum error) value. + /// This method is designed as a "fits-all" solution and attempts to handle as many cases as possible. + /// + /// The first float. + /// The second float. + /// The maximum error between the two. + /// true if the values are approximately equal within the error margin; otherwise, false. + [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] + public static bool ApproximatelyEqualEpsilon(float a, float b, float epsilon) + { + const float floatNormal = (1 << 23) * float.Epsilon; + float absA = Math.Abs(a); + float absB = Math.Abs(b); + float diff = Math.Abs(a - b); + + if (a == b) + { + // Shortcut, handles infinities + return true; + } + + if (a == 0.0f || b == 0.0f || diff < floatNormal) + { + // a or b is zero, or both are extremely close to it. + // relative error is less meaningful here + return diff < (epsilon * floatNormal); + } + + // use relative error + float relativeError = diff / Math.Min((absA + absB), float.MaxValue); + return relativeError < epsilon; + } + #endregion #endregion From 87de6dda4dc0ea766a0b514e13c2985497fb1df8 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 7 Jun 2017 14:27:36 +0200 Subject: [PATCH 63/66] Merged new equivalence function. --- src/OpenTK/Math/MathHelper.cs | 44 +++++++++++++++++++++++++ tests/OpenTK.Tests/Assertions.fs | 7 +++- tests/OpenTK.Tests/MathHelperTests.fs | 46 ++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/OpenTK/Math/MathHelper.cs b/src/OpenTK/Math/MathHelper.cs index c13cd893..0dc553fe 100644 --- a/src/OpenTK/Math/MathHelper.cs +++ b/src/OpenTK/Math/MathHelper.cs @@ -422,6 +422,50 @@ namespace OpenTK return relativeError < epsilon; } + /// + /// Approximates equivalence between two single-precision floating-point numbers on a direct human scale. + /// It is important to note that this does not approximate equality - instead, it merely checks whether or not + /// two numbers could be considered equivalent to each other within a certain tolerance. + /// + /// The first value to compare. + /// The second value to compare· + /// The tolerance within which the two values would be considered equivalent. + /// Whether or not the values can be considered equivalent within the tolerance. + [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] + public static bool ApproximatelyEquivalent(float a, float b, float tolerance) + { + if (a == b) + { + // Early bailout, handles infinities + return true; + } + + float diff = Math.Abs(a - b); + return diff < tolerance; + } + + /// + /// Approximates equivalence between two double-precision floating-point numbers on a direct human scale. + /// It is important to note that this does not approximate equality - instead, it merely checks whether or not + /// two numbers could be considered equivalent to each other within a certain tolerance. + /// + /// The first value to compare. + /// The second value to compare· + /// The tolerance within which the two values would be considered equivalent. + /// Whether or not the values can be considered equivalent within the tolerance. + [SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator")] + public static bool ApproximatelyEquivalent(double a, double b, double tolerance) + { + if (a == b) + { + // Early bailout, handles infinities + return true; + } + + double diff = Math.Abs(a - b); + return diff < tolerance; + } + #endregion #endregion diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index 72673de7..b54ef7a2 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -11,8 +11,13 @@ module private AssertHelpers = [] let private BitAccuracy = 16 + [] + let private EquivalenceTolerance = 0.0001f + + let approxEq a b = MathHelper.ApproximatelyEquivalent(a, b, EquivalenceTolerance) //let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) - let approxEq a b = MathHelper.ApproximatelyEqualEpsilon(a,b,0.0001f) + //let approxEq a b = MathHelper.ApproximatelyEqualEpsilon(a,b,0.0001f) + let approxEqSingleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001f) let approxEqDoubleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001) diff --git a/tests/OpenTK.Tests/MathHelperTests.fs b/tests/OpenTK.Tests/MathHelperTests.fs index 554341af..fdd21f91 100644 --- a/tests/OpenTK.Tests/MathHelperTests.fs +++ b/tests/OpenTK.Tests/MathHelperTests.fs @@ -305,4 +305,48 @@ module MathHelper = Assert.NotApproximatelyEqualEpsilon(0.000000001, -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001, System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, 0.000000001); - Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.000000001); \ No newline at end of file + Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.000000001); + + [ |], MaxTest = 10000)>] + module ``ApproximatelyEquivalent (tolerance diff)`` = + [] + let ``ApproximatelyEquivalent correctly approximates equivalence where the difference falls below the tolerance``() = + let a = 0.0001f + let b = 0.00019f + Assert.NotEqual(a,b) + Assert.True(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) + + [] + let ``ApproximatelyEquivalent correctly approximates inequivalence where the difference is the tolerance``() = + let a = 0.0001f + let b = 0.0002f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) + + [] + let ``ApproximatelyEquivalent correctly approximates inequivalence where the difference exceeds the tolerance``() = + let a = 0.0001f + let b = 0.00021f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) + + [] + let ``ApproximatelyEquivalent reports very different values as non-equal even with a high tolerance``() = + let a = 2.0f + let b = 1.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 1.0f)) + + [] + let ``ApproximatelyEquivalent works with single zero value``() = + let a = 1.0f + let b = 0.0f + Assert.NotEqual(a,b) + Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) + + [] + let ``ApproximatelyEquivalent works with both zero values``() = + let a = 0.0f + let b = 0.0f + Assert.Equal(a,b) + Assert.True(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) \ No newline at end of file From 01bcbf181b74750a3cb7f556f47f5326e0773895 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 7 Jun 2017 15:22:37 +0200 Subject: [PATCH 64/66] Added check for directly equal inputs. --- src/OpenTK/Math/MathHelper.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/OpenTK/Math/MathHelper.cs b/src/OpenTK/Math/MathHelper.cs index 0dc553fe..57072e12 100644 --- a/src/OpenTK/Math/MathHelper.cs +++ b/src/OpenTK/Math/MathHelper.cs @@ -425,7 +425,8 @@ namespace OpenTK /// /// Approximates equivalence between two single-precision floating-point numbers on a direct human scale. /// It is important to note that this does not approximate equality - instead, it merely checks whether or not - /// two numbers could be considered equivalent to each other within a certain tolerance. + /// two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is + /// inclusive. /// /// The first value to compare. /// The second value to compare· @@ -441,13 +442,14 @@ namespace OpenTK } float diff = Math.Abs(a - b); - return diff < tolerance; + return diff <= tolerance; } /// /// Approximates equivalence between two double-precision floating-point numbers on a direct human scale. /// It is important to note that this does not approximate equality - instead, it merely checks whether or not - /// two numbers could be considered equivalent to each other within a certain tolerance. + /// two numbers could be considered equivalent to each other within a certain tolerance. The tolerance is + /// inclusive. /// /// The first value to compare. /// The second value to compare· @@ -463,7 +465,7 @@ namespace OpenTK } double diff = Math.Abs(a - b); - return diff < tolerance; + return diff <= tolerance; } #endregion From c6335b7aac2cf1d07bb302a9608283e49accd0cc Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 7 Jun 2017 15:22:52 +0200 Subject: [PATCH 65/66] Changed all tests to use the new method. --- tests/OpenTK.Tests/Assertions.fs | 14 +-- tests/OpenTK.Tests/MathHelperTests.fs | 134 +++++++++++++------------- tests/OpenTK.Tests/Matrix4Tests.fs | 14 +-- tests/OpenTK.Tests/Vector2Tests.fs | 96 +++++++++--------- tests/OpenTK.Tests/Vector3Tests.fs | 112 ++++++++++----------- tests/OpenTK.Tests/Vector4Tests.fs | 116 +++++++++++----------- 6 files changed, 243 insertions(+), 243 deletions(-) diff --git a/tests/OpenTK.Tests/Assertions.fs b/tests/OpenTK.Tests/Assertions.fs index b54ef7a2..0d0df594 100644 --- a/tests/OpenTK.Tests/Assertions.fs +++ b/tests/OpenTK.Tests/Assertions.fs @@ -12,11 +12,11 @@ module private AssertHelpers = let private BitAccuracy = 16 [] - let private EquivalenceTolerance = 0.0001f + let private EquivalenceTolerance = 0.00005f let approxEq a b = MathHelper.ApproximatelyEquivalent(a, b, EquivalenceTolerance) - //let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) - //let approxEq a b = MathHelper.ApproximatelyEqualEpsilon(a,b,0.0001f) + + let approxEqDelta a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy) let approxEqSingleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001f) let approxEqDoubleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001) @@ -32,17 +32,17 @@ module private AssertHelpers = [] type internal Assert = - static member ApproximatelyEqual(a : Vector2,b : Vector2) = + static member ApproximatelyEquivalent(a : Vector2,b : Vector2) = if not <| approxEq a.X b.X && approxEq a.Y b.Y then raise <| new Xunit.Sdk.EqualException(a,b) - static member ApproximatelyEqual(a : Vector3,b : Vector3) = + static member ApproximatelyEquivalent(a : Vector3,b : Vector3) = if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z then raise <| new Xunit.Sdk.EqualException(a,b) - static member ApproximatelyEqual(a : Vector4,b : Vector4) = + static member ApproximatelyEquivalent(a : Vector4,b : Vector4) = if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z && approxEq a.W b.W then raise <| new Xunit.Sdk.EqualException(a,b) - static member ApproximatelyEqual(a : float32,b : float32) = + static member ApproximatelyEquivalent(a : float32,b : float32) = if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b) diff --git a/tests/OpenTK.Tests/MathHelperTests.fs b/tests/OpenTK.Tests/MathHelperTests.fs index fdd21f91..542f00cd 100644 --- a/tests/OpenTK.Tests/MathHelperTests.fs +++ b/tests/OpenTK.Tests/MathHelperTests.fs @@ -7,7 +7,7 @@ open System open OpenTK module MathHelper = - [ |], MaxTest = 10000)>] + [ |])>] module ``ApproximatelyEqual (delta)`` = /// This test ensures that approximately equal can never get it 'wrong' about the values. [] @@ -55,74 +55,74 @@ module MathHelper = Assert.Equal(a,b) Assert.True(MathHelper.ApproximatelyEqual(a,b,0)) - [ |], MaxTest = 10000)>] + [ |])>] module ``ApproximatelyEqual (single-precision epsilon)`` = // [] let ``ApproximatelyEqual (single precision) is correct for large positive values``() = - Assert.ApproximatelyEqualEpsilon(1000000.0f, 1000001.0f); - Assert.ApproximatelyEqualEpsilon(1000001.0f, 1000000.0f); + Assert.ApproximatelyEquivalentEpsilon(1000000.0f, 1000001.0f); + Assert.ApproximatelyEquivalentEpsilon(1000001.0f, 1000000.0f); Assert.NotApproximatelyEqualEpsilon(10000.0f, 10001.0f); Assert.NotApproximatelyEqualEpsilon(10001.0f, 10000.0f); [] let ``ApproximatelyEqual (single precision) is correct for large negative values``() = - Assert.ApproximatelyEqualEpsilon(-1000000.0f, -1000001.0f); - Assert.ApproximatelyEqualEpsilon(-1000001.0f, -1000000.0f); + Assert.ApproximatelyEquivalentEpsilon(-1000000.0f, -1000001.0f); + Assert.ApproximatelyEquivalentEpsilon(-1000001.0f, -1000000.0f); Assert.NotApproximatelyEqualEpsilon(-10000.0f, -10001.0f); Assert.NotApproximatelyEqualEpsilon(-10001.0f, -10000.0f); [] let ``ApproximatelyEqual (single precision) is correct for positive values around 1``() = - Assert.ApproximatelyEqualEpsilon(1.0000001f, 1.0000002f); - Assert.ApproximatelyEqualEpsilon(1.0000002f, 1.0000001f); + Assert.ApproximatelyEquivalentEpsilon(1.0000001f, 1.0000002f); + Assert.ApproximatelyEquivalentEpsilon(1.0000002f, 1.0000001f); Assert.NotApproximatelyEqualEpsilon(1.0002f, 1.0001f); Assert.NotApproximatelyEqualEpsilon(1.0001f, 1.0002f); [] let ``ApproximatelyEqual (single precision) is correct for negative values around -1``() = - Assert.ApproximatelyEqualEpsilon(-1.000001f, -1.000002f); - Assert.ApproximatelyEqualEpsilon(-1.000002f, -1.000001f); + Assert.ApproximatelyEquivalentEpsilon(-1.000001f, -1.000002f); + Assert.ApproximatelyEquivalentEpsilon(-1.000002f, -1.000001f); Assert.NotApproximatelyEqualEpsilon(-1.0001f, -1.0002f); Assert.NotApproximatelyEqualEpsilon(-1.0002f, -1.0001f); [] let ``ApproximatelyEqual (single precision) is correct for values between 1 and 0``() = - Assert.ApproximatelyEqualEpsilon(0.000000001000001f, 0.000000001000002f); - Assert.ApproximatelyEqualEpsilon(0.000000001000002f, 0.000000001000001f); + Assert.ApproximatelyEquivalentEpsilon(0.000000001000001f, 0.000000001000002f); + Assert.ApproximatelyEquivalentEpsilon(0.000000001000002f, 0.000000001000001f); Assert.NotApproximatelyEqualEpsilon(0.000000000001002f, 0.000000000001001f); Assert.NotApproximatelyEqualEpsilon(0.000000000001001f, 0.000000000001002f); [] let ``ApproximatelyEqual (single precision) is correct for values between -1 and 0``() = - Assert.ApproximatelyEqualEpsilon(-0.000000001000001f, -0.000000001000002f); - Assert.ApproximatelyEqualEpsilon(-0.000000001000002f, -0.000000001000001f); + Assert.ApproximatelyEquivalentEpsilon(-0.000000001000001f, -0.000000001000002f); + Assert.ApproximatelyEquivalentEpsilon(-0.000000001000002f, -0.000000001000001f); Assert.NotApproximatelyEqualEpsilon(-0.000000000001002f, -0.000000000001001f); Assert.NotApproximatelyEqualEpsilon(-0.000000000001001f, -0.000000000001002f); [] let ``ApproximatelyEqual (single precision) is correct for comparisons involving 0``() = - Assert.ApproximatelyEqualEpsilon(0.0f, 0.0f); - Assert.ApproximatelyEqualEpsilon(0.0f, -0.0f); - Assert.ApproximatelyEqualEpsilon(-0.0f, -0.0f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, 0.0f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, -0.0f); + Assert.ApproximatelyEquivalentEpsilon(-0.0f, -0.0f); Assert.NotApproximatelyEqualEpsilon(0.00000001f, 0.0f); Assert.NotApproximatelyEqualEpsilon(0.0f, 0.00000001f); Assert.NotApproximatelyEqualEpsilon(-0.00000001f, 0.0f); Assert.NotApproximatelyEqualEpsilon(0.0f, -0.00000001f); - Assert.ApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.01f); - Assert.ApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.01f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, 1e-40f, 0.01f); + Assert.ApproximatelyEquivalentEpsilon(1e-40f, 0.0f, 0.01f); Assert.NotApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.000001f); Assert.NotApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.000001f); - Assert.ApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.1f); - Assert.ApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.1f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, -1e-40f, 0.1f); + Assert.ApproximatelyEquivalentEpsilon(-1e-40f, 0.0f, 0.1f); Assert.NotApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.00000001f); Assert.NotApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.00000001f); [] let ``ApproximatelyEqual (single precision) is correct for extreme values with overflow potential``() = - Assert.ApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue); + Assert.ApproximatelyEquivalentEpsilon(System.Single.MaxValue, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue / 2.0f); @@ -131,8 +131,8 @@ module MathHelper = [] let ``ApproximatelyEqual (single precision) is correct for values involving infinities``() = - Assert.ApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity); - Assert.ApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity); + Assert.ApproximatelyEquivalentEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity); + Assert.ApproximatelyEquivalentEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity); Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.PositiveInfinity); Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, -System.Single.MaxValue); @@ -163,92 +163,92 @@ module MathHelper = Assert.NotApproximatelyEqualEpsilon(-1.0f, 1.000000001f); Assert.NotApproximatelyEqualEpsilon(-1.000000001f, 1.0f); Assert.NotApproximatelyEqualEpsilon(1.0f, -1.000000001f); - Assert.ApproximatelyEqualEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(10000.0f * System.Single.Epsilon, 10000.0f * -System.Single.Epsilon); [] let ``ApproximatelyEqual (single precision) is correct for values very close to 0``() = - Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.Epsilon); - Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, -System.Single.Epsilon); - Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.Epsilon); - Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, 0.0f); - Assert.ApproximatelyEqualEpsilon(0.0f, System.Single.Epsilon); - Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.0f); - Assert.ApproximatelyEqualEpsilon(0.0f, -System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, -System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(-System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, System.Single.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(-System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEquivalentEpsilon(0.0f, -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001f, -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001f, System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(System.Single.Epsilon, 0.000000001f); Assert.NotApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.000000001f); - [ |], MaxTest = 10000)>] + [ |])>] module ``ApproximatelyEqual (double-precision epsilon)`` = // [] let ``ApproximatelyEqual (double precision) is correct for large positive values``() = - Assert.ApproximatelyEqualEpsilon(1000000.0, 1000001.0); - Assert.ApproximatelyEqualEpsilon(1000001.0, 1000000.0); + Assert.ApproximatelyEquivalentEpsilon(1000000.0, 1000001.0); + Assert.ApproximatelyEquivalentEpsilon(1000001.0, 1000000.0); Assert.NotApproximatelyEqualEpsilon(10000.0, 10001.0); Assert.NotApproximatelyEqualEpsilon(10001.0, 10000.0); [] let ``ApproximatelyEqual (double precision) is correct for large negative values``() = - Assert.ApproximatelyEqualEpsilon(-1000000.0, -1000001.0); - Assert.ApproximatelyEqualEpsilon(-1000001.0, -1000000.0); + Assert.ApproximatelyEquivalentEpsilon(-1000000.0, -1000001.0); + Assert.ApproximatelyEquivalentEpsilon(-1000001.0, -1000000.0); Assert.NotApproximatelyEqualEpsilon(-10000.0, -10001.0); Assert.NotApproximatelyEqualEpsilon(-10001.0, -10000.0); [] let ``ApproximatelyEqual (double precision) is correct for positive values around 1``() = - Assert.ApproximatelyEqualEpsilon(1.0000001, 1.0000002); - Assert.ApproximatelyEqualEpsilon(1.0000002, 1.0000001); + Assert.ApproximatelyEquivalentEpsilon(1.0000001, 1.0000002); + Assert.ApproximatelyEquivalentEpsilon(1.0000002, 1.0000001); Assert.NotApproximatelyEqualEpsilon(1.0002, 1.0001); Assert.NotApproximatelyEqualEpsilon(1.0001, 1.0002); [] let ``ApproximatelyEqual (double precision) is correct for negative values around -1``() = - Assert.ApproximatelyEqualEpsilon(-1.000001, -1.000002); - Assert.ApproximatelyEqualEpsilon(-1.000002, -1.000001); + Assert.ApproximatelyEquivalentEpsilon(-1.000001, -1.000002); + Assert.ApproximatelyEquivalentEpsilon(-1.000002, -1.000001); Assert.NotApproximatelyEqualEpsilon(-1.0001, -1.0002); Assert.NotApproximatelyEqualEpsilon(-1.0002, -1.0001); [] let ``ApproximatelyEqual (double precision) is correct for values between 1 and 0``() = - Assert.ApproximatelyEqualEpsilon(0.000000001000001, 0.000000001000002); - Assert.ApproximatelyEqualEpsilon(0.000000001000002, 0.000000001000001); + Assert.ApproximatelyEquivalentEpsilon(0.000000001000001, 0.000000001000002); + Assert.ApproximatelyEquivalentEpsilon(0.000000001000002, 0.000000001000001); Assert.NotApproximatelyEqualEpsilon(0.000000000001002, 0.000000000001001); Assert.NotApproximatelyEqualEpsilon(0.000000000001001, 0.000000000001002); [] let ``ApproximatelyEqual (double precision) is correct for values between -1 and 0``() = - Assert.ApproximatelyEqualEpsilon(-0.000000001000001, -0.000000001000002); - Assert.ApproximatelyEqualEpsilon(-0.000000001000002, -0.000000001000001); + Assert.ApproximatelyEquivalentEpsilon(-0.000000001000001, -0.000000001000002); + Assert.ApproximatelyEquivalentEpsilon(-0.000000001000002, -0.000000001000001); Assert.NotApproximatelyEqualEpsilon(-0.000000000001002, -0.000000000001001); Assert.NotApproximatelyEqualEpsilon(-0.000000000001001, -0.000000000001002); [] let ``ApproximatelyEqual (double precision) is correct for comparisons involving 0``() = - Assert.ApproximatelyEqualEpsilon(0.0, 0.0); - Assert.ApproximatelyEqualEpsilon(0.0, -0.0); - Assert.ApproximatelyEqualEpsilon(-0.0, -0.0); + Assert.ApproximatelyEquivalentEpsilon(0.0, 0.0); + Assert.ApproximatelyEquivalentEpsilon(0.0, -0.0); + Assert.ApproximatelyEquivalentEpsilon(-0.0, -0.0); Assert.NotApproximatelyEqualEpsilon(0.00000001, 0.0); Assert.NotApproximatelyEqualEpsilon(0.0, 0.00000001); Assert.NotApproximatelyEqualEpsilon(-0.00000001, 0.0); Assert.NotApproximatelyEqualEpsilon(0.0, -0.00000001); - Assert.ApproximatelyEqualEpsilon(0.0, 1e-310, 0.01); - Assert.ApproximatelyEqualEpsilon(1e-310, 0.0, 0.01); + Assert.ApproximatelyEquivalentEpsilon(0.0, 1e-310, 0.01); + Assert.ApproximatelyEquivalentEpsilon(1e-310, 0.0, 0.01); Assert.NotApproximatelyEqualEpsilon(1e-310, 0.0, 0.000001); Assert.NotApproximatelyEqualEpsilon(0.0, 1e-310, 0.000001); - Assert.ApproximatelyEqualEpsilon(0.0, -1e-310, 0.1); - Assert.ApproximatelyEqualEpsilon(-1e-310, 0.0, 0.1); + Assert.ApproximatelyEquivalentEpsilon(0.0, -1e-310, 0.1); + Assert.ApproximatelyEquivalentEpsilon(-1e-310, 0.0, 0.1); Assert.NotApproximatelyEqualEpsilon(-1e-310, 0.0, 0.00000001); Assert.NotApproximatelyEqualEpsilon(0.0, -1e-310, 0.00000001); [] let ``ApproximatelyEqual (double precision) is correct for extreme values with overflow potential``() = - Assert.ApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue); + Assert.ApproximatelyEquivalentEpsilon(System.Double.MaxValue, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue / 2.0); @@ -257,8 +257,8 @@ module MathHelper = [] let ``ApproximatelyEqual (double precision) is correct for values involving infinities``() = - Assert.ApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity); - Assert.ApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity); + Assert.ApproximatelyEquivalentEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity); + Assert.ApproximatelyEquivalentEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity); Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.PositiveInfinity); Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, -System.Double.MaxValue); @@ -289,25 +289,25 @@ module MathHelper = Assert.NotApproximatelyEqualEpsilon(-1.0, 1.000000001); Assert.NotApproximatelyEqualEpsilon(-1.000000001, 1.0); Assert.NotApproximatelyEqualEpsilon(1.0, -1.000000001); - Assert.ApproximatelyEqualEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(100000000000.0 * System.Double.Epsilon, 100000000000.0 * -System.Double.Epsilon); [] let ``ApproximatelyEqual (double precision) is correct for values very close to 0``() = - Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.Epsilon); - Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, -System.Double.Epsilon); - Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.Epsilon); - Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, 0.0); - Assert.ApproximatelyEqualEpsilon(0.0, System.Double.Epsilon); - Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.0); - Assert.ApproximatelyEqualEpsilon(0.0, -System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, -System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(-System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, 0.0); + Assert.ApproximatelyEquivalentEpsilon(0.0, System.Double.Epsilon); + Assert.ApproximatelyEquivalentEpsilon(-System.Double.Epsilon, 0.0); + Assert.ApproximatelyEquivalentEpsilon(0.0, -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001, -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001, System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, 0.000000001); Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.000000001); - [ |], MaxTest = 10000)>] + [ |])>] module ``ApproximatelyEquivalent (tolerance diff)`` = [] let ``ApproximatelyEquivalent correctly approximates equivalence where the difference falls below the tolerance``() = @@ -317,11 +317,11 @@ module MathHelper = Assert.True(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) [] - let ``ApproximatelyEquivalent correctly approximates inequivalence where the difference is the tolerance``() = + let ``ApproximatelyEquivalent correctly approximates equivalence where the difference is the tolerance``() = let a = 0.0001f let b = 0.0002f Assert.NotEqual(a,b) - Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) + Assert.True(MathHelper.ApproximatelyEquivalent(a, b, 0.0001f)) [] let ``ApproximatelyEquivalent correctly approximates inequivalence where the difference exceeds the tolerance``() = @@ -332,7 +332,7 @@ module MathHelper = [] let ``ApproximatelyEquivalent reports very different values as non-equal even with a high tolerance``() = - let a = 2.0f + let a = 3.0f let b = 1.0f Assert.NotEqual(a,b) Assert.False(MathHelper.ApproximatelyEquivalent(a, b, 1.0f)) diff --git a/tests/OpenTK.Tests/Matrix4Tests.fs b/tests/OpenTK.Tests/Matrix4Tests.fs index 43dc471c..e4ca3f5d 100644 --- a/tests/OpenTK.Tests/Matrix4Tests.fs +++ b/tests/OpenTK.Tests/Matrix4Tests.fs @@ -7,7 +7,7 @@ open System open OpenTK module Matrix4 = - [ |], MaxTest = 10000)>] + [ |])>] module Constructors = // [] @@ -88,7 +88,7 @@ module Matrix4 = Assert.Equal(o, A.M43) Assert.Equal(p, A.M44) - [ |], MaxTest = 10000)>] + [ |])>] module Equality = // [] @@ -103,7 +103,7 @@ module Matrix4 = let ``A matrix is not equal to an object which is not a matrix`` (a : Matrix4, b : Vector3) = Assert.False(a.Equals(b)) - [ |], MaxTest = 10000)>] + [ |])>] module Multiplication = // [] @@ -202,7 +202,7 @@ module Matrix4 = Assert.Equal(R4, AScaled.Row3) - [ |], MaxTest = 10000)>] + [ |])>] module Addition = // [] @@ -232,7 +232,7 @@ module Matrix4 = Assert.Equal(o + o, sum.M43) Assert.Equal(p + p, sum.M44) - [ |], MaxTest = 10000)>] + [ |])>] module Subtraction = // [] @@ -262,7 +262,7 @@ module Matrix4 = Assert.Equal(o - o, sub.M43) Assert.Equal(p - p, sub.M44) - [ |], MaxTest = 10000)>] + [ |])>] module Indexing = // [] @@ -363,7 +363,7 @@ module Matrix4 = (fun() -> a.[1, 6] |> ignore) |> Assert.ThrowsIndexExn (fun() -> a.[7, 12] |> ignore) |> Assert.ThrowsIndexExn - [ |], MaxTest = 10000)>] + [ |])>] module ``Row and column properties`` = // [] diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index ae595064..e44d8de6 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector2 = - [ |], MaxTest = 10000)>] + [ |])>] module Constructors = // [] @@ -23,7 +23,7 @@ module Vector2 = Assert.Equal(x,v.X) Assert.Equal(y,v.Y) - [ |], MaxTest = 10000)>] + [ |])>] module Clamping = // [] @@ -46,7 +46,7 @@ module Vector2 = Assert.Equal(expX, res.X) Assert.Equal(expY, res.Y) - [ |], MaxTest = 10000)>] + [ |])>] module Length = // [] @@ -75,7 +75,7 @@ module Vector2 = Assert.Equal(lsq, v.LengthSquared) - [ |], MaxTest = 10000)>] + [ |])>] module ``Unit vectors and perpendicularity`` = // [] @@ -92,7 +92,7 @@ module Vector2 = Assert.Equal(perp, v.PerpendicularLeft) - [ |], MaxTest = 10000)>] + [ |])>] module Indexing = // [] @@ -126,7 +126,7 @@ module Vector2 = (fun() -> v.[2] |> ignore) |> Assert.ThrowsIndexExn - [ |], MaxTest = 10000)>] + [ |])>] module ``Simple Properties`` = // [] @@ -139,26 +139,26 @@ module Vector2 = // Assert.True(a.Length >= 0.0f) - [ |], MaxTest = 10000)>] + [ |])>] module Addition = // [] let ``Vector addition is the same as component addition`` (a : Vector2,b : Vector2) = let c = a + b - Assert.ApproximatelyEqual(a.X + b.X,c.X) - Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) + Assert.ApproximatelyEquivalent(a.X + b.X,c.X) + Assert.ApproximatelyEquivalent(a.Y + b.Y,c.Y) [] let ``Vector addition is commutative`` (a : Vector2,b : Vector2) = let c = a + b let c2 = b + a - Assert.ApproximatelyEqual(c,c2) + Assert.ApproximatelyEquivalent(c,c2) [] let ``Vector addition is associative`` (a : Vector2,b : Vector2,c : Vector2) = let r1 = (a + b) + c let r2 = a + (b + c) - Assert.ApproximatelyEqual(r1,r2) + Assert.ApproximatelyEquivalent(r1,r2) [] let ``Static Vector2 addition method is the same as component addition`` (a : Vector2, b : Vector2) = @@ -166,7 +166,7 @@ module Vector2 = let v1 = Vector2(a.X + b.X, a.Y + b.Y) let sum = Vector2.Add(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2 addition method by reference is the same as component addition`` (a : Vector2, b : Vector2) = @@ -174,9 +174,9 @@ module Vector2 = let v1 = Vector2(a.X + b.X, a.Y + b.Y) let sum = Vector2.Add(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Multiplication = // [] @@ -210,7 +210,7 @@ module Vector2 = let v1 = Vector2(a.X * b.X, a.Y * b.Y) let sum = Vector2.Multiply(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2 multiplication method by reference is the same as component multiplication`` (a : Vector2, b : Vector2) = @@ -218,7 +218,7 @@ module Vector2 = let v1 = Vector2(a.X * b.X, a.Y * b.Y) let sum = Vector2.Multiply(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static method Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) = @@ -227,7 +227,7 @@ module Vector2 = Assert.Equal(a.X * f,r.X) Assert.Equal(a.Y * f,r.Y) - [ |], MaxTest = 10000)>] + [ |])>] module Subtraction = // [] @@ -242,7 +242,7 @@ module Vector2 = let v1 = Vector2(a.X - b.X, a.Y - b.Y) let sum = Vector2.Subtract(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2 subtraction method by reference is the same as component addition`` (a : Vector2, b : Vector2) = @@ -250,9 +250,9 @@ module Vector2 = let v1 = Vector2(a.X - b.X, a.Y - b.Y) let sum = Vector2.Subtract(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Division = // [] @@ -260,8 +260,8 @@ module Vector2 = if not (approxEq f 0.0f) then let r = a / f - Assert.ApproximatelyEqual(a.X / f,r.X) - Assert.ApproximatelyEqual(a.Y / f,r.Y) + Assert.ApproximatelyEquivalent(a.X / f,r.X) + Assert.ApproximatelyEquivalent(a.Y / f,r.Y) [] let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) = @@ -269,7 +269,7 @@ module Vector2 = let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) = @@ -277,7 +277,7 @@ module Vector2 = let v1 = Vector2(a.X / b.X, a.Y / b.Y) let sum = Vector2.Divide(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) = @@ -285,7 +285,7 @@ module Vector2 = let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) = @@ -293,9 +293,9 @@ module Vector2 = let v1 = Vector2(a.X / b, a.Y / b) let sum = Vector2.Divide(ref a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Negation = // [] @@ -305,7 +305,7 @@ module Vector2 = Assert.Equal(-x, vNeg.X) Assert.Equal(-y, vNeg.Y) - [ |], MaxTest = 10000)>] + [ |])>] module Equality = // [] @@ -336,7 +336,7 @@ module Vector2 = Assert.True(equality) Assert.False(inequalityByOtherType) - [ |], MaxTest = 10000)>] + [ |])>] module Swizzling = // [] @@ -347,7 +347,7 @@ module Vector2 = let v1yx = v1.Yx; Assert.Equal(v2, v1yx); - [ |], MaxTest = 10000)>] + [ |])>] module Interpolation = // [] @@ -374,7 +374,7 @@ module Vector2 = let vRes = Vector2.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module ``Vector products`` = // [] @@ -395,7 +395,7 @@ module Vector2 = let vRes = Vector2.PerpDot(ref a, ref b) Assert.Equal(perpDot, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module Normalization = // [] @@ -407,8 +407,8 @@ module Vector2 = if not (approxEq l 0.0f) then let norm = v.Normalized() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) [] let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = @@ -419,8 +419,8 @@ module Vector2 = let norm = Vector2(a, b) norm.Normalize() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) [] let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b) = @@ -430,8 +430,8 @@ module Vector2 = let scale = MathHelper.InverseSqrtFast(a * a + b * b) - Assert.ApproximatelyEqual(v.X * scale, norm.X) - Assert.ApproximatelyEqual(v.Y * scale, norm.Y) + Assert.ApproximatelyEquivalent(v.X * scale, norm.X) + Assert.ApproximatelyEquivalent(v.Y * scale, norm.Y) [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector2) = @@ -440,7 +440,7 @@ module Vector2 = let norm = a / a.Length let vRes = Vector2.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector2) = @@ -448,7 +448,7 @@ module Vector2 = if not (approxEq a.Length 0.0f) then let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector2.Normalize(a)); + Assert.ApproximatelyEquivalent(norm, Vector2.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector2) = @@ -457,7 +457,7 @@ module Vector2 = let norm = a * scale let vRes = Vector2.NormalizeFast(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector2) = @@ -465,9 +465,9 @@ module Vector2 = let norm = a * scale - Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); + Assert.ApproximatelyEquivalent(norm, Vector2.NormalizeFast(a)); - [ |], MaxTest = 10000)>] + [ |])>] module ``Magnitude min and max`` = // [] @@ -534,7 +534,7 @@ module Vector2 = let v2LongerThanv1 = l2 > l1 Assert.True(v2LongerThanv1) - [ |], MaxTest = 10000)>] + [ |])>] module ``Component min and max`` = // [] @@ -569,7 +569,7 @@ module Vector2 = Assert.True(isComponentLargest vMax.X v1.X v2.X) Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) - [ |], MaxTest = 10000)>] + [ |])>] module Transformation = // [] @@ -580,7 +580,7 @@ module Vector2 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(v, q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector2.Transform(v, q)) [] let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector2, q : Quaternion) = @@ -590,9 +590,9 @@ module Vector2 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector2(transformedQuat.X, transformedQuat.Y) - Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(ref v, ref q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector2.Transform(ref v, ref q)) - [ |], MaxTest = 10000)>] + [ |])>] module Serialization = // [] diff --git a/tests/OpenTK.Tests/Vector3Tests.fs b/tests/OpenTK.Tests/Vector3Tests.fs index 6428684e..c12c0f18 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector3 = - [ |], MaxTest = 10000)>] + [ |])>] module Constructors = // [] @@ -65,7 +65,7 @@ module Vector3 = Assert.Equal(b, v2.Y) Assert.Equal(c, v2.Z) - [ |], MaxTest = 10000)>] + [ |])>] module Indexing = // [] @@ -100,7 +100,7 @@ module Vector3 = (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn - [ |], MaxTest = 10000)>] + [ |])>] module Length = // [] @@ -124,7 +124,7 @@ module Vector3 = Assert.Equal(lsq, v.LengthSquared) - [ |], MaxTest = 10000)>] + [ |])>] module Normalization = // [] @@ -136,9 +136,9 @@ module Vector3 = if not (approxEq l 0.0f) then let norm = v.Normalized() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.Z / l, norm.Z) [] let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = @@ -149,9 +149,9 @@ module Vector3 = let norm = Vector3(a, b, c) norm.Normalize() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.Z / l, norm.Z) [] let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (a, b, c) = @@ -161,9 +161,9 @@ module Vector3 = let scale = MathHelper.InverseSqrtFast(a * a + b * b + c * c) - Assert.ApproximatelyEqual(v.X * scale, norm.X) - Assert.ApproximatelyEqual(v.Y * scale, norm.Y) - Assert.ApproximatelyEqual(v.Z * scale, norm.Z) + Assert.ApproximatelyEquivalent(v.X * scale, norm.X) + Assert.ApproximatelyEquivalent(v.Y * scale, norm.Y) + Assert.ApproximatelyEquivalent(v.Z * scale, norm.Z) [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector3) = @@ -172,7 +172,7 @@ module Vector3 = let norm = a / a.Length let vRes = Vector3.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector3) = @@ -180,7 +180,7 @@ module Vector3 = if not (approxEq a.Length 0.0f) then let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector3.Normalize(a)); + Assert.ApproximatelyEquivalent(norm, Vector3.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector3) = @@ -189,7 +189,7 @@ module Vector3 = let norm = a * scale let vRes = Vector3.NormalizeFast(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Fast approximate normalization is the same as multiplication by fast inverse square`` (a : Vector3) = @@ -197,32 +197,32 @@ module Vector3 = let norm = a * scale - Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a)); + Assert.ApproximatelyEquivalent(norm, Vector3.NormalizeFast(a)); - [ |], MaxTest = 10000)>] + [ |])>] module Addition = // [] let ``Vector3 addition is the same as component addition`` (a : Vector3, b : Vector3) = let c = a + b - Assert.ApproximatelyEqual(a.X + b.X,c.X) - Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) - Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) + Assert.ApproximatelyEquivalent(a.X + b.X,c.X) + Assert.ApproximatelyEquivalent(a.Y + b.Y,c.Y) + Assert.ApproximatelyEquivalent(a.Z + b.Z,c.Z) [] let ``Vector3 addition is commutative`` (a : Vector3, b : Vector3) = let c = a + b let c2 = b + a - Assert.ApproximatelyEqual(c, c2) + Assert.ApproximatelyEquivalent(c, c2) [] let ``Vector3 addition is associative`` (a : Vector3, b : Vector3, c : Vector3) = let r1 = (a + b) + c let r2 = a + (b + c) - Assert.ApproximatelyEqual(r1, r2) + Assert.ApproximatelyEquivalent(r1, r2) [] let ``Static Vector3 addition method is the same as component addition`` (a : Vector3, b : Vector3) = @@ -230,7 +230,7 @@ module Vector3 = let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3 addition method by reference is the same as component addition`` (a : Vector3, b : Vector3) = @@ -238,9 +238,9 @@ module Vector3 = let v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z) let sum = Vector3.Add(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Subtraction = // [] @@ -257,7 +257,7 @@ module Vector3 = let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3 subtraction method by reference is the same as component addition`` (a : Vector3, b : Vector3) = @@ -265,9 +265,9 @@ module Vector3 = let v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z) let sum = Vector3.Subtract(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Multiplication = // [] @@ -338,7 +338,7 @@ module Vector3 = let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3 multiplication method by reference is the same as component multiplication`` (a : Vector3, b : Vector3) = @@ -346,9 +346,9 @@ module Vector3 = let v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z) let sum = Vector3.Multiply(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Division = // [] @@ -356,9 +356,9 @@ module Vector3 = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f - Assert.ApproximatelyEqual(a.X / f,r.X) - Assert.ApproximatelyEqual(a.Y / f,r.Y) - Assert.ApproximatelyEqual(a.Z / f,r.Z) + Assert.ApproximatelyEquivalent(a.X / f,r.X) + Assert.ApproximatelyEquivalent(a.Y / f,r.Y) + Assert.ApproximatelyEquivalent(a.Z / f,r.Z) [] let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) = @@ -366,7 +366,7 @@ module Vector3 = let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) = @@ -374,7 +374,7 @@ module Vector3 = let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z) let sum = Vector3.Divide(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) = @@ -382,7 +382,7 @@ module Vector3 = let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) = @@ -390,9 +390,9 @@ module Vector3 = let v1 = Vector3(a.X / b, a.Y / b, a.Z / b) let sum = Vector3.Divide(ref a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Negation = // [] @@ -403,7 +403,7 @@ module Vector3 = Assert.Equal(-y, vNeg.Y) Assert.Equal(-z, vNeg.Z) - [ |], MaxTest = 10000)>] + [ |])>] module Equality = // [] @@ -434,7 +434,7 @@ module Vector3 = Assert.True(equality) Assert.False(inequalityByOtherType) - [ |], MaxTest = 10000)>] + [ |])>] module Swizzling = // [] @@ -479,7 +479,7 @@ module Vector3 = Assert.Equal(zx, v.Zx); Assert.Equal(zy, v.Zy); - [ |], MaxTest = 10000)>] + [ |])>] module Interpolation = // [] @@ -507,7 +507,7 @@ module Vector3 = let vRes = Vector3.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module ``Vector products`` = // [] @@ -531,7 +531,7 @@ module Vector3 = let vRes = Vector3.Cross(ref a, ref b) Assert.Equal(cross, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module ``Magnitude min and max`` = // [] @@ -598,7 +598,7 @@ module Vector3 = let v2LongerThanv1 = l2 > l1 Assert.True(v2LongerThanv1) - [ |], MaxTest = 10000)>] + [ |])>] module ``Component min and max`` = // [] @@ -637,7 +637,7 @@ module Vector3 = Assert.True(isComponentLargest vMax.Y v1.Y v2.Y) Assert.True(isComponentLargest vMax.Z v1.Z v2.Z) - [ |], MaxTest = 10000)>] + [ |])>] module Clamping = // [] @@ -664,7 +664,7 @@ module Vector3 = Assert.Equal(expY, res.Y) Assert.Equal(expZ, res.Z) - [ |], MaxTest = 10000)>] + [ |])>] module ``Unit vectors``= // [] @@ -697,7 +697,7 @@ module Vector3 = Assert.Equal(Vector3.One, unitOne) - [ |], MaxTest = 10000)>] + [ |])>] module Serialization = // [] @@ -707,7 +707,7 @@ module Vector3 = Assert.Equal(expectedSize, Vector3.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector3())) - [ |], MaxTest = 10000)>] + [ |])>] module Transformation = // [] @@ -718,7 +718,7 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(v, q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector3.Transform(v, q)) [] let ``Transformation by quaternion by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = @@ -728,7 +728,7 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(ref v, ref q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector3.Transform(ref v, ref q)) [] let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector3, q : Quaternion) = @@ -738,7 +738,7 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.ApproximatelyEqual(transformedVector, q * v) + Assert.ApproximatelyEquivalent(transformedVector, q * v) [] let ``Transformation by identity quaternion does not alter vector`` (v : Vector3) = @@ -749,6 +749,6 @@ module Vector3 = let transformedQuat = q * vectorQuat * inverse let transformedVector = transformedQuat.Xyz - Assert.ApproximatelyEqual(v, transformedVector) - Assert.ApproximatelyEqual(v, Vector3.Transform(v, q)) - Assert.ApproximatelyEqual(transformedVector, Vector3.Transform(v, q)) \ No newline at end of file + Assert.ApproximatelyEquivalent(v, transformedVector) + Assert.ApproximatelyEquivalent(v, Vector3.Transform(v, q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector3.Transform(v, q)) \ No newline at end of file diff --git a/tests/OpenTK.Tests/Vector4Tests.fs b/tests/OpenTK.Tests/Vector4Tests.fs index df8a9b6e..a7fce208 100644 --- a/tests/OpenTK.Tests/Vector4Tests.fs +++ b/tests/OpenTK.Tests/Vector4Tests.fs @@ -8,7 +8,7 @@ open System.Runtime.InteropServices open OpenTK module Vector4 = - [ |], MaxTest = 10000)>] + [ |])>] module Constructors = // [] @@ -85,7 +85,7 @@ module Vector4 = Assert.Equal(z, v2.Z) Assert.Equal(w, v2.W) - [ |], MaxTest = 10000)>] + [ |])>] module Indexing = // [] @@ -121,7 +121,7 @@ module Vector4 = (fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn - [ |], MaxTest = 10000)>] + [ |])>] module Length = // [] @@ -145,7 +145,7 @@ module Vector4 = Assert.Equal(lsq, v.LengthSquared) - [ |], MaxTest = 10000)>] + [ |])>] module Normalization = // [] @@ -157,10 +157,10 @@ module Vector4 = if not (approxEq l 0.0f) then let norm = v.Normalized() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.Z / l, norm.Z) + Assert.ApproximatelyEquivalent(v.W / l, norm.W) [] let ``Normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = @@ -172,10 +172,10 @@ module Vector4 = let norm = Vector4(x, y, z, w) norm.Normalize() - Assert.ApproximatelyEqual(v.X / l, norm.X) - Assert.ApproximatelyEqual(v.Y / l, norm.Y) - Assert.ApproximatelyEqual(v.Z / l, norm.Z) - Assert.ApproximatelyEqual(v.W / l, norm.W) + Assert.ApproximatelyEquivalent(v.X / l, norm.X) + Assert.ApproximatelyEquivalent(v.Y / l, norm.Y) + Assert.ApproximatelyEquivalent(v.Z / l, norm.Z) + Assert.ApproximatelyEquivalent(v.W / l, norm.W) [] let ``Fast approximate normalization of instance transforms the instance into a unit length vector with the correct components`` (x, y, z, w) = @@ -185,10 +185,10 @@ module Vector4 = let scale = MathHelper.InverseSqrtFast(x * x + y * y + z * z + w * w) - Assert.ApproximatelyEqual(v.X * scale, norm.X) - Assert.ApproximatelyEqual(v.Y * scale, norm.Y) - Assert.ApproximatelyEqual(v.Z * scale, norm.Z) - Assert.ApproximatelyEqual(v.W * scale, norm.W) + Assert.ApproximatelyEquivalent(v.X * scale, norm.X) + Assert.ApproximatelyEquivalent(v.Y * scale, norm.Y) + Assert.ApproximatelyEquivalent(v.Z * scale, norm.Z) + Assert.ApproximatelyEquivalent(v.W * scale, norm.W) [] let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) = @@ -197,7 +197,7 @@ module Vector4 = let norm = a / a.Length let vRes = Vector4.Normalize(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Normalization is the same as division by magnitude`` (a : Vector4) = @@ -205,7 +205,7 @@ module Vector4 = if not (approxEq a.Length 0.0f) then let norm = a / a.Length - Assert.ApproximatelyEqual(norm, Vector4.Normalize(a)); + Assert.ApproximatelyEquivalent(norm, Vector4.Normalize(a)); [] let ``Fast approximate normalization by reference is the same as multiplication by the fast inverse square`` (a : Vector4) = @@ -214,40 +214,40 @@ module Vector4 = let norm = a * scale let vRes = Vector4.NormalizeFast(ref a) - Assert.ApproximatelyEqual(norm, vRes) + Assert.ApproximatelyEquivalent(norm, vRes) [] let ``Fast approximate normalization is the same as multiplication by the fast inverse square`` (a : Vector4) = let scale = MathHelper.InverseSqrtFast(a.X * a.X + a.Y * a.Y + a.Z * a.Z + a.W * a.W) let norm = a * scale - Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a)); + Assert.ApproximatelyEquivalent(norm, Vector4.NormalizeFast(a)); - [ |], MaxTest = 10000)>] + [ |])>] module Addition = // [] let ``Vector4 addition is the same as component addition`` (a : Vector4, b : Vector4) = let c = a + b - Assert.ApproximatelyEqual(a.X + b.X,c.X) - Assert.ApproximatelyEqual(a.Y + b.Y,c.Y) - Assert.ApproximatelyEqual(a.Z + b.Z,c.Z) - Assert.ApproximatelyEqual(a.W + b.W,c.W) + Assert.ApproximatelyEquivalent(a.X + b.X,c.X) + Assert.ApproximatelyEquivalent(a.Y + b.Y,c.Y) + Assert.ApproximatelyEquivalent(a.Z + b.Z,c.Z) + Assert.ApproximatelyEquivalent(a.W + b.W,c.W) [] let ``Vector4 addition is commutative`` (a : Vector4, b : Vector4) = let c = a + b let c2 = b + a - Assert.ApproximatelyEqual(c, c2) + Assert.ApproximatelyEquivalent(c, c2) [] let ``Vector4 addition is associative`` (a : Vector4, b : Vector4, c : Vector4) = let r1 = (a + b) + c let r2 = a + (b + c) - Assert.ApproximatelyEqual(r1, r2) + Assert.ApproximatelyEquivalent(r1, r2) [] let ``Static Vector4 addition method is the same as component addition`` (a : Vector4, b : Vector4) = @@ -255,7 +255,7 @@ module Vector4 = let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) let sum = Vector4.Add(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4 addition method by reference is the same as component addition`` (a : Vector4, b : Vector4) = @@ -263,9 +263,9 @@ module Vector4 = let v1 = Vector4(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W) let sum = Vector4.Add(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Subtraction = // [] @@ -283,7 +283,7 @@ module Vector4 = let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) let sum = Vector4.Subtract(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4 subtraction method by reference is the same as component addition`` (a : Vector4, b : Vector4) = @@ -291,9 +291,9 @@ module Vector4 = let v1 = Vector4(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W) let sum = Vector4.Subtract(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Multiplication = // [] @@ -371,7 +371,7 @@ module Vector4 = let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) let sum = Vector4.Multiply(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4 multiplication method by reference is the same as component multiplication`` (a : Vector4, b : Vector4) = @@ -379,9 +379,9 @@ module Vector4 = let v1 = Vector4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W) let sum = Vector4.Multiply(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Division = // [] @@ -389,10 +389,10 @@ module Vector4 = if not (approxEq f 0.0f) then // we don't support diving by zero. let r = a / f - Assert.ApproximatelyEqual(a.X / f, r.X) - Assert.ApproximatelyEqual(a.Y / f, r.Y) - Assert.ApproximatelyEqual(a.Z / f, r.Z) - Assert.ApproximatelyEqual(a.W / f, r.W) + Assert.ApproximatelyEquivalent(a.X / f, r.X) + Assert.ApproximatelyEquivalent(a.Y / f, r.Y) + Assert.ApproximatelyEquivalent(a.Z / f, r.Z) + Assert.ApproximatelyEquivalent(a.W / f, r.W) [] let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) = @@ -400,7 +400,7 @@ module Vector4 = let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) = @@ -408,7 +408,7 @@ module Vector4 = let v1 = Vector4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W) let sum = Vector4.Divide(ref a, ref b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) = @@ -416,7 +416,7 @@ module Vector4 = let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) [] let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) = @@ -424,9 +424,9 @@ module Vector4 = let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b) let sum = Vector4.Divide(ref a, b) - Assert.ApproximatelyEqual(v1, sum) + Assert.ApproximatelyEquivalent(v1, sum) - [ |], MaxTest = 10000)>] + [ |])>] module Negation = // [] @@ -438,7 +438,7 @@ module Vector4 = Assert.Equal(-z, vNeg.Z) Assert.Equal(-w, vNeg.W) - [ |], MaxTest = 10000)>] + [ |])>] module Equality = // [] @@ -478,7 +478,7 @@ module Vector4 = Assert.False(inequalityByOtherType) - [ |], MaxTest = 10000)>] + [ |])>] module Swizzling = // [] @@ -657,7 +657,7 @@ module Vector4 = Assert.Equal(wy, v.Wy) Assert.Equal(wz, v.Wz) - [ |], MaxTest = 10000)>] + [ |])>] module Interpolation = // [] @@ -686,7 +686,7 @@ module Vector4 = let vRes = Vector4.BaryCentric(ref a, ref b, ref c, u, v) Assert.Equal(r, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module ``Vector products`` = // [] @@ -698,7 +698,7 @@ module Vector4 = let vRes = Vector4.Dot(ref a, ref b) Assert.Equal(dot, vRes) - [ |], MaxTest = 10000)>] + [ |])>] module ``Magnitude min and max`` = // [] @@ -765,7 +765,7 @@ module Vector4 = let v2LongerThanv1 = l2 > l1 Assert.True(v2LongerThanv1) - [ |], MaxTest = 10000)>] + [ |])>] module ``Component min and max`` = // [] @@ -809,7 +809,7 @@ module Vector4 = Assert.True(isComponentLargest vMax.W v1.W v2.W) - [ |], MaxTest = 10000)>] + [ |])>] module Clamping = // [] @@ -840,7 +840,7 @@ module Vector4 = Assert.Equal(expZ, res.Z) Assert.Equal(expW, res.W) - [ |], MaxTest = 10000)>] + [ |])>] module ``Unit vectors``= // [] @@ -879,7 +879,7 @@ module Vector4 = Assert.Equal(Vector4.One, unitOne) - [ |], MaxTest = 10000)>] + [ |])>] module Serialization = // [] @@ -889,7 +889,7 @@ module Vector4 = Assert.Equal(expectedSize, Vector4.SizeInBytes) Assert.Equal(expectedSize, Marshal.SizeOf(Vector4())) - [ |], MaxTest = 10000)>] + [ |])>] module Transformation = // [] @@ -900,7 +900,7 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) - Assert.ApproximatelyEqual(transformedVector, Vector4.Transform(v, q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector4.Transform(v, q)) [] let ``Transformation by quaternion with static method by reference is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = @@ -910,7 +910,7 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y,transformedQuat.Z, transformedQuat.W) - Assert.ApproximatelyEqual(transformedVector, Vector4.Transform(ref v, ref q)) + Assert.ApproximatelyEquivalent(transformedVector, Vector4.Transform(ref v, ref q)) [] let ``Transformation by quaternion by multiplication using right-handed notation is the same as multiplication by quaternion and its conjugate`` (v : Vector4, q : Quaternion) = @@ -920,4 +920,4 @@ module Vector4 = let transformedQuat = q * vectorQuat * inverse let transformedVector = Vector4(transformedQuat.X, transformedQuat.Y, transformedQuat.Z, transformedQuat.W) - Assert.ApproximatelyEqual(transformedVector, q * v) \ No newline at end of file + Assert.ApproximatelyEquivalent(transformedVector, q * v) \ No newline at end of file From 268c3a02209f28ecc305df955d44a7b4e52bd7d6 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 7 Jun 2017 15:24:20 +0200 Subject: [PATCH 66/66] Corrected bad search & replace. --- tests/OpenTK.Tests/MathHelperTests.fs | 120 +++++++++++++------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/tests/OpenTK.Tests/MathHelperTests.fs b/tests/OpenTK.Tests/MathHelperTests.fs index 542f00cd..76b96e15 100644 --- a/tests/OpenTK.Tests/MathHelperTests.fs +++ b/tests/OpenTK.Tests/MathHelperTests.fs @@ -60,69 +60,69 @@ module MathHelper = // [] let ``ApproximatelyEqual (single precision) is correct for large positive values``() = - Assert.ApproximatelyEquivalentEpsilon(1000000.0f, 1000001.0f); - Assert.ApproximatelyEquivalentEpsilon(1000001.0f, 1000000.0f); + Assert.ApproximatelyEqualEpsilon(1000000.0f, 1000001.0f); + Assert.ApproximatelyEqualEpsilon(1000001.0f, 1000000.0f); Assert.NotApproximatelyEqualEpsilon(10000.0f, 10001.0f); Assert.NotApproximatelyEqualEpsilon(10001.0f, 10000.0f); [] let ``ApproximatelyEqual (single precision) is correct for large negative values``() = - Assert.ApproximatelyEquivalentEpsilon(-1000000.0f, -1000001.0f); - Assert.ApproximatelyEquivalentEpsilon(-1000001.0f, -1000000.0f); + Assert.ApproximatelyEqualEpsilon(-1000000.0f, -1000001.0f); + Assert.ApproximatelyEqualEpsilon(-1000001.0f, -1000000.0f); Assert.NotApproximatelyEqualEpsilon(-10000.0f, -10001.0f); Assert.NotApproximatelyEqualEpsilon(-10001.0f, -10000.0f); [] let ``ApproximatelyEqual (single precision) is correct for positive values around 1``() = - Assert.ApproximatelyEquivalentEpsilon(1.0000001f, 1.0000002f); - Assert.ApproximatelyEquivalentEpsilon(1.0000002f, 1.0000001f); + Assert.ApproximatelyEqualEpsilon(1.0000001f, 1.0000002f); + Assert.ApproximatelyEqualEpsilon(1.0000002f, 1.0000001f); Assert.NotApproximatelyEqualEpsilon(1.0002f, 1.0001f); Assert.NotApproximatelyEqualEpsilon(1.0001f, 1.0002f); [] let ``ApproximatelyEqual (single precision) is correct for negative values around -1``() = - Assert.ApproximatelyEquivalentEpsilon(-1.000001f, -1.000002f); - Assert.ApproximatelyEquivalentEpsilon(-1.000002f, -1.000001f); + Assert.ApproximatelyEqualEpsilon(-1.000001f, -1.000002f); + Assert.ApproximatelyEqualEpsilon(-1.000002f, -1.000001f); Assert.NotApproximatelyEqualEpsilon(-1.0001f, -1.0002f); Assert.NotApproximatelyEqualEpsilon(-1.0002f, -1.0001f); [] let ``ApproximatelyEqual (single precision) is correct for values between 1 and 0``() = - Assert.ApproximatelyEquivalentEpsilon(0.000000001000001f, 0.000000001000002f); - Assert.ApproximatelyEquivalentEpsilon(0.000000001000002f, 0.000000001000001f); + Assert.ApproximatelyEqualEpsilon(0.000000001000001f, 0.000000001000002f); + Assert.ApproximatelyEqualEpsilon(0.000000001000002f, 0.000000001000001f); Assert.NotApproximatelyEqualEpsilon(0.000000000001002f, 0.000000000001001f); Assert.NotApproximatelyEqualEpsilon(0.000000000001001f, 0.000000000001002f); [] let ``ApproximatelyEqual (single precision) is correct for values between -1 and 0``() = - Assert.ApproximatelyEquivalentEpsilon(-0.000000001000001f, -0.000000001000002f); - Assert.ApproximatelyEquivalentEpsilon(-0.000000001000002f, -0.000000001000001f); + Assert.ApproximatelyEqualEpsilon(-0.000000001000001f, -0.000000001000002f); + Assert.ApproximatelyEqualEpsilon(-0.000000001000002f, -0.000000001000001f); Assert.NotApproximatelyEqualEpsilon(-0.000000000001002f, -0.000000000001001f); Assert.NotApproximatelyEqualEpsilon(-0.000000000001001f, -0.000000000001002f); [] let ``ApproximatelyEqual (single precision) is correct for comparisons involving 0``() = - Assert.ApproximatelyEquivalentEpsilon(0.0f, 0.0f); - Assert.ApproximatelyEquivalentEpsilon(0.0f, -0.0f); - Assert.ApproximatelyEquivalentEpsilon(-0.0f, -0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, -0.0f); + Assert.ApproximatelyEqualEpsilon(-0.0f, -0.0f); Assert.NotApproximatelyEqualEpsilon(0.00000001f, 0.0f); Assert.NotApproximatelyEqualEpsilon(0.0f, 0.00000001f); Assert.NotApproximatelyEqualEpsilon(-0.00000001f, 0.0f); Assert.NotApproximatelyEqualEpsilon(0.0f, -0.00000001f); - Assert.ApproximatelyEquivalentEpsilon(0.0f, 1e-40f, 0.01f); - Assert.ApproximatelyEquivalentEpsilon(1e-40f, 0.0f, 0.01f); + Assert.ApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.01f); + Assert.ApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.01f); Assert.NotApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.000001f); Assert.NotApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.000001f); - Assert.ApproximatelyEquivalentEpsilon(0.0f, -1e-40f, 0.1f); - Assert.ApproximatelyEquivalentEpsilon(-1e-40f, 0.0f, 0.1f); + Assert.ApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.1f); + Assert.ApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.1f); Assert.NotApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.00000001f); Assert.NotApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.00000001f); [] let ``ApproximatelyEqual (single precision) is correct for extreme values with overflow potential``() = - Assert.ApproximatelyEquivalentEpsilon(System.Single.MaxValue, System.Single.MaxValue); + Assert.ApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue / 2.0f); @@ -131,8 +131,8 @@ module MathHelper = [] let ``ApproximatelyEqual (single precision) is correct for values involving infinities``() = - Assert.ApproximatelyEquivalentEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity); - Assert.ApproximatelyEquivalentEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity); + Assert.ApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity); + Assert.ApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity); Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.PositiveInfinity); Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, -System.Single.MaxValue); @@ -163,18 +163,18 @@ module MathHelper = Assert.NotApproximatelyEqualEpsilon(-1.0f, 1.000000001f); Assert.NotApproximatelyEqualEpsilon(-1.000000001f, 1.0f); Assert.NotApproximatelyEqualEpsilon(1.0f, -1.000000001f); - Assert.ApproximatelyEquivalentEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(10000.0f * System.Single.Epsilon, 10000.0f * -System.Single.Epsilon); [] let ``ApproximatelyEqual (single precision) is correct for values very close to 0``() = - Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, System.Single.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, -System.Single.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(-System.Single.Epsilon, System.Single.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(System.Single.Epsilon, 0.0f); - Assert.ApproximatelyEquivalentEpsilon(0.0f, System.Single.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(-System.Single.Epsilon, 0.0f); - Assert.ApproximatelyEquivalentEpsilon(0.0f, -System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, -System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, System.Single.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.0f); + Assert.ApproximatelyEqualEpsilon(0.0f, -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001f, -System.Single.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001f, System.Single.Epsilon); @@ -186,69 +186,69 @@ module MathHelper = // [] let ``ApproximatelyEqual (double precision) is correct for large positive values``() = - Assert.ApproximatelyEquivalentEpsilon(1000000.0, 1000001.0); - Assert.ApproximatelyEquivalentEpsilon(1000001.0, 1000000.0); + Assert.ApproximatelyEqualEpsilon(1000000.0, 1000001.0); + Assert.ApproximatelyEqualEpsilon(1000001.0, 1000000.0); Assert.NotApproximatelyEqualEpsilon(10000.0, 10001.0); Assert.NotApproximatelyEqualEpsilon(10001.0, 10000.0); [] let ``ApproximatelyEqual (double precision) is correct for large negative values``() = - Assert.ApproximatelyEquivalentEpsilon(-1000000.0, -1000001.0); - Assert.ApproximatelyEquivalentEpsilon(-1000001.0, -1000000.0); + Assert.ApproximatelyEqualEpsilon(-1000000.0, -1000001.0); + Assert.ApproximatelyEqualEpsilon(-1000001.0, -1000000.0); Assert.NotApproximatelyEqualEpsilon(-10000.0, -10001.0); Assert.NotApproximatelyEqualEpsilon(-10001.0, -10000.0); [] let ``ApproximatelyEqual (double precision) is correct for positive values around 1``() = - Assert.ApproximatelyEquivalentEpsilon(1.0000001, 1.0000002); - Assert.ApproximatelyEquivalentEpsilon(1.0000002, 1.0000001); + Assert.ApproximatelyEqualEpsilon(1.0000001, 1.0000002); + Assert.ApproximatelyEqualEpsilon(1.0000002, 1.0000001); Assert.NotApproximatelyEqualEpsilon(1.0002, 1.0001); Assert.NotApproximatelyEqualEpsilon(1.0001, 1.0002); [] let ``ApproximatelyEqual (double precision) is correct for negative values around -1``() = - Assert.ApproximatelyEquivalentEpsilon(-1.000001, -1.000002); - Assert.ApproximatelyEquivalentEpsilon(-1.000002, -1.000001); + Assert.ApproximatelyEqualEpsilon(-1.000001, -1.000002); + Assert.ApproximatelyEqualEpsilon(-1.000002, -1.000001); Assert.NotApproximatelyEqualEpsilon(-1.0001, -1.0002); Assert.NotApproximatelyEqualEpsilon(-1.0002, -1.0001); [] let ``ApproximatelyEqual (double precision) is correct for values between 1 and 0``() = - Assert.ApproximatelyEquivalentEpsilon(0.000000001000001, 0.000000001000002); - Assert.ApproximatelyEquivalentEpsilon(0.000000001000002, 0.000000001000001); + Assert.ApproximatelyEqualEpsilon(0.000000001000001, 0.000000001000002); + Assert.ApproximatelyEqualEpsilon(0.000000001000002, 0.000000001000001); Assert.NotApproximatelyEqualEpsilon(0.000000000001002, 0.000000000001001); Assert.NotApproximatelyEqualEpsilon(0.000000000001001, 0.000000000001002); [] let ``ApproximatelyEqual (double precision) is correct for values between -1 and 0``() = - Assert.ApproximatelyEquivalentEpsilon(-0.000000001000001, -0.000000001000002); - Assert.ApproximatelyEquivalentEpsilon(-0.000000001000002, -0.000000001000001); + Assert.ApproximatelyEqualEpsilon(-0.000000001000001, -0.000000001000002); + Assert.ApproximatelyEqualEpsilon(-0.000000001000002, -0.000000001000001); Assert.NotApproximatelyEqualEpsilon(-0.000000000001002, -0.000000000001001); Assert.NotApproximatelyEqualEpsilon(-0.000000000001001, -0.000000000001002); [] let ``ApproximatelyEqual (double precision) is correct for comparisons involving 0``() = - Assert.ApproximatelyEquivalentEpsilon(0.0, 0.0); - Assert.ApproximatelyEquivalentEpsilon(0.0, -0.0); - Assert.ApproximatelyEquivalentEpsilon(-0.0, -0.0); + Assert.ApproximatelyEqualEpsilon(0.0, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, -0.0); + Assert.ApproximatelyEqualEpsilon(-0.0, -0.0); Assert.NotApproximatelyEqualEpsilon(0.00000001, 0.0); Assert.NotApproximatelyEqualEpsilon(0.0, 0.00000001); Assert.NotApproximatelyEqualEpsilon(-0.00000001, 0.0); Assert.NotApproximatelyEqualEpsilon(0.0, -0.00000001); - Assert.ApproximatelyEquivalentEpsilon(0.0, 1e-310, 0.01); - Assert.ApproximatelyEquivalentEpsilon(1e-310, 0.0, 0.01); + Assert.ApproximatelyEqualEpsilon(0.0, 1e-310, 0.01); + Assert.ApproximatelyEqualEpsilon(1e-310, 0.0, 0.01); Assert.NotApproximatelyEqualEpsilon(1e-310, 0.0, 0.000001); Assert.NotApproximatelyEqualEpsilon(0.0, 1e-310, 0.000001); - Assert.ApproximatelyEquivalentEpsilon(0.0, -1e-310, 0.1); - Assert.ApproximatelyEquivalentEpsilon(-1e-310, 0.0, 0.1); + Assert.ApproximatelyEqualEpsilon(0.0, -1e-310, 0.1); + Assert.ApproximatelyEqualEpsilon(-1e-310, 0.0, 0.1); Assert.NotApproximatelyEqualEpsilon(-1e-310, 0.0, 0.00000001); Assert.NotApproximatelyEqualEpsilon(0.0, -1e-310, 0.00000001); [] let ``ApproximatelyEqual (double precision) is correct for extreme values with overflow potential``() = - Assert.ApproximatelyEquivalentEpsilon(System.Double.MaxValue, System.Double.MaxValue); + Assert.ApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue / 2.0); @@ -257,8 +257,8 @@ module MathHelper = [] let ``ApproximatelyEqual (double precision) is correct for values involving infinities``() = - Assert.ApproximatelyEquivalentEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity); - Assert.ApproximatelyEquivalentEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity); + Assert.ApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity); + Assert.ApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity); Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.PositiveInfinity); Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.MaxValue); Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, -System.Double.MaxValue); @@ -289,18 +289,18 @@ module MathHelper = Assert.NotApproximatelyEqualEpsilon(-1.0, 1.000000001); Assert.NotApproximatelyEqualEpsilon(-1.000000001, 1.0); Assert.NotApproximatelyEqualEpsilon(1.0, -1.000000001); - Assert.ApproximatelyEquivalentEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(100000000000.0 * System.Double.Epsilon, 100000000000.0 * -System.Double.Epsilon); [] let ``ApproximatelyEqual (double precision) is correct for values very close to 0``() = - Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, System.Double.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, -System.Double.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(-System.Double.Epsilon, System.Double.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(System.Double.Epsilon, 0.0); - Assert.ApproximatelyEquivalentEpsilon(0.0, System.Double.Epsilon); - Assert.ApproximatelyEquivalentEpsilon(-System.Double.Epsilon, 0.0); - Assert.ApproximatelyEquivalentEpsilon(0.0, -System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, -System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, System.Double.Epsilon); + Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.0); + Assert.ApproximatelyEqualEpsilon(0.0, -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001, -System.Double.Epsilon); Assert.NotApproximatelyEqualEpsilon(0.000000001, System.Double.Epsilon);