Added new and improved floating-point equality tester.
This commit is contained in:
parent
4ae58b3073
commit
6d0f3eb973
6 changed files with 625 additions and 295 deletions
|
@ -9,9 +9,19 @@ open OpenTK
|
|||
[<AutoOpen>]
|
||||
module private AssertHelpers =
|
||||
[<Literal>]
|
||||
let private BitAccuracy = 13
|
||||
let private BitAccuracy = 16
|
||||
|
||||
let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy)
|
||||
//let approxEq a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy)
|
||||
let approxEq a b = MathHelper.ApproximatelyEqualEpsilon(a,b,0.0001f)
|
||||
let approxEqSingleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001f)
|
||||
let approxEqDoubleEpsilon a b = MathHelper.ApproximatelyEqualEpsilon(a, b, 0.00001)
|
||||
|
||||
let approxEqSingleEpsilonWithError (a, b, c : float32) = MathHelper.ApproximatelyEqualEpsilon(a, b, c)
|
||||
let approxEqDoubleEpsilonWithError (a, b, c : float) = MathHelper.ApproximatelyEqualEpsilon(a, b, c)
|
||||
|
||||
let anyZero2 (a : Vector2) = (approxEq a.X 0.0f || approxEq a.Y 0.0f)
|
||||
let anyZero3 (a : Vector3) = (approxEq a.X 0.0f || approxEq a.Y 0.0f || approxEq a.Z 0.0f)
|
||||
let anyZero4 (a : Vector4) = (approxEq a.X 0.0f || approxEq a.Y 0.0f || approxEq a.Z 0.0f || approxEq a.W 0.0f)
|
||||
|
||||
/// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal.
|
||||
[<Sealed>]
|
||||
|
@ -31,4 +41,31 @@ type internal Assert =
|
|||
if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
|
||||
static member ApproximatelyEqualEpsilon(a : float32, b : float32) =
|
||||
if not <| approxEqSingleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
static member ApproximatelyEqualEpsilon(a : float32, b : float32, c : float32) =
|
||||
if not <| approxEqSingleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
|
||||
static member ApproximatelyEqualEpsilon(a : float, b : float) =
|
||||
if not <| approxEqDoubleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
static member ApproximatelyEqualEpsilon(a : float, b : float, c : float) =
|
||||
if not <| approxEqDoubleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
|
||||
static member NotApproximatelyEqualEpsilon(a : float32, b : float32) =
|
||||
if approxEqSingleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
static member NotApproximatelyEqualEpsilon(a : float32, b : float32, c : float32) =
|
||||
if approxEqSingleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
|
||||
static member NotApproximatelyEqualEpsilon(a : float, b : float) =
|
||||
if approxEqDoubleEpsilon a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
static member NotApproximatelyEqualEpsilon(a : float, b : float, c : float) =
|
||||
if approxEqDoubleEpsilonWithError(a, b, c) then raise <| new Xunit.Sdk.EqualException(a,b)
|
||||
|
||||
static member ThrowsIndexExn(f:unit -> unit) = Assert.Throws<IndexOutOfRangeException>(f) |> ignore
|
||||
|
|
|
@ -6,8 +6,9 @@ open FsCheck.Xunit
|
|||
open System
|
||||
open OpenTK
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
module MathHelper =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``ApproximatelyEqual (delta)`` =
|
||||
/// This test ensures that approximately equal can never get it 'wrong' about the values.
|
||||
[<Property>]
|
||||
let ``ApproximatelyEqual is never incorrect`` (a : float32,b : float32,bits : int32) =
|
||||
|
@ -53,3 +54,255 @@ module MathHelper =
|
|||
let b = 0.0f
|
||||
Assert.Equal(a,b)
|
||||
Assert.True(MathHelper.ApproximatelyEqual(a,b,0))
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``ApproximatelyEqual (single-precision epsilon)`` =
|
||||
//
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for large positive values``() =
|
||||
Assert.ApproximatelyEqualEpsilon(1000000.0f, 1000001.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(1000001.0f, 1000000.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(10000.0f, 10001.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(10001.0f, 10000.0f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for large negative values``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-1000000.0f, -1000001.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(-1000001.0f, -1000000.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-10000.0f, -10001.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-10001.0f, -10000.0f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for positive values around 1``() =
|
||||
Assert.ApproximatelyEqualEpsilon(1.0000001f, 1.0000002f);
|
||||
Assert.ApproximatelyEqualEpsilon(1.0000002f, 1.0000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0002f, 1.0001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0001f, 1.0002f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for negative values around -1``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-1.000001f, -1.000002f);
|
||||
Assert.ApproximatelyEqualEpsilon(-1.000002f, -1.000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0001f, -1.0002f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0002f, -1.0001f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values between 1 and 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(0.000000001000001f, 0.000000001000002f);
|
||||
Assert.ApproximatelyEqualEpsilon(0.000000001000002f, 0.000000001000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000000001002f, 0.000000000001001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000000001001f, 0.000000000001002f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values between -1 and 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-0.000000001000001f, -0.000000001000002f);
|
||||
Assert.ApproximatelyEqualEpsilon(-0.000000001000002f, -0.000000001000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.000000000001002f, -0.000000000001001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.000000000001001f, -0.000000000001002f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for comparisons involving 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, 0.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, -0.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(-0.0f, -0.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.00000001f, 0.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0f, 0.00000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.00000001f, 0.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0f, -0.00000001f);
|
||||
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.01f);
|
||||
Assert.ApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.01f);
|
||||
Assert.NotApproximatelyEqualEpsilon(1e-40f, 0.0f, 0.000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0f, 1e-40f, 0.000001f);
|
||||
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.1f);
|
||||
Assert.ApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.1f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1e-40f, 0.0f, 0.00000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0f, -1e-40f, 0.00000001f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for extreme values with overflow potential``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.MaxValue / 2.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, -System.Single.MaxValue / 2.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.MaxValue / 2.0f);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values involving infinities``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.PositiveInfinity);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NegativeInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.PositiveInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, -System.Single.MaxValue);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values involving NaN``() =
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, 0.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.0f, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -0.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0f, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.PositiveInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.PositiveInfinity, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.NegativeInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NegativeInfinity, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.MaxValue, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -System.Single.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Single.MaxValue, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, System.Single.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.NaN, -System.Single.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.NaN);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values on opposite sides of 0``() =
|
||||
Assert.NotApproximatelyEqualEpsilon(1.000000001f, -1.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0f, 1.000000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.000000001f, 1.0f);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0f, -1.000000001f);
|
||||
Assert.ApproximatelyEqualEpsilon(10.0f * System.Single.Epsilon, 10.0f * -System.Single.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(10000.0f * System.Single.Epsilon, 10000.0f * -System.Single.Epsilon);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (single precision) is correct for values very close to 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, System.Single.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, -System.Single.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, System.Single.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Single.Epsilon, 0.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, System.Single.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.0f);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0f, -System.Single.Epsilon);
|
||||
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000001f, -System.Single.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000001f, System.Single.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Single.Epsilon, 0.000000001f);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Single.Epsilon, 0.000000001f);
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``ApproximatelyEqual (double-precision epsilon)`` =
|
||||
//
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for large positive values``() =
|
||||
Assert.ApproximatelyEqualEpsilon(1000000.0, 1000001.0);
|
||||
Assert.ApproximatelyEqualEpsilon(1000001.0, 1000000.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(10000.0, 10001.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(10001.0, 10000.0);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for large negative values``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-1000000.0, -1000001.0);
|
||||
Assert.ApproximatelyEqualEpsilon(-1000001.0, -1000000.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(-10000.0, -10001.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(-10001.0, -10000.0);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for positive values around 1``() =
|
||||
Assert.ApproximatelyEqualEpsilon(1.0000001, 1.0000002);
|
||||
Assert.ApproximatelyEqualEpsilon(1.0000002, 1.0000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0002, 1.0001);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0001, 1.0002);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for negative values around -1``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-1.000001, -1.000002);
|
||||
Assert.ApproximatelyEqualEpsilon(-1.000002, -1.000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0001, -1.0002);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0002, -1.0001);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values between 1 and 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(0.000000001000001, 0.000000001000002);
|
||||
Assert.ApproximatelyEqualEpsilon(0.000000001000002, 0.000000001000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000000001002, 0.000000000001001);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000000001001, 0.000000000001002);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values between -1 and 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(-0.000000001000001, -0.000000001000002);
|
||||
Assert.ApproximatelyEqualEpsilon(-0.000000001000002, -0.000000001000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.000000000001002, -0.000000000001001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.000000000001001, -0.000000000001002);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for comparisons involving 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, 0.0);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, -0.0);
|
||||
Assert.ApproximatelyEqualEpsilon(-0.0, -0.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.00000001, 0.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0, 0.00000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.00000001, 0.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0, -0.00000001);
|
||||
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, 1e-310, 0.01);
|
||||
Assert.ApproximatelyEqualEpsilon(1e-310, 0.0, 0.01);
|
||||
Assert.NotApproximatelyEqualEpsilon(1e-310, 0.0, 0.000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0, 1e-310, 0.000001);
|
||||
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, -1e-310, 0.1);
|
||||
Assert.ApproximatelyEqualEpsilon(-1e-310, 0.0, 0.1);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1e-310, 0.0, 0.00000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0, -1e-310, 0.00000001);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for extreme values with overflow potential``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.MaxValue / 2.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, -System.Double.MaxValue / 2.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.MaxValue / 2.0);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values involving infinities``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.PositiveInfinity);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NegativeInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.PositiveInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, -System.Double.MaxValue);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values involving NaN``() =
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, 0.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(-0.0, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -0.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.0, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.PositiveInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.PositiveInfinity, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.NegativeInfinity);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NegativeInfinity, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.MaxValue, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -System.Double.MaxValue);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Double.MaxValue, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, System.Double.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.NaN);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.NaN, -System.Double.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.NaN);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values on opposite sides of 0``() =
|
||||
Assert.NotApproximatelyEqualEpsilon(1.000000001, -1.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.0, 1.000000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-1.000000001, 1.0);
|
||||
Assert.NotApproximatelyEqualEpsilon(1.0, -1.000000001);
|
||||
Assert.ApproximatelyEqualEpsilon(10.0 * System.Double.Epsilon, 10.0 * -System.Double.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(100000000000.0 * System.Double.Epsilon, 100000000000.0 * -System.Double.Epsilon);
|
||||
|
||||
[<Fact>]
|
||||
let ``ApproximatelyEqual (double precision) is correct for values very close to 0``() =
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, System.Double.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, -System.Double.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, System.Double.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(System.Double.Epsilon, 0.0);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, System.Double.Epsilon);
|
||||
Assert.ApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.0);
|
||||
Assert.ApproximatelyEqualEpsilon(0.0, -System.Double.Epsilon);
|
||||
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000001, -System.Double.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(0.000000001, System.Double.Epsilon);
|
||||
Assert.NotApproximatelyEqualEpsilon(System.Double.Epsilon, 0.000000001);
|
||||
Assert.NotApproximatelyEqualEpsilon(-System.Double.Epsilon, 0.000000001);
|
|
@ -7,7 +7,7 @@ open System
|
|||
open OpenTK
|
||||
|
||||
module Matrix4 =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Constructors =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -88,7 +88,7 @@ module Matrix4 =
|
|||
Assert.Equal(o, A.M43)
|
||||
Assert.Equal(p, A.M44)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Equality =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -103,7 +103,7 @@ module Matrix4 =
|
|||
let ``A matrix is not equal to an object which is not a matrix`` (a : Matrix4, b : Vector3) =
|
||||
Assert.False(a.Equals(b))
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Multiplication =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -202,7 +202,7 @@ module Matrix4 =
|
|||
Assert.Equal(R4, AScaled.Row3)
|
||||
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Addition =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -232,7 +232,7 @@ module Matrix4 =
|
|||
Assert.Equal(o + o, sum.M43)
|
||||
Assert.Equal(p + p, sum.M44)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Subtraction =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -262,7 +262,7 @@ module Matrix4 =
|
|||
Assert.Equal(o - o, sub.M43)
|
||||
Assert.Equal(p - p, sub.M44)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Indexing =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -363,7 +363,7 @@ module Matrix4 =
|
|||
(fun() -> a.[1, 6] |> ignore) |> Assert.ThrowsIndexExn
|
||||
(fun() -> a.[7, 12] |> ignore) |> Assert.ThrowsIndexExn
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Row and column properties`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
|
|
@ -8,7 +8,7 @@ open System.Runtime.InteropServices
|
|||
open OpenTK
|
||||
|
||||
module Vector2 =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Constructors =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -23,7 +23,7 @@ module Vector2 =
|
|||
Assert.Equal(x,v.X)
|
||||
Assert.Equal(y,v.Y)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Clamping =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -46,7 +46,7 @@ module Vector2 =
|
|||
Assert.Equal(expX, res.X)
|
||||
Assert.Equal(expY, res.Y)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Length =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -75,7 +75,7 @@ module Vector2 =
|
|||
|
||||
Assert.Equal(lsq, v.LengthSquared)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Unit vectors and perpendicularity`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -92,7 +92,7 @@ module Vector2 =
|
|||
|
||||
Assert.Equal(perp, v.PerpendicularLeft)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Indexing =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -126,7 +126,7 @@ module Vector2 =
|
|||
|
||||
(fun() -> v.[2] |> ignore) |> Assert.ThrowsIndexExn
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Simple Properties`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -139,7 +139,7 @@ module Vector2 =
|
|||
//
|
||||
Assert.True(a.Length >= 0.0f)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Addition =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -176,7 +176,7 @@ module Vector2 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Multiplication =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -227,7 +227,7 @@ module Vector2 =
|
|||
Assert.Equal(a.X * f,r.X)
|
||||
Assert.Equal(a.Y * f,r.Y)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Subtraction =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -252,11 +252,12 @@ module Vector2 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Division =
|
||||
//
|
||||
[<Property>]
|
||||
let ``Vector2-float division is the same as component-float division`` (a : Vector2, f : float32) =
|
||||
if not (approxEq f 0.0f) then
|
||||
let r = a / f
|
||||
|
||||
Assert.ApproximatelyEqual(a.X / f,r.X)
|
||||
|
@ -264,7 +265,7 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector2-Vector2 division method is the same as component division`` (a : Vector2, b : Vector2) =
|
||||
|
||||
if not (anyZero2 a || anyZero2 b) then
|
||||
let v1 = Vector2(a.X / b.X, a.Y / b.Y)
|
||||
let sum = Vector2.Divide(a, b)
|
||||
|
||||
|
@ -272,7 +273,7 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector2-Vector2 divison method by reference `` (a : Vector2, b : Vector2) =
|
||||
|
||||
if not (anyZero2 a || anyZero2 b) then
|
||||
let v1 = Vector2(a.X / b.X, a.Y / b.Y)
|
||||
let sum = Vector2.Divide(ref a, ref b)
|
||||
|
||||
|
@ -280,7 +281,7 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector2-scalar division method is the same as component division`` (a : Vector2, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then
|
||||
let v1 = Vector2(a.X / b, a.Y / b)
|
||||
let sum = Vector2.Divide(a, b)
|
||||
|
||||
|
@ -288,13 +289,13 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector2-scalar divison method by reference is the same as component division`` (a : Vector2, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then
|
||||
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> |], MaxTest = 10000)>]
|
||||
module Negation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -304,7 +305,7 @@ module Vector2 =
|
|||
Assert.Equal(-x, vNeg.X)
|
||||
Assert.Equal(-y, vNeg.Y)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Equality =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -335,7 +336,7 @@ module Vector2 =
|
|||
Assert.True(equality)
|
||||
Assert.False(inequalityByOtherType)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Swizzling =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -346,7 +347,7 @@ module Vector2 =
|
|||
let v1yx = v1.Yx;
|
||||
Assert.Equal(v2, v1yx);
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Interpolation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -373,7 +374,7 @@ module Vector2 =
|
|||
let vRes = Vector2.BaryCentric(ref a, ref b, ref c, u, v)
|
||||
Assert.Equal(r, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Vector products`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -394,7 +395,7 @@ module Vector2 =
|
|||
let vRes = Vector2.PerpDot(ref a, ref b)
|
||||
Assert.Equal(perpDot, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Normalization =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -434,6 +435,8 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization by reference is the same as division by magnitude`` (a : Vector2) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
let vRes = Vector2.Normalize(ref a)
|
||||
|
||||
|
@ -441,6 +444,8 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization is the same as division by magnitude`` (a : Vector2) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
|
||||
Assert.ApproximatelyEqual(norm, Vector2.Normalize(a));
|
||||
|
@ -462,11 +467,13 @@ module Vector2 =
|
|||
|
||||
Assert.ApproximatelyEqual(norm, Vector2.NormalizeFast(a));
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Magnitude min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -481,6 +488,8 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -495,6 +504,8 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector2, v2: Vector2) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -509,6 +520,8 @@ module Vector2 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax by reference selects the vector with equal greater magnitude given two vectors`` (v1 : Vector2, v2: Vector2) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -521,7 +534,7 @@ module Vector2 =
|
|||
let v2LongerThanv1 = l2 > l1
|
||||
Assert.True(v2LongerThanv1)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Component min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -556,7 +569,7 @@ module Vector2 =
|
|||
Assert.True(isComponentLargest vMax.X v1.X v2.X)
|
||||
Assert.True(isComponentLargest vMax.Y v1.Y v2.Y)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Transformation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -579,7 +592,7 @@ module Vector2 =
|
|||
|
||||
Assert.ApproximatelyEqual(transformedVector, Vector2.Transform(ref v, ref q))
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Serialization =
|
||||
//
|
||||
[<Property>]
|
||||
|
|
|
@ -8,7 +8,7 @@ open System.Runtime.InteropServices
|
|||
open OpenTK
|
||||
|
||||
module Vector3 =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Constructors =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -65,7 +65,7 @@ module Vector3 =
|
|||
Assert.Equal(b, v2.Y)
|
||||
Assert.Equal(c, v2.Z)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Indexing =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -100,7 +100,7 @@ module Vector3 =
|
|||
|
||||
(fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Length =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -124,7 +124,7 @@ module Vector3 =
|
|||
|
||||
Assert.Equal(lsq, v.LengthSquared)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Normalization =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -167,6 +167,8 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization by reference is the same as division by magnitude`` (a : Vector3) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
let vRes = Vector3.Normalize(ref a)
|
||||
|
||||
|
@ -174,6 +176,8 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization is the same as division by magnitude`` (a : Vector3) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
|
||||
Assert.ApproximatelyEqual(norm, Vector3.Normalize(a));
|
||||
|
@ -195,7 +199,7 @@ module Vector3 =
|
|||
|
||||
Assert.ApproximatelyEqual(norm, Vector3.NormalizeFast(a));
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Addition =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -236,7 +240,7 @@ module Vector3 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Subtraction =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -263,7 +267,7 @@ module Vector3 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Multiplication =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -344,7 +348,7 @@ module Vector3 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Division =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -358,7 +362,7 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector3-Vector3 division method is the same as component division`` (a : Vector3, b : Vector3) =
|
||||
|
||||
if not (anyZero3 a || anyZero3 b) then
|
||||
let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z)
|
||||
let sum = Vector3.Divide(a, b)
|
||||
|
||||
|
@ -366,7 +370,7 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector3-Vector3 divison method by reference is the same as component division`` (a : Vector3, b : Vector3) =
|
||||
|
||||
if not (anyZero3 a || anyZero3 b) then
|
||||
let v1 = Vector3(a.X / b.X, a.Y / b.Y, a.Z / b.Z)
|
||||
let sum = Vector3.Divide(ref a, ref b)
|
||||
|
||||
|
@ -374,7 +378,7 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector3-scalar division method is the same as component division`` (a : Vector3, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then // we don't support diving by zero.
|
||||
let v1 = Vector3(a.X / b, a.Y / b, a.Z / b)
|
||||
let sum = Vector3.Divide(a, b)
|
||||
|
||||
|
@ -382,13 +386,13 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector3-scalar divison method by reference is the same as component division`` (a : Vector3, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then // we don't support diving by zero.
|
||||
let v1 = Vector3(a.X / b, a.Y / b, a.Z / b)
|
||||
let sum = Vector3.Divide(ref a, b)
|
||||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Negation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -399,7 +403,7 @@ module Vector3 =
|
|||
Assert.Equal(-y, vNeg.Y)
|
||||
Assert.Equal(-z, vNeg.Z)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Equality =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -430,7 +434,7 @@ module Vector3 =
|
|||
Assert.True(equality)
|
||||
Assert.False(inequalityByOtherType)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Swizzling =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -475,7 +479,7 @@ module Vector3 =
|
|||
Assert.Equal(zx, v.Zx);
|
||||
Assert.Equal(zy, v.Zy);
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Interpolation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -503,7 +507,7 @@ module Vector3 =
|
|||
let vRes = Vector3.BaryCentric(ref a, ref b, ref c, u, v)
|
||||
Assert.Equal(r, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Vector products`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -527,11 +531,13 @@ module Vector3 =
|
|||
let vRes = Vector3.Cross(ref a, ref b)
|
||||
Assert.Equal(cross, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Magnitude min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -546,6 +552,8 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -560,6 +568,8 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector3, v2: Vector3) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -574,6 +584,8 @@ module Vector3 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector3, v2: Vector3) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -586,7 +598,7 @@ module Vector3 =
|
|||
let v2LongerThanv1 = l2 > l1
|
||||
Assert.True(v2LongerThanv1)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Component min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -625,7 +637,7 @@ module Vector3 =
|
|||
Assert.True(isComponentLargest vMax.Y v1.Y v2.Y)
|
||||
Assert.True(isComponentLargest vMax.Z v1.Z v2.Z)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Clamping =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -652,7 +664,7 @@ module Vector3 =
|
|||
Assert.Equal(expY, res.Y)
|
||||
Assert.Equal(expZ, res.Z)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Unit vectors``=
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -685,7 +697,7 @@ module Vector3 =
|
|||
|
||||
Assert.Equal(Vector3.One, unitOne)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Serialization =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -695,7 +707,7 @@ module Vector3 =
|
|||
Assert.Equal(expectedSize, Vector3.SizeInBytes)
|
||||
Assert.Equal(expectedSize, Marshal.SizeOf(Vector3()))
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Transformation =
|
||||
//
|
||||
[<Property>]
|
||||
|
|
|
@ -8,7 +8,7 @@ open System.Runtime.InteropServices
|
|||
open OpenTK
|
||||
|
||||
module Vector4 =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Constructors =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -85,7 +85,7 @@ module Vector4 =
|
|||
Assert.Equal(z, v2.Z)
|
||||
Assert.Equal(w, v2.W)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Indexing =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -121,7 +121,7 @@ module Vector4 =
|
|||
|
||||
(fun() -> v.[4] |> ignore) |> Assert.ThrowsIndexExn
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Length =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -145,7 +145,7 @@ module Vector4 =
|
|||
|
||||
Assert.Equal(lsq, v.LengthSquared)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Normalization =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -153,6 +153,8 @@ module Vector4 =
|
|||
let v = Vector4(x, y, z, w)
|
||||
let l = v.Length
|
||||
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq l 0.0f) then
|
||||
let norm = v.Normalized()
|
||||
|
||||
Assert.ApproximatelyEqual(v.X / l, norm.X)
|
||||
|
@ -165,6 +167,8 @@ module Vector4 =
|
|||
let v = Vector4(x, y, z, w)
|
||||
let l = v.Length
|
||||
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq l 0.0f) then
|
||||
let norm = Vector4(x, y, z, w)
|
||||
norm.Normalize()
|
||||
|
||||
|
@ -188,6 +192,8 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization by reference is the same as division by magnitude`` (a : Vector4) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
let vRes = Vector4.Normalize(ref a)
|
||||
|
||||
|
@ -195,6 +201,8 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Normalization is the same as division by magnitude`` (a : Vector4) =
|
||||
// Zero-length vectors can't be normalized
|
||||
if not (approxEq a.Length 0.0f) then
|
||||
let norm = a / a.Length
|
||||
|
||||
Assert.ApproximatelyEqual(norm, Vector4.Normalize(a));
|
||||
|
@ -211,12 +219,11 @@ module Vector4 =
|
|||
[<Property>]
|
||||
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 = a * scale
|
||||
|
||||
Assert.ApproximatelyEqual(norm, Vector4.NormalizeFast(a));
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Addition =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -258,7 +265,7 @@ module Vector4 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Subtraction =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -286,7 +293,7 @@ module Vector4 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Multiplication =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -374,7 +381,7 @@ module Vector4 =
|
|||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Division =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -389,7 +396,7 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector4-Vector4 division method is the same as component division`` (a : Vector4, b : Vector4) =
|
||||
|
||||
if not (anyZero4 a || anyZero4 b) then
|
||||
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)
|
||||
|
||||
|
@ -397,7 +404,7 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector4-Vector4 divison method by reference is the same as component division`` (a : Vector4, b : Vector4) =
|
||||
|
||||
if not (anyZero4 a || anyZero4 b) then
|
||||
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)
|
||||
|
||||
|
@ -405,7 +412,7 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector4-scalar division method is the same as component division`` (a : Vector4, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then // we don't support diving by zero.
|
||||
let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b)
|
||||
let sum = Vector4.Divide(a, b)
|
||||
|
||||
|
@ -413,13 +420,13 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``Static Vector4-scalar divison method by reference is the same as component division`` (a : Vector4, b : float32) =
|
||||
|
||||
if not (approxEq b 0.0f) then // we don't support diving by zero.
|
||||
let v1 = Vector4(a.X / b, a.Y / b, a.Z / b, a.W / b)
|
||||
let sum = Vector4.Divide(ref a, b)
|
||||
|
||||
Assert.ApproximatelyEqual(v1, sum)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Negation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -431,7 +438,7 @@ module Vector4 =
|
|||
Assert.Equal(-z, vNeg.Z)
|
||||
Assert.Equal(-w, vNeg.W)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Equality =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -471,7 +478,7 @@ module Vector4 =
|
|||
|
||||
Assert.False(inequalityByOtherType)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Swizzling =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -650,7 +657,7 @@ module Vector4 =
|
|||
Assert.Equal(wy, v.Wy)
|
||||
Assert.Equal(wz, v.Wz)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Interpolation =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -679,7 +686,7 @@ module Vector4 =
|
|||
let vRes = Vector4.BaryCentric(ref a, ref b, ref c, u, v)
|
||||
Assert.Equal(r, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Vector products`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -691,11 +698,13 @@ module Vector4 =
|
|||
let vRes = Vector4.Dot(ref a, ref b)
|
||||
Assert.Equal(dot, vRes)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Magnitude min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
let ``MagnitudeMin selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -710,6 +719,8 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -724,6 +735,8 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMin by reference selects the vector with equal or lesser magnitude given two vectors`` (v1 : Vector4, v2: Vector4) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -738,6 +751,8 @@ module Vector4 =
|
|||
|
||||
[<Property>]
|
||||
let ``MagnitudeMax by reference selects the vector with equal or greater magnitude given two vectors`` (v1 : Vector4, v2: Vector4) =
|
||||
// Results do not matter for equal vectors
|
||||
if not (v1 = v2) then
|
||||
let l1 = v1.LengthSquared
|
||||
let l2 = v2.LengthSquared
|
||||
|
||||
|
@ -750,7 +765,7 @@ module Vector4 =
|
|||
let v2LongerThanv1 = l2 > l1
|
||||
Assert.True(v2LongerThanv1)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Component min and max`` =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -794,7 +809,7 @@ module Vector4 =
|
|||
Assert.True(isComponentLargest vMax.W v1.W v2.W)
|
||||
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Clamping =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -825,7 +840,7 @@ module Vector4 =
|
|||
Assert.Equal(expZ, res.Z)
|
||||
Assert.Equal(expW, res.W)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module ``Unit vectors``=
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -864,7 +879,7 @@ module Vector4 =
|
|||
|
||||
Assert.Equal(Vector4.One, unitOne)
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Serialization =
|
||||
//
|
||||
[<Property>]
|
||||
|
@ -874,7 +889,7 @@ module Vector4 =
|
|||
Assert.Equal(expectedSize, Vector4.SizeInBytes)
|
||||
Assert.Equal(expectedSize, Marshal.SizeOf(Vector4()))
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |], MaxTest = 10000)>]
|
||||
module Transformation =
|
||||
//
|
||||
[<Property>]
|
||||
|
|
Loading…
Reference in a new issue