Split FsCheck data generators into a helper library (#716)

* Move generators and assertions to helper library.

* Add example usage to bezier curve tests.

* Add FsCheck to OpenTK.Tests.Math via paket.

* Tweak fsharp msbuild settings for OpenTK.Tests.Generators.
This commit is contained in:
Jarl Gullberg 2018-01-09 12:06:39 +01:00 committed by GitHub
parent 0a5c346c52
commit 6ad8b92c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 3021 additions and 21 deletions

View file

@ -41,6 +41,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests.Integration",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTK.Tests.Math", "tests\OpenTK.Tests.Math\OpenTK.Tests.Math.csproj", "{C2B07CD9-B388-4FC3-AF31-C648F7EA904E}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests.Generators", "tests\OpenTK.Tests.Generators\OpenTK.Tests.Generators.fsproj", "{2B11AAEB-D8AC-4356-938F-532D720E0C30}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -91,6 +93,10 @@ Global
{C2B07CD9-B388-4FC3-AF31-C648F7EA904E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2B07CD9-B388-4FC3-AF31-C648F7EA904E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2B07CD9-B388-4FC3-AF31-C648F7EA904E}.Release|Any CPU.Build.0 = Release|Any CPU
{2B11AAEB-D8AC-4356-938F-532D720E0C30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B11AAEB-D8AC-4356-938F-532D720E0C30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B11AAEB-D8AC-4356-938F-532D720E0C30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B11AAEB-D8AC-4356-938F-532D720E0C30}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -99,5 +105,6 @@ Global
{6801C263-ADDA-4A7B-979D-649BCB5A1DF7} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
{522D9279-3ED6-475F-867A-6AE69A53C24A} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
{C2B07CD9-B388-4FC3-AF31-C648F7EA904E} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
{2B11AAEB-D8AC-4356-938F-532D720E0C30} = {1857BB8E-1A35-4EBF-9F6D-685F11DC025B}
EndGlobalSection
EndGlobal

View file

@ -1,4 +1,4 @@
namespace OpenTK.Tests
namespace OpenTK.Tests.Generators
open Xunit
open FsCheck
@ -7,7 +7,7 @@ open System
open OpenTK
[<AutoOpen>]
module private AssertHelpers =
module public AssertHelpers =
[<Literal>]
let private BitAccuracy = 16
@ -30,7 +30,7 @@ module private AssertHelpers =
/// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal.
[<Sealed>]
type internal Assert =
type public Assert =
static member ApproximatelyEquivalent(a : Vector2,b : Vector2) =
if not <| approxEq a.X b.X && approxEq a.Y b.Y then raise <| new Xunit.Sdk.EqualException(a,b)

View file

@ -1,8 +1,6 @@
namespace OpenTK.Tests
namespace OpenTK.Tests.Generators
open Xunit
open FsCheck
open FsCheck.Xunit
open System
open OpenTK
@ -66,7 +64,7 @@ module private Generators =
|> Gen.map Matrix4
|> Arb.fromGen
type OpenTKGen =
type public OpenTKGen =
static member Single() = single
static member float32() = single
static member Double() = double

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
xunit
FsCheck.XUnit

View file

@ -1,8 +1,29 @@
using Xunit;
using FsCheck.Xunit;
using OpenTK.Tests.Generators;
using Xunit;
using Assert = Xunit.Assert;
namespace OpenTK.Tests.Unit
namespace OpenTK.Tests.Math
{
public class BezierCurveTests
{
[Properties(Arbitrary = new[] { typeof(OpenTKGen) })]
public class Constructor
{
[Property]
public void AcceptingVector2EnumerableCreatesCurveContainingThePointsInTheEnumerable
(Vector2 a, Vector2 b, Vector2 c, Vector2 d)
{
var expected = new[] { a, b, c, d };
var curve = new BezierCurve(expected);
var actual = curve.Points;
Assert.Equal(expected, actual);
}
}
public class CalculatePoint
{
[Fact]
public void StraightLine()
@ -13,4 +34,5 @@ namespace OpenTK.Tests.Unit
Assert.Equal(new Vector2(0.5f, 0.5f), curve.CalculatePoint(0.5f));
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,4 @@ xunit
xunit.abstractions
xunit.extensibility.core
xunit.extensibility.execution
FsCheck.XUnit

View file

@ -5,6 +5,7 @@ open FsCheck
open FsCheck.Xunit
open System
open OpenTK
open OpenTK.Tests.Generators
module MathHelper =
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]

View file

@ -5,6 +5,7 @@ open FsCheck
open FsCheck.Xunit
open System
open OpenTK
open OpenTK.Tests.Generators
module Matrix4 =
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]

View file

@ -62,8 +62,6 @@
-->
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Assertions.fs" />
<Compile Include="Generators.fs" />
<Compile Include="MathHelperTests.fs" />
<Compile Include="Matrix4Tests.fs" />
<Compile Include="Vector2Tests.fs" />
@ -74,6 +72,10 @@
<None Include="paket.references" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenTK.Tests.Generators\OpenTK.Tests.Generators.fsproj">
<Project>{2b11aaeb-d8ac-4356-938f-532d720e0c30}</Project>
<Name>OpenTK.Tests.Generators</Name>
</ProjectReference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />

View file

@ -6,6 +6,7 @@ open FsCheck.Xunit
open System
open System.Runtime.InteropServices
open OpenTK
open OpenTK.Tests.Generators
module Vector2 =
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]

View file

@ -6,6 +6,7 @@ open FsCheck.Xunit
open System
open System.Runtime.InteropServices
open OpenTK
open OpenTK.Tests.Generators
module Vector3 =
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]

View file

@ -6,6 +6,7 @@ open FsCheck.Xunit
open System
open System.Runtime.InteropServices
open OpenTK
open OpenTK.Tests.Generators
module Vector4 =
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]