diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 57ed0f4..c90a3d1 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -23,6 +23,16 @@ type NightLightTests() = fakeHome + let doesLightHavePowerAfter interactions light = + interactions + |> Seq.choose (fun interaction -> + match interaction with + | HumanInteraction(LightPoweredOff l) when l = light -> Some false + | HumanInteraction(LightPoweredOn l) when l = light -> Some true + | _ -> None) + |> Seq.tryLast + |> Option.defaultValue false + [] let ``All lights that are on should be white or yellow during the day`` () = genTimeChangedToDay @@ -43,6 +53,24 @@ type NightLightTests() = let fakeHome = createFakeHomeWithNightLightAndInteract interactions fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red) + [] + let ``After pressing 'On' on the remote, the remotely controlled lights that have power should be on until they are powered off or 'Off' is pressed`` + () + = + genInteractionListContaining (HumanInteraction RemotePressedOnButton) (function + | HumanInteraction RemotePressedOffButton -> true + | HumanInteraction(LightPoweredOff l) when l.ControlledWithRemote -> true + | _ -> false) + |> Arb.fromGen + |> Prop.forAll + <| fun interactions -> + let fakeHome = createFakeHomeWithNightLightAndInteract interactions + + fakeHome.LightStates + |> Seq.filter (fst >> doesLightHavePowerAfter interactions) + |> Seq.map snd + |> Seq.forall _.IsOn + [] let ``After pressing 'Off' on the remote, the remotely controlled lights should stay off until 'On' is pressed`` ()