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

View file

@ -16,4 +16,4 @@ nuget xunit.core 2.2.0 restriction: >= net452
nuget xunit.assert 2.2.0 restriction: >= net452 nuget xunit.assert 2.2.0 restriction: >= net452
nuget FAKE nuget FAKE
nuget Mono.Cecil >= 0.10.0-beta6 nuget Mono.Cecil >= 0.10.0-beta6
nuget gtk-sharp3 nuget gtk-sharp3

View file

@ -1,4 +1,4 @@
namespace OpenTK.Tests namespace OpenTK.Tests.Generators
open Xunit open Xunit
open FsCheck open FsCheck
@ -7,7 +7,7 @@ open System
open OpenTK open OpenTK
[<AutoOpen>] [<AutoOpen>]
module private AssertHelpers = module public AssertHelpers =
[<Literal>] [<Literal>]
let private BitAccuracy = 16 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. /// We use a full type here instead of a module, as the overloading semantics are more suitable for our desired goal.
[<Sealed>] [<Sealed>]
type internal Assert = type public Assert =
static member ApproximatelyEquivalent(a : Vector2,b : Vector2) = 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) 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
open FsCheck.Xunit
open System open System
open OpenTK open OpenTK
@ -66,7 +64,7 @@ module private Generators =
|> Gen.map Matrix4 |> Gen.map Matrix4
|> Arb.fromGen |> Arb.fromGen
type OpenTKGen = type public OpenTKGen =
static member Single() = single static member Single() = single
static member float32() = single static member float32() = single
static member Double() = double 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,16 +1,38 @@
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 public class BezierCurveTests
{ {
[Fact] [Properties(Arbitrary = new[] { typeof(OpenTKGen) })]
public void StraightLine() public class Constructor
{ {
var curve = new BezierCurve(Vector2.Zero, Vector2.One); [Property]
Assert.Equal(Vector2.Zero, curve.CalculatePoint(0.0f)); public void AcceptingVector2EnumerableCreatesCurveContainingThePointsInTheEnumerable
Assert.Equal(Vector2.One, curve.CalculatePoint(1.0f)); (Vector2 a, Vector2 b, Vector2 c, Vector2 d)
Assert.Equal(new Vector2(0.5f, 0.5f), curve.CalculatePoint(0.5f)); {
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()
{
var curve = new BezierCurve(Vector2.Zero, Vector2.One);
Assert.Equal(Vector2.Zero, curve.CalculatePoint(0.0f));
Assert.Equal(Vector2.One, curve.CalculatePoint(1.0f));
Assert.Equal(new Vector2(0.5f, 0.5f), curve.CalculatePoint(0.5f));
}
} }
} }
} }

File diff suppressed because it is too large Load diff

View file

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

View file

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

View file

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

View file

@ -62,8 +62,6 @@
--> -->
<ItemGroup> <ItemGroup>
<Compile Include="AssemblyInfo.fs" /> <Compile Include="AssemblyInfo.fs" />
<Compile Include="Assertions.fs" />
<Compile Include="Generators.fs" />
<Compile Include="MathHelperTests.fs" /> <Compile Include="MathHelperTests.fs" />
<Compile Include="Matrix4Tests.fs" /> <Compile Include="Matrix4Tests.fs" />
<Compile Include="Vector2Tests.fs" /> <Compile Include="Vector2Tests.fs" />
@ -74,6 +72,10 @@
<None Include="paket.references" /> <None Include="paket.references" />
</ItemGroup> </ItemGroup>
<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="mscorlib" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />

View file

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

View file

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

View file

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