night-light/NightLight.Core.Tests/InteractionListGenerators.fs
2026-01-20 20:13:11 +01:00

43 lines
1.5 KiB
FSharp

module NightLight.Core.Tests.InteractionListGenerators
open System
open NightLight.Core.Models
open FsCheck.FSharp
let private genTimeChanged =
ArbMap.defaults |> ArbMap.generate<DateTime> |> Gen.map Interaction.TimeChanged
let private genHumanInteraction =
Gen.elements lights
|> Gen.bind (fun light -> Gen.elements [ LightPoweredOn light; LightPoweredOff light ])
|> Gen.map Interaction.HumanInteraction
let private genRemoteInteraction =
Gen.elements [ RemotePressedOnButton; RemotePressedOffButton; RemotePressedLeftButton ]
|> Gen.map RemoteInteraction
let private genInteraction =
Gen.frequency [ 4, genTimeChanged; 1, genHumanInteraction; 1, genRemoteInteraction ]
type ArbitraryInteractions() =
static member Interactions() =
let gen =
genInteraction
|> Gen.listOf
|> Gen.bind (fun interactions ->
match interactions with
| Interaction.TimeChanged _ :: _ -> Gen.constant interactions
| _ -> genTimeChanged |> Gen.map (fun tc -> tc :: interactions))
let removeFromFrontAfterFirst (lst: 'a list) : seq<'a list> =
Seq.unfold
(fun current ->
match current with
| [] -> None
| [ _ ] -> None
| first :: _ :: rest ->
let next = first :: rest
Some(next, next))
lst
Arb.fromGenShrink (gen, removeFromFrontAfterFirst)