From d7fac9c3d07147af83da2ca059e10942bb1bbd18 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Thu, 8 Jan 2026 21:45:46 +0100 Subject: [PATCH] Verify that non-remotely controlled lights are on if they have power --- .../InteractionListGenerators.fs | 4 ++-- NightLight.Core.Tests/LightArbitraries.fs | 7 +++++++ NightLight.Core.Tests/NightLightTests.fs | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index e254b1a..641d87c 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -19,14 +19,14 @@ let private genHumanInteraction biasTowardsLight = let private genInteraction biasTowardsLight = Gen.oneof [ genTimeChanged; genHumanInteraction biasTowardsLight ] -let private genInteractionsListThatStartsWithTimeChanged biasTowardsLight = +let genInitialInteractions biasTowardsLight = [ genTimeChanged |> Gen.map List.singleton Gen.listOf <| genInteraction biasTowardsLight ] |> concatGens let genInitialInteractionsAndEndWith biasTowardsLight (endsWith: Interaction) = let genNonTrivialList = - genInteractionsListThatStartsWithTimeChanged biasTowardsLight + genInitialInteractions biasTowardsLight |> Gen.map (fun lst -> lst @ [ endsWith ]) match endsWith with diff --git a/NightLight.Core.Tests/LightArbitraries.fs b/NightLight.Core.Tests/LightArbitraries.fs index 65240f6..e91e114 100644 --- a/NightLight.Core.Tests/LightArbitraries.fs +++ b/NightLight.Core.Tests/LightArbitraries.fs @@ -6,6 +6,13 @@ open FsCheck.FSharp type ArbitraryLight = static member Light() = lights |> Gen.elements |> Arb.fromGen +type ArbitraryNonRemotelyControlledLight = + static member Light() = + lights + |> Seq.filter (not << _.ControlledWithRemote) + |> Gen.elements + |> Arb.fromGen + type ArbitraryRemotelyControlledLight = static member Light() = lights |> Seq.filter _.ControlledWithRemote |> Gen.elements |> Arb.fromGen diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 2eea0ea..4e795da 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -63,8 +63,16 @@ type NightLightTests() = | Off -> true | On(_, color) -> color = Red) - [ |])>] - let ``After pressing 'On' on the remote, all lights with power should be on, as long as the 'Off' button isn't pressed`` + [ |])>] + let ``All non-remotely controlled lights should be on *if and only if* they have power`` (light: Light) = + genInitialInteractions light |> Arb.fromGen |> Prop.forAll + <| fun interactions -> + let fakeHome = createFakeHomeWithNightLightAndInteract interactions + + doesLightHavePowerAfter light interactions = fakeHome.LightShouldHaveState light _.IsOn + + [ |])>] + let ``After pressing 'On' on the remote, all remotely controlled lights with power should be on, as long as the 'Off' button isn't pressed`` (light: Light) = concatGens @@ -78,8 +86,8 @@ type NightLightTests() = doesLightHavePowerAfter light interactions ==> fakeHome.LightShouldHaveState light _.IsOn - [ |])>] - let ``After a new day starts, all lights with power should be on, as long as the 'Off' button isn't pressed`` + [ |])>] + let ``After a new day starts, all remotely controlled lights with power should be on, as long as the 'Off' button isn't pressed`` (light: Light) = concatGens