2017-03-19 14:35:46 +01:00
|
|
|
namespace OpenTK.Tests
|
|
|
|
|
|
|
|
open Xunit
|
|
|
|
open FsCheck
|
|
|
|
open FsCheck.Xunit
|
|
|
|
open System
|
|
|
|
open OpenTK
|
|
|
|
|
|
|
|
[<AutoOpen>]
|
2017-06-01 21:12:59 +02:00
|
|
|
module private AssertHelpers =
|
2017-03-19 14:35:46 +01:00
|
|
|
[<Literal>]
|
2017-06-04 19:05:43 +02:00
|
|
|
let private BitAccuracy = 16
|
2017-06-01 21:12:59 +02:00
|
|
|
|
2017-06-07 14:27:36 +02:00
|
|
|
[<Literal>]
|
2017-06-07 15:22:52 +02:00
|
|
|
let private EquivalenceTolerance = 0.00005f
|
2017-06-07 14:27:36 +02:00
|
|
|
|
|
|
|
let approxEq a b = MathHelper.ApproximatelyEquivalent(a, b, EquivalenceTolerance)
|
2017-06-07 15:22:52 +02:00
|
|
|
|
|
|
|
let approxEqDelta a b = MathHelper.ApproximatelyEqual(a,b,BitAccuracy)
|
2017-06-07 14:27:36 +02:00
|
|
|
|
2017-06-04 19:05:43 +02:00
|
|
|
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)
|
2017-03-19 14:35:46 +01:00
|
|
|
|
|
|
|
/// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal.
|
|
|
|
[<Sealed>]
|
2017-06-01 21:12:59 +02:00
|
|
|
type internal Assert =
|
|
|
|
|
2017-06-07 15:22:52 +02:00
|
|
|
static member ApproximatelyEquivalent(a : Vector2,b : Vector2) =
|
2017-03-19 14:35:46 +01:00
|
|
|
if not <| approxEq a.X b.X && approxEq a.Y b.Y then raise <| new Xunit.Sdk.EqualException(a,b)
|
2017-06-01 21:12:59 +02:00
|
|
|
|
2017-06-07 15:22:52 +02:00
|
|
|
static member ApproximatelyEquivalent(a : Vector3,b : Vector3) =
|
2017-03-19 14:35:46 +01:00
|
|
|
if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z then raise <| new Xunit.Sdk.EqualException(a,b)
|
2017-06-01 21:12:59 +02:00
|
|
|
|
2017-06-07 15:22:52 +02:00
|
|
|
static member ApproximatelyEquivalent(a : Vector4,b : Vector4) =
|
2017-06-01 21:12:59 +02:00
|
|
|
if not <| approxEq a.X b.X && approxEq a.Y b.Y && approxEq a.Z b.Z && approxEq a.W b.W then
|
2017-03-19 14:35:46 +01:00
|
|
|
raise <| new Xunit.Sdk.EqualException(a,b)
|
2017-06-01 21:12:59 +02:00
|
|
|
|
2017-06-07 15:22:52 +02:00
|
|
|
static member ApproximatelyEquivalent(a : float32,b : float32) =
|
2017-03-19 14:35:46 +01:00
|
|
|
if not <| approxEq a b then raise <| new Xunit.Sdk.EqualException(a,b)
|
2017-06-02 13:48:29 +02:00
|
|
|
|
|
|
|
|
2017-06-04 19:05:43 +02:00
|
|
|
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)
|
|
|
|
|
2017-06-02 13:48:29 +02:00
|
|
|
static member ThrowsIndexExn(f:unit -> unit) = Assert.Throws<IndexOutOfRangeException>(f) |> ignore
|