From 72b00b4460bee5ff8bc00df53a63778bf62a23c9 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Wed, 31 May 2017 22:09:04 +0200 Subject: [PATCH] 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