From c3fa66eb15da1f58145315ac7e21d8a5ff467d58 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 2 Jun 2017 20:33:00 +0200 Subject: [PATCH] Implemented all ComponentMin/Max and MagnitudeMin/Max tests. --- tests/OpenTK.Tests/Vector2Tests.fs | 127 ++++++++++++++++---------------- tests/OpenTK.Tests/Vector3Tests.fs | 143 ++++++++++++++++++------------------- tests/OpenTK.Tests/Vector4Tests.fs | 86 +++++++++++++++++++--- 3 files changed, 212 insertions(+), 144 deletions(-) diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index fccdbc6..fd9fb6e 100644 --- a/tests/OpenTK.Tests/Vector2Tests.fs +++ b/tests/OpenTK.Tests/Vector2Tests.fs @@ -463,93 +463,98 @@ module Vector2 = Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a)); [ |])>] - module ``Component min and max`` = + module ``Magnitude 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 vMin = Vector2.ComponentMin(v1, v2) + 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 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) + let vMin = Vector2.MagnitudeMin(v1, v2) - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] - 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) + 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 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) + let vMin = Vector2.MagnitudeMax(v1, v2) - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) [] - 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) + 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 - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) + let vMin = Vector2.MagnitudeMin(ref v1, ref v2) - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] - 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) + 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 - Assert.True(vMax.X >= v1.X) - Assert.True(vMax.X >= v2.X) + let vMin = Vector2.MagnitudeMax(ref v1, ref v2) - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + 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 ``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 ``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 - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) - let vMin = Vector2.Min(v1, v2) + [] + 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 - 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) [] - 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 ``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 - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + Assert.True(isComponentSmallest vMin.X v1.X v2.X) + Assert.True(isComponentSmallest vMin.Y v1.Y v2.Y) - let vMin = Vector2.Max(v1, v2) + [] + 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 - 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 851358c..36713dd 100644 --- a/tests/OpenTK.Tests/Vector3Tests.fs +++ b/tests/OpenTK.Tests/Vector3Tests.fs @@ -528,105 +528,102 @@ module Vector3 = Assert.Equal(cross, vRes) [ |])>] - module ``Component min and max`` = + module ``Magnitude 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 vMin = Vector3.ComponentMin(v1, v2) - - Assert.True(vMin.X <= v1.X) - Assert.True(vMin.X <= v2.X) + 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 - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + let vMin = Vector3.MagnitudeMin(v1, v2) - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] - 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) + 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 - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + let vMin = Vector3.MagnitudeMax(v1, v2) - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) + if vMin = v1 then + let v1LongerThanOrEqualTov2 = l1 >= l2 + Assert.True(v1LongerThanOrEqualTov2) + else + let v2LongerThanv1 = l2 > l1 + Assert.True(v2LongerThanv1) [] - 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) + 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 - Assert.True(vMin.Y <= v1.Y) - Assert.True(vMin.Y <= v2.Y) + let vMin = Vector3.MagnitudeMin(ref v1, ref v2) - Assert.True(vMin.Z <= v1.Z) - Assert.True(vMin.Z <= v2.Z) + if vMin = v1 then + let v1ShorterThanv2 = l1 < l2 + Assert.True(v1ShorterThanv2) + else + let v2ShorterThanOrEqualTov1 = l2 <= l1 + Assert.True(v2ShorterThanOrEqualTov1) [] - 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) + 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 - Assert.True(vMax.Y >= v1.Y) - Assert.True(vMax.Y >= v2.Y) + let vMin = Vector3.MagnitudeMax(ref v1, ref v2) - Assert.True(vMax.Z >= v1.Z) - Assert.True(vMax.Z >= v2.Z) + 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 ``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 ``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 - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + 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 vMin = Vector3.Min(v1, v2) + [] + 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 - 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) [] - 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 ``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 - let l1 = v1.LengthSquared - let l2 = v2.LengthSquared + 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 vMin = Vector3.Max(v1, v2) + [] + 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 - 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 0cf78ad..90babe0 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,39 @@ 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.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 : Vector4, v2: Vector4) = let l1 = v1.LengthSquared let l2 = v2.LengthSquared - let vMin = Vector4.Max(v1, 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) + + [] + 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 @@ -729,6 +751,50 @@ module Vector4 = 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 = // [] -- 2.7.4