Introduce ensureLastRemoteInteractionIs
This commit is contained in:
parent
b3689108a7
commit
d509829304
2 changed files with 23 additions and 8 deletions
|
|
@ -67,3 +67,22 @@ let ensurePartOfDayIs (desiredPartOfDay: PartOfDay) (genInteractions: Gen<Intera
|
||||||
desiredPartOfDay
|
desiredPartOfDay
|
||||||
|> genTimeChangedToPartOfDay
|
|> genTimeChangedToPartOfDay
|
||||||
|> Gen.map (fun tc -> interactions @ [ tc ]))
|
|> Gen.map (fun tc -> interactions @ [ tc ]))
|
||||||
|
|
||||||
|
let ensureLastRemoteInteractionIs
|
||||||
|
(desiredLastRemoteInteraction: RemoteInteraction)
|
||||||
|
(genInteractions: Gen<Interaction list>)
|
||||||
|
=
|
||||||
|
genInteractions
|
||||||
|
|> Gen.map (fun interactions ->
|
||||||
|
let maybeLastRemoteInteraction =
|
||||||
|
interactions
|
||||||
|
|> Seq.choose (fun interaction ->
|
||||||
|
match interaction with
|
||||||
|
| Interaction.RemoteInteraction remoteInteraction -> Some remoteInteraction
|
||||||
|
| _ -> None)
|
||||||
|
|> Seq.tryLast
|
||||||
|
|
||||||
|
if maybeLastRemoteInteraction = Some desiredLastRemoteInteraction then
|
||||||
|
interactions
|
||||||
|
else
|
||||||
|
interactions @ [ RemoteInteraction desiredLastRemoteInteraction ])
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,8 @@ type NightLightTests() =
|
||||||
let ``After pressing 'On' on the remote, if the remote isn't used again, all remotely controlled lights with power should be on``
|
let ``After pressing 'On' on the remote, if the remote isn't used again, all remotely controlled lights with power should be on``
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
genRandomInteractions light
|
||||||
[ genRandomInteractions light
|
|> ensureLastRemoteInteractionIs RemotePressedOnButton
|
||||||
RemoteInteraction RemotePressedOnButton |> List.singleton |> Gen.constant
|
|
||||||
genRandomInteractionsExcept light _.IsRemoteInteraction ]
|
|
||||||
|> ensureLightHasPower light
|
|> ensureLightHasPower light
|
||||||
|> ensureStartsWithTimeChanged
|
|> ensureStartsWithTimeChanged
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|
|
@ -127,10 +125,8 @@ type NightLightTests() =
|
||||||
let ``After pressing 'Left' on the remote, if the remote isn't used again, all left-side remotely controlled lights with power should be on``
|
let ``After pressing 'Left' on the remote, if the remote isn't used again, all left-side remotely controlled lights with power should be on``
|
||||||
(light: Light)
|
(light: Light)
|
||||||
=
|
=
|
||||||
concatGens
|
genRandomInteractions light
|
||||||
[ genRandomInteractions light
|
|> ensureLastRemoteInteractionIs RemotePressedLeftButton
|
||||||
RemoteInteraction RemotePressedLeftButton |> List.singleton |> Gen.constant
|
|
||||||
genRandomInteractionsExcept light _.IsRemoteInteraction ]
|
|
||||||
|> ensureStartsWithTimeChanged
|
|> ensureStartsWithTimeChanged
|
||||||
|> ensureLightHasPower light
|
|> ensureLightHasPower light
|
||||||
|> Arb.fromGen
|
|> Arb.fromGen
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue