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:
parent
0a5c346c52
commit
6ad8b92c84
15 changed files with 3021 additions and 21 deletions
|
@ -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
|
||||
|
|
|
@ -16,4 +16,4 @@ nuget xunit.core 2.2.0 restriction: >= net452
|
|||
nuget xunit.assert 2.2.0 restriction: >= net452
|
||||
nuget FAKE
|
||||
nuget Mono.Cecil >= 0.10.0-beta6
|
||||
nuget gtk-sharp3
|
||||
nuget gtk-sharp3
|
|
@ -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)
|
|
@ -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
|
1538
tests/OpenTK.Tests.Generators/OpenTK.Tests.Generators.fsproj
Normal file
1538
tests/OpenTK.Tests.Generators/OpenTK.Tests.Generators.fsproj
Normal file
File diff suppressed because it is too large
Load diff
2
tests/OpenTK.Tests.Generators/paket.references
Normal file
2
tests/OpenTK.Tests.Generators/paket.references
Normal file
|
@ -0,0 +1,2 @@
|
|||
xunit
|
||||
FsCheck.XUnit
|
|
@ -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
|
||||
{
|
||||
[Fact]
|
||||
public void StraightLine()
|
||||
[Properties(Arbitrary = new[] { typeof(OpenTKGen) })]
|
||||
public class Constructor
|
||||
{
|
||||
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));
|
||||
[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()
|
||||
{
|
||||
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
|
@ -3,4 +3,5 @@ xunit.assert
|
|||
xunit
|
||||
xunit.abstractions
|
||||
xunit.extensibility.core
|
||||
xunit.extensibility.execution
|
||||
xunit.extensibility.execution
|
||||
FsCheck.XUnit
|
|
@ -5,6 +5,7 @@ open FsCheck
|
|||
open FsCheck.Xunit
|
||||
open System
|
||||
open OpenTK
|
||||
open OpenTK.Tests.Generators
|
||||
|
||||
module MathHelper =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
|
|
|
@ -5,6 +5,7 @@ open FsCheck
|
|||
open FsCheck.Xunit
|
||||
open System
|
||||
open OpenTK
|
||||
open OpenTK.Tests.Generators
|
||||
|
||||
module Matrix4 =
|
||||
[<Properties(Arbitrary = [| typeof<OpenTKGen> |])>]
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -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> |])>]
|
||||
|
|
|
@ -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> |])>]
|
||||
|
|
|
@ -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> |])>]
|
||||
|
|
Loading…
Reference in a new issue