Introduce ensurePartOfDayIs
This commit is contained in:
parent
8f53033db4
commit
b3689108a7
3 changed files with 46 additions and 32 deletions
|
|
@ -49,3 +49,21 @@ let ensureLightHasPower (light: Light) (genInteractions: Gen<Interaction list>)
|
|||
interactions
|
||||
else
|
||||
interactions @ [ HumanInteraction(LightPoweredOn light) ])
|
||||
|
||||
let ensurePartOfDayIs (desiredPartOfDay: PartOfDay) (genInteractions: Gen<Interaction list>) =
|
||||
genInteractions
|
||||
|> Gen.bind (fun interactions ->
|
||||
let maybeActualTime =
|
||||
interactions
|
||||
|> Seq.choose (fun interaction ->
|
||||
match interaction with
|
||||
| Interaction.TimeChanged time -> Some time
|
||||
| _ -> None)
|
||||
|> Seq.tryLast
|
||||
|
||||
if maybeActualTime |> Option.map getPartOfDay = Some desiredPartOfDay then
|
||||
Gen.constant interactions
|
||||
else
|
||||
desiredPartOfDay
|
||||
|> genTimeChangedToPartOfDay
|
||||
|> Gen.map (fun tc -> interactions @ [ tc ]))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue