diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index c4412a6..aadeb95 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -42,6 +42,16 @@ let getPartOfDayAfterInteractions interactions = |> Seq.last |> getPartOfDay +let doesLightHavePowerAfterInteractions light interactions = + 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 ensureStartsWithTimeChanged (genInteractions: Gen) = genInteractions |> Gen.bind (fun interactions -> @@ -52,17 +62,7 @@ let ensureStartsWithTimeChanged (genInteractions: Gen) = let ensureLightHasPower (light: Light) (genInteractions: Gen) = genInteractions |> Gen.map (fun interactions -> - let lightHasPower = - 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 - - if lightHasPower then + if doesLightHavePowerAfterInteractions light interactions then interactions else interactions @ [ HumanInteraction(LightPoweredOn light) ]) diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 8ed5ab3..5ad3ab6 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -44,16 +44,23 @@ type NightLightTests() = |> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0) |> Prop.collect $"{fakeHome.LightsThatAreOn.Length} light(s) on" - [ |])>] - let ``All non-remotely controlled lights with power should be on`` (light: Light) = - genBiasedInteractions light - |> ensureLightHasPower light - |> ensureStartsWithTimeChanged - |> Arb.fromGen - |> Prop.forAll + [] + let ``All non-remotely controlled lights that have power should be on`` () = + genInteractions |> ensureStartsWithTimeChanged |> Arb.fromGen |> Prop.forAll <| fun interactions -> let fakeHome = createFakeHomeWithNightLightAndInteract interactions - fakeHome.LightShouldHaveState light _.IsOn + + let nonRemotelyControlledLightsWithPower = + fakeHome.LightStates + |> Seq.filter (fun (light, _) -> + light.ControlledWithRemote = NonRemote + && doesLightHavePowerAfterInteractions light interactions) + |> Seq.toList + + nonRemotelyControlledLightsWithPower + |> Seq.forall (snd >> _.IsOn) + |> Prop.trivial (nonRemotelyControlledLightsWithPower.Length = 0) + |> Prop.collect $"{nonRemotelyControlledLightsWithPower.Length} non-remotely controlled light(s) with power" [ |])>] let ``If the remote was never used, all remote controlled lights with power should be on`` (light: Light) =