module Indexing =
//
[<Property>]
- 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
Assert.Equal(n, A.M42)
Assert.Equal(o, A.M43)
Assert.Equal(p, A.M44)
-
+
[<Property>]
- let ``Matrix indexing throws on negative indices`` (a) =
- let mutable A = Matrix4()
+ 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])
+ Assert.Equal(d, A.[0, 3])
- let invalidIndexingAssignmentR = fun() -> A.[-1, 2] <- a
- let invalidIndexingAssignmentC = fun() -> A.[1, -2] <- a
- let invalidIndexingAssignmentRC = fun() -> A.[-1, -2] <- a
+ Assert.Equal(e, A.[1, 0])
+ Assert.Equal(f, A.[1, 1])
+ Assert.Equal(g, A.[1, 2])
+ Assert.Equal(h, A.[1, 3])
- let invalidIndexingAccessR = fun() -> A.[-1, 2] |> ignore
- let invalidIndexingAccessC = fun() -> A.[1, -2] |> ignore
- let invalidIndexingAccessRC = fun() -> A.[-1, -2] |> ignore
+ 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.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentR) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentC) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentRC) |> ignore
-
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessR) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessC) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessRC) |> ignore
-
- [<Property>]
- let ``Matrix indexing throws on large indices`` (a) =
- let mutable A = Matrix4()
+ 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 invalidIndexingAssignmentR = fun() -> A.[5, 2] <- a
- let invalidIndexingAssignmentC = fun() -> A.[1, 6] <- a
- let invalidIndexingAssignmentRC = fun() -> A.[7, 12] <- a
+ [<Property>]
+ let ``Indexed set operator throws exception for negative indices`` (b : Matrix4, x : float32) =
+ let mutable a = b
+ (fun() -> a.[-1, 2] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[1, -2] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[-1, -2] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
- let invalidIndexingAccessR = fun() -> A.[5, 2] |> ignore
- let invalidIndexingAccessC = fun() -> A.[1, 6] |> ignore
- let invalidIndexingAccessRC = fun() -> A.[7, 12] |> ignore
+ [<Property>]
+ let ``Indexed get operator throws exception for negative indices`` (a : Matrix4) =
+ (fun() -> a.[-1, 2] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[1, -2] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[-1, -2] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentR) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentC) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignmentRC) |> ignore
+ [<Property>]
+ let ``Indexed set operator throws exception for large indices`` (a : Matrix4, x : float32) =
+ let mutable b = a
+ (fun() -> b.[5, 2] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> b.[1, 6] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> b.[7, 12] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessR) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessC) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccessRC) |> ignore
+ [<Property>]
+ let ``Indexed get operator throws exception for large indices`` (a : Matrix4) =
+ (fun() -> a.[5, 2] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[1, 6] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+ (fun() -> a.[7, 12] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module ``Row and column properties`` =
let v = Vector2(x,y)
Assert.Equal(x,v.X)
Assert.Equal(y,v.Y)
-
- //[<Property>]
- // 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)
+
+ [<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
+ module Clamping =
+ //
+ [<Property>]
+ 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)
+
+ [<Property>]
+ 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)
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Length =
module Indexing =
//
[<Property>]
- 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])
[<Property>]
- 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)
+
+ (fun() -> v.[-1] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ let ``Indexed get operator throws exception for negative indices`` (x, y) =
+ let mutable v = Vector2(x, y)
+
+ (fun() -> v.[-1] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ let ``Indexed set operator throws exception for large indices`` (x, y) =
let mutable v = Vector2(x, y)
- let invalidIndexingAccess = fun() -> v.[2] |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccess) |> ignore
- let invalidIndexingAssignment = (fun() -> v.[2] <- x)
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignment) |> ignore
-
+ (fun() -> v.[2] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
[<Property>]
- 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 large indices`` (x, y) =
+ let mutable v = Vector2(x, y)
+
+ (fun() -> v.[2] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module ``Simple Properties`` =
//
[<Property>]
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)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
module Negation =
//
[<Property>]
- 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)
module Equality =
//
[<Property>]
- 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
Assert.True(equality)
[<Property>]
- 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
Assert.True(inequality)
[<Property>]
- 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()
module Swizzling =
//
[<Property>]
- 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)
module Interpolation =
//
[<Property>]
- let ``Linear interpolation works`` (a : Vector2, b : Vector2, q) =
+ let ``Linear interpolation is by component`` (a : Vector2, b : Vector2, q) =
let blend = q
Assert.Equal(vExp, vRes)
[<Property>]
- 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)
module ``Vector products`` =
//
[<Property>]
- 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));
Assert.Equal(dot, vRes)
[<Property>]
- 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)
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Normalization =
//
[<Property>]
- 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
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
[<Property>]
- 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
Assert.ApproximatelyEqual(v.Y / l, norm.Y)
[<Property>]
- 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()
Assert.ApproximatelyEqual(v.Y * scale, norm.Y)
[<Property>]
- 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)
[<Property>]
- 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));
[<Property>]
- 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)
[<Property>]
- 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));
module ``Component min and max`` =
//
[<Property>]
- 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)
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 ``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)
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 ``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)
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 ``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)
Assert.True(vMax.Y >= v2.Y)
[<Property>]
- 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)
Assert.True(equalsLast)
[<Property>]
- 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)
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)
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Transformation =
module Indexing =
//
[<Property>]
- 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])
[<Property>]
- 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)
+
+ (fun() -> v.[-1] <- x) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ let ``Indexed get operator throws exception for negative indices`` (x, y, z) =
+ let mutable v = Vector3(x, y, z)
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAccess) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignment) |> ignore
+ (fun() -> v.[-1] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ 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<IndexOutOfRangeException> |> ignore
[<Property>]
- 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<IndexOutOfRangeException>(invalidIndexingAccess) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignment) |> ignore
+ (fun() -> v.[4] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Length =
//
[<Property>]
- 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)
[<Property>]
- 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)
[<Property>]
- 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
module Normalization =
//
[<Property>]
- 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
Assert.ApproximatelyEqual(v.Z / l, norm.Z)
[<Property>]
- 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)
[<Property>]
- 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()
Assert.ApproximatelyEqual(v.Z * scale, norm.Z)
[<Property>]
- 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)
[<Property>]
- 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));
[<Property>]
- 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)
[<Property>]
- 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));
Assert.Equal(a.Z * f,r.Z)
[<Property>]
- 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
Assert.Equal(exp, res)
[<Property>]
- 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
Assert.ApproximatelyEqual(a.Z / f,r.Z)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
module Negation =
//
[<Property>]
- 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)
module Equality =
//
[<Property>]
- 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
Assert.True(equality)
[<Property>]
- 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
Assert.True(inequality)
[<Property>]
- 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()
module Swizzling =
//
[<Property>]
- 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)
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);
+ [<Property>]
+ 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);
+ [<Property>]
+ 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);
module Interpolation =
//
[<Property>]
- let ``Linear interpolation works`` (a : Vector3, b : Vector3, q) =
+ let ``Linear interpolation is by component`` (a : Vector3, b : Vector3, q) =
let blend = q
Assert.Equal(vExp, vRes)
[<Property>]
- 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)
module ``Vector products`` =
//
[<Property>]
- 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));
Assert.Equal(dot, vRes)
[<Property>]
- 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
module ``Component min and max`` =
//
[<Property>]
- 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)
Assert.True(vMin.Z <= v2.Z)
[<Property>]
- 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)
Assert.True(vMax.Z >= v2.Z)
[<Property>]
- 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)
Assert.True(vMin.Z <= v2.Z)
[<Property>]
- 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)
Assert.True(vMax.Z >= v2.Z)
[<Property>]
- 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)
Assert.True(equalsLast)
[<Property>]
- 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)
module Clamping =
//
[<Property>]
- 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
Assert.Equal(expZ, res.Z)
[<Property>]
- 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
Assert.Equal((float32)0, v2.W)
[<Property>]
+ 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)
+
+ [<Property>]
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(w, v.[3])
[<Property>]
- 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<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ let ``Indexed get 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<IndexOutOfRangeException>(invalidIndexingAccess) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignment) |> ignore
+ (fun() -> v.[-1] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
+
+ [<Property>]
+ 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<IndexOutOfRangeException> |> ignore
[<Property>]
- 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<IndexOutOfRangeException>(invalidIndexingAccess) |> ignore
- Assert.Throws<IndexOutOfRangeException>(invalidIndexingAssignment) |> ignore
+ (fun() -> v.[4] |> ignore) |> Assert.Throws<IndexOutOfRangeException> |> ignore
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Length =
//
[<Property>]
- 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)
[<Property>]
- 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)
[<Property>]
- 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
module Normalization =
//
[<Property>]
- 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)
[<Property>]
- 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)
[<Property>]
- 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()
Assert.ApproximatelyEqual(v.Z * scale, norm.Z)
Assert.ApproximatelyEqual(v.W * scale, norm.W)
- [<Property>] // 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)
+ [<Property>]
+ let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) =
+ let norm = a / a.Length
+ let vRes = Vector4.Normalize(ref a)
- [<Property>] // 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)
[<Property>]
- 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));
+
+ [<Property>]
+ 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)
[<Property>]
- 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));
Assert.Equal(a.W * f,r.W)
[<Property>]
- 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
Assert.Equal(exp, res)
[<Property>]
- 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
Assert.ApproximatelyEqual(a.W / f, r.W)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
Assert.ApproximatelyEqual(v1, sum)
[<Property>]
- 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)
module Negation =
//
[<Property>]
- 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)
module Equality =
//
[<Property>]
- 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
Assert.True(equality)
[<Property>]
- 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
Assert.True(inequality)
[<Property>]
- 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()
Assert.True(equality)
Assert.False(inequalityByOtherType)
+ [<Property>]
+ 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)
+
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
module Swizzling =
//
[<Property>]
- 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)
Assert.Equal(xw, v.Xw)
[<Property>]
- 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)
Assert.Equal(yw, v.Yw)
[<Property>]
- 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)
Assert.Equal(zw, v.Zw)
[<Property>]
- 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)
module Interpolation =
//
[<Property>]
- let ``Linear interpolation works`` (a : Vector4, b : Vector4, q) =
+ let ``Linear interpolation is by component`` (a : Vector4, b : Vector4, q) =
let blend = q
Assert.Equal(vExp, vRes)
[<Property>]
- 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)
module ``Vector products`` =
//
[<Property>]
- 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));
module ``Component min and max`` =
//
[<Property>]
- 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)
Assert.True(v2ShorterThanv1)
[<Property>]
- 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)
module Clamping =
//
[<Property>]
- 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
Assert.Equal(expW, res.W)
[<Property>]
- 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