Add some synctatic sugar

This commit is contained in:
Sven van Heugten 2026-01-08 20:58:24 +01:00
parent 0033fed73e
commit 2c051c0b3d
2 changed files with 6 additions and 4 deletions

View file

@ -7,3 +7,5 @@ let concatGens (gens: Gen<'a list> list) : Gen<'a list> =
match gens with match gens with
| [] -> Gen.constant [] | [] -> Gen.constant []
| first :: rest -> rest |> List.fold (fun accGen g -> Gen.map2 (@) accGen g) first | first :: rest -> rest |> List.fold (fun accGen g -> Gen.map2 (@) accGen g) first
let (=<<) m f = Gen.bind m f

View file

@ -40,7 +40,7 @@ type NightLightTests() =
[<Property>] [<Property>]
let ``All lights that are on should be white or yellow during the day`` () = let ``All lights that are on should be white or yellow during the day`` () =
concatGens concatGens
[ Gen.bind genInitialInteractionsAndEndWith genTimeChangedToDay [ genInitialInteractionsAndEndWith =<< genTimeChangedToDay
genInteractionsExcept isTimeChangedToNight ] genInteractionsExcept isTimeChangedToNight ]
|> Arb.fromGen |> Arb.fromGen
|> Prop.forAll |> Prop.forAll
@ -53,7 +53,7 @@ type NightLightTests() =
[<Property>] [<Property>]
let ``All lights that are on should be red during the night`` () = let ``All lights that are on should be red during the night`` () =
concatGens concatGens
[ Gen.bind genInitialInteractionsAndEndWith genTimeChangedToNight [ genInitialInteractionsAndEndWith =<< genTimeChangedToNight
genInteractionsExcept isTimeChangedToDay ] genInteractionsExcept isTimeChangedToDay ]
|> Arb.fromGen |> Arb.fromGen
|> Prop.forAll |> Prop.forAll
@ -105,9 +105,9 @@ type NightLightTests() =
= =
let genInitialInteractionsListThatEndsWithTransitionToDay = let genInitialInteractionsListThatEndsWithTransitionToDay =
concatGens concatGens
[ Gen.bind genInitialInteractionsAndEndWith genTimeChangedToNight [ genInitialInteractionsAndEndWith =<< genTimeChangedToNight
genInteractionsExcept isTimeChangedToDay genInteractionsExcept isTimeChangedToDay
Gen.map List.singleton genTimeChangedToDay ] genTimeChangedToDay |> Gen.map List.singleton ]
concatGens concatGens
[ genInitialInteractionsListThatEndsWithTransitionToDay [ genInitialInteractionsListThatEndsWithTransitionToDay