Skip to content

Commit

Permalink
start moving tests to f# and property tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy committed Dec 31, 2023
1 parent 3bbcfdc commit f973715
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ScoutHelper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScoutHelperTests", "ScoutHe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OtterGui", "OtterGui\OtterGui.csproj", "{7A4734E7-B71E-4A2A-A497-25892BDE1C4A}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TestProject1", "TestProject1\TestProject1.fsproj", "{8937AF85-A11F-4B39-823C-776F120C6BA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -27,6 +29,10 @@ Global
{7A4734E7-B71E-4A2A-A497-25892BDE1C4A}.Debug|x64.Build.0 = Debug|Any CPU
{7A4734E7-B71E-4A2A-A497-25892BDE1C4A}.Release|x64.ActiveCfg = Release|Any CPU
{7A4734E7-B71E-4A2A-A497-25892BDE1C4A}.Release|x64.Build.0 = Release|Any CPU
{8937AF85-A11F-4B39-823C-776F120C6BA4}.Debug|x64.ActiveCfg = Debug|Any CPU
{8937AF85-A11F-4B39-823C-776F120C6BA4}.Debug|x64.Build.0 = Debug|Any CPU
{8937AF85-A11F-4B39-823C-776F120C6BA4}.Release|x64.ActiveCfg = Release|Any CPU
{8937AF85-A11F-4B39-823C-776F120C6BA4}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
40 changes: 40 additions & 0 deletions TestProject1/TestProject1.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Include="Utils\Curry.fs" />
<None Include="Utils\UtilGenerator.fsx" />
<Compile Include="Utils\FsCheckUtils.fs" />
<Compile Include="UtilsTests.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CSharpFunctionalExtensions" Version="2.40.3" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FsCheck" Version="2.16.6" />
<PackageReference Include="FsCheck.Xunit" Version="2.16.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1"/>
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ScoutHelper\ScoutHelper.csproj" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions TestProject1/Utils/Curry.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module TestProject1.Utils.Curry

let curry f' a b = f' (a, b)
let curry2 f' a b = f' (a, b)
let curry3 f' a b c = f' (a, b, c)
let curry4 f' a b c d = f' (a, b, c, d)
let curry5 f' a b c d e = f' (a, b, c, d, e)
let curry6 f' a b c d e f = f' (a, b, c, d, e, f)
let curry7 f' a b c d e f g = f' (a, b, c, d, e, f, g)
let curry8 f' a b c d e f g h = f' (a, b, c, d, e, f, g, h)

let uncurry f' (a, b) = f' a b
let uncurry2 f' (a, b) = f' a b
let uncurry3 f' (a, b, c) = f' a b c
let uncurry4 f' (a, b, c, d) = f' a b c d
let uncurry5 f' (a, b, c, d, e) = f' a b c d e
let uncurry6 f' (a, b, c, d, e, f) = f' a b c d e f
let uncurry7 f' (a, b, c, d, e, f, g) = f' a b c d e f g
let uncurry8 f' (a, b, c, d, e, f, g, h) = f' a b c d e f g h
126 changes: 126 additions & 0 deletions TestProject1/Utils/FsCheckUtils.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module TestProject1.Utils.FsCheckUtils

open Curry
open FsCheck

let gen2 a b = gen {
let! a' = a
let! b' = b
return (a', b')
}
let gen3 a b c = gen {
let! a' = a
let! b' = b
let! c' = c
return (a', b', c')
}
let gen4 a b c d = gen {
let! a' = a
let! b' = b
let! c' = c
let! d' = d
return (a', b', c', d')
}
let gen5 a b c d e = gen {
let! a' = a
let! b' = b
let! c' = c
let! d' = d
let! e' = e
return (a', b', c', d', e')
}
let gen6 a b c d e f = gen {
let! a' = a
let! b' = b
let! c' = c
let! d' = d
let! e' = e
let! f' = f
return (a', b', c', d', e', f')
}
let gen7 a b c d e f g = gen {
let! a' = a
let! b' = b
let! c' = c
let! d' = d
let! e' = e
let! f' = f
let! g' = g
return (a', b', c', d', e', f', g')
}
let gen8 a b c d e f g h = gen {
let! a' = a
let! b' = b
let! c' = c
let! d' = d
let! e' = e
let! f' = f
let! g' = g
let! h' = h
return (a', b', c', d', e', f', g', h')
}

let map2 a b =
gen2
(Arb.toGen a)
(Arb.toGen b)
|> Arb.fromGen
let map3 a b c =
gen3
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
|> Arb.fromGen
let map4 a b c d =
gen4
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
(Arb.toGen d)
|> Arb.fromGen
let map5 a b c d e =
gen5
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
(Arb.toGen d)
(Arb.toGen e)
|> Arb.fromGen
let map6 a b c d e f =
gen6
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
(Arb.toGen d)
(Arb.toGen e)
(Arb.toGen f)
|> Arb.fromGen
let map7 a b c d e f g =
gen7
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
(Arb.toGen d)
(Arb.toGen e)
(Arb.toGen f)
(Arb.toGen g)
|> Arb.fromGen
let map8 a b c d e f g h =
gen8
(Arb.toGen a)
(Arb.toGen b)
(Arb.toGen c)
(Arb.toGen d)
(Arb.toGen e)
(Arb.toGen f)
(Arb.toGen g)
(Arb.toGen h)
|> Arb.fromGen

let forAll2 a b f' = Prop.forAll (map2 a b) (uncurry2 f')
let forAll3 a b c f' = Prop.forAll (map3 a b c) (uncurry3 f')
let forAll4 a b c d f' = Prop.forAll (map4 a b c d) (uncurry4 f')
let forAll5 a b c d e f' = Prop.forAll (map5 a b c d e) (uncurry5 f')
let forAll6 a b c d e f f' = Prop.forAll (map6 a b c d e f) (uncurry6 f')
let forAll7 a b c d e f g f' = Prop.forAll (map7 a b c d e f g) (uncurry7 f')
let forAll8 a b c d e f g h f' = Prop.forAll (map8 a b c d e f g h) (uncurry8 f')
26 changes: 26 additions & 0 deletions TestProject1/Utils/UtilGenerator.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let map = List.map

let internal inc (n:int) : int list =
let rec inc' cur total =
match cur with
| _ when cur = total -> []
| _ -> cur :: (inc' (cur + 1) total)
inc' 0 n
let internal inc1 n = inc n |> map ((+) 1)
let internal chars n =
(inc n)
|> map (fun i -> char (97 + i))
|> map (fun c -> new string([|c|]))

let internal printFunc n f =
inc1 n
|> map (fun i -> f i <| chars i)

let _ = printFunc 8 <| fun i cs ->
printfn
"let forAll%i %s f' = Prop.forAll (map%i %s) (uncurry%i f')"
i
(String.concat " " cs)
i
(String.concat " " cs)
i
10 changes: 10 additions & 0 deletions TestProject1/UtilsTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module TestProject1.UtilsTests

open

open Xunit
open FsCheck

[<Fact>]
let ``My test`` () =
Prop.forAll

0 comments on commit f973715

Please sign in to comment.