Ported more arithmetic tests.
This commit is contained in:
parent
476d55b5dd
commit
a658d7a1cd
2 changed files with 213 additions and 11 deletions
|
@ -65,14 +65,14 @@ module Vector2 =
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v = Vector2(a, b)
|
||||||
let perp = Vector2(a, -b)
|
let perp = Vector2(b, -a)
|
||||||
|
|
||||||
Assert.Equal(perp, v.PerpendicularRight)
|
Assert.Equal(perp, v.PerpendicularRight)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v = Vector2(a, b)
|
||||||
let perp = Vector2(-a, b)
|
let perp = Vector2(-b, a)
|
||||||
|
|
||||||
Assert.Equal(perp, v.PerpendicularLeft)
|
Assert.Equal(perp, v.PerpendicularLeft)
|
||||||
|
|
||||||
|
@ -136,6 +136,22 @@ module Vector2 =
|
||||||
let r1 = (a + b) + c
|
let r1 = (a + b) + c
|
||||||
let r2 = a + (b + c)
|
let r2 = a + (b + c)
|
||||||
Assert.ApproximatelyEqual(r1,r2)
|
Assert.ApproximatelyEqual(r1,r2)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
module Multiplication =
|
module Multiplication =
|
||||||
|
@ -153,15 +169,40 @@ module Vector2 =
|
||||||
Assert.Equal(r1,r2)
|
Assert.Equal(r1,r2)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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
|
let r = a * f
|
||||||
|
|
||||||
Assert.Equal(a.X * f,r.X)
|
Assert.Equal(a.X * f,r.X)
|
||||||
Assert.Equal(a.Y * f,r.Y)
|
Assert.Equal(a.Y * f,r.Y)
|
||||||
|
|
||||||
// Inverse direction
|
[<Property>]
|
||||||
|
let ``Right-handed Vector2-scalar multiplication is the same as component-scalar multiplication`` (a : Vector2, f : float32) =
|
||||||
let r = f * a
|
let r = f * a
|
||||||
Assert.Equal(a.X * f,r.X)
|
Assert.Equal(a.X * f,r.X)
|
||||||
Assert.Equal(a.Y * f,r.Y)
|
Assert.Equal(a.Y * f,r.Y)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
module Subtraction =
|
module Subtraction =
|
||||||
|
@ -171,6 +212,22 @@ module Vector2 =
|
||||||
let c = a - b
|
let c = a - b
|
||||||
Assert.Equal(a.X - b.X,c.X)
|
Assert.Equal(a.X - b.X,c.X)
|
||||||
Assert.Equal(a.Y - b.Y,c.Y)
|
Assert.Equal(a.Y - b.Y,c.Y)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
module Division =
|
module Division =
|
||||||
|
@ -179,8 +236,41 @@ module Vector2 =
|
||||||
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) =
|
||||||
if not (approxEq f 0.0f) then // we don't support diving by zero.
|
if not (approxEq f 0.0f) then // we don't support diving by zero.
|
||||||
let r = a / f
|
let r = a / f
|
||||||
|
|
||||||
Assert.ApproximatelyEqual(a.X / f,r.X)
|
Assert.ApproximatelyEqual(a.X / f,r.X)
|
||||||
Assert.ApproximatelyEqual(a.Y / f,r.Y)
|
Assert.ApproximatelyEqual(a.Y / f,r.Y)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
module Negation =
|
module Negation =
|
||||||
|
@ -352,4 +442,116 @@ module Vector2 =
|
||||||
|
|
||||||
let norm = Vector2(a.X * scale, a.Y * scale)
|
let norm = Vector2(a.X * scale, a.Y * scale)
|
||||||
|
|
||||||
Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a));
|
Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a));
|
||||||
|
|
||||||
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
|
module ``Component min and max`` =
|
||||||
|
//
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||||
|
module Clamping =
|
||||||
|
//
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
||||||
|
[<Property>]
|
||||||
|
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)
|
||||||
|
|
|
@ -221,7 +221,7 @@ module Vector3 =
|
||||||
Assert.ApproximatelyEqual(r1, r2)
|
Assert.ApproximatelyEqual(r1, r2)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z)
|
||||||
let sum = Vector3.Add(a, b)
|
let sum = Vector3.Add(a, b)
|
||||||
|
@ -229,7 +229,7 @@ module Vector3 =
|
||||||
Assert.ApproximatelyEqual(v1, sum)
|
Assert.ApproximatelyEqual(v1, sum)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z)
|
||||||
let sum = Vector3.Add(ref a, ref b)
|
let sum = Vector3.Add(ref a, ref b)
|
||||||
|
@ -248,7 +248,7 @@ module Vector3 =
|
||||||
Assert.Equal(a.Z - b.Z,c.Z)
|
Assert.Equal(a.Z - b.Z,c.Z)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z)
|
||||||
let sum = Vector3.Subtract(a, b)
|
let sum = Vector3.Subtract(a, b)
|
||||||
|
@ -256,7 +256,7 @@ module Vector3 =
|
||||||
Assert.ApproximatelyEqual(v1, sum)
|
Assert.ApproximatelyEqual(v1, sum)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z)
|
||||||
let sum = Vector3.Subtract(ref a, ref b)
|
let sum = Vector3.Subtract(ref a, ref b)
|
||||||
|
@ -329,7 +329,7 @@ module Vector3 =
|
||||||
Assert.Equal(exp, res)
|
Assert.Equal(exp, res)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z)
|
||||||
let sum = Vector3.Multiply(a, b)
|
let sum = Vector3.Multiply(a, b)
|
||||||
|
@ -337,7 +337,7 @@ module Vector3 =
|
||||||
Assert.ApproximatelyEqual(v1, sum)
|
Assert.ApproximatelyEqual(v1, sum)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
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 v1 = Vector3(a.X * b.X, a.Y * b.Y, a.Z * b.Z)
|
||||||
let sum = Vector3.Multiply(ref a, ref b)
|
let sum = Vector3.Multiply(ref a, ref b)
|
||||||
|
|
Loading…
Reference in a new issue