diff --git a/NightLight.Core.Tests/ArbitraryInteractionLists.fs b/NightLight.Core.Tests/ArbitraryInteractionLists.fs index 1a80df4..906ae6d 100644 --- a/NightLight.Core.Tests/ArbitraryInteractionLists.fs +++ b/NightLight.Core.Tests/ArbitraryInteractionLists.fs @@ -3,6 +3,7 @@ module NightLight.Core.Tests.ArbitraryInteractionLists open System open FsCheck.FSharp open NightLight.Core.Tests.InteractionListGenerators +open NightLight.Core.Models let private isDay (time: DateTime) = time.TimeOfDay >= TimeSpan.FromHours 5.5 diff --git a/NightLight.Core.Tests/FakeHome.fs b/NightLight.Core.Tests/FakeHome.fs index c3a7c4c..11e0bb0 100644 --- a/NightLight.Core.Tests/FakeHome.fs +++ b/NightLight.Core.Tests/FakeHome.fs @@ -139,3 +139,8 @@ type FakeHome with | On(brightness, color) -> Some(light, brightness, color) | Off -> None) |> Seq.forall condition + + member this.ForAllRemotelyControlledLights condition = + this.LightStates + |> Seq.filter (fst >> _.ControlledWithRemote) + |> Seq.forall condition diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index 7289a32..144579f 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -28,7 +28,7 @@ let private genInteractionsListThatStartsWithTimeChanged = return firstInteraction :: remainingInteractions } -let private genInteractionListContaining containingInteraction afterFilter = +let genInteractionListContaining containingInteraction afterFilter = gen { let genNonTrivialList = gen { diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 9eaad9e..4ca2fb7 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -2,7 +2,10 @@ namespace NightLight.Core.Tests open NightLight.Core.Core open NightLight.Core.Tests.ArbitraryInteractionLists +open NightLight.Core.Tests.InteractionListGenerators +open FsCheck open FsCheck.Xunit +open FsCheck.FSharp type NightLightTests() = let createFakeHomeWithNightLightAndInteract (interactions: Interaction list) = @@ -30,3 +33,16 @@ type NightLightTests() = let ``All lights that are on should be red during the night`` (interactions: Interaction list) = let fakeHome = createFakeHomeWithNightLightAndInteract interactions fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red) + + [] + let ``After pressing 'Off' on the remote, the remotely controlled lights should stay off until 'On' is pressed again`` + () + = + genInteractionListContaining + (HumanInteraction RemotePressedOffButton) + ((<>) (HumanInteraction RemotePressedOnButton)) + |> Arb.fromGen + |> Prop.forAll + <| fun interactions -> + let fakeHome = createFakeHomeWithNightLightAndInteract interactions + fakeHome.ForAllRemotelyControlledLights(fun (_, state) -> state = Off)