From: Jarl Gullberg Date: Wed, 31 May 2017 20:38:54 +0000 (+0200) Subject: Ported more arithmetic tests. X-Git-Tag: v3.0.0~107^2~1^2~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a658d7a1cd843c3f050c6df19d725de36818bc8e;p=platform%2Fcore%2Fcsapi%2Fopentk.git Ported more arithmetic tests. --- diff --git a/tests/OpenTK.Tests/Vector2Tests.fs b/tests/OpenTK.Tests/Vector2Tests.fs index 7b6310b..2c9f01d 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 ab8fcd6..b4ace2f 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)