diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index a431f96..1f155ca 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -67,3 +67,22 @@ let ensurePartOfDayIs (desiredPartOfDay: PartOfDay) (genInteractions: Gen genTimeChangedToPartOfDay |> Gen.map (fun tc -> interactions @ [ tc ])) + +let ensureLastRemoteInteractionIs + (desiredLastRemoteInteraction: RemoteInteraction) + (genInteractions: Gen) + = + 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 ]) diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 6320b95..49c149e 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -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`` (light: Light) = - concatGens - [ genRandomInteractions light - RemoteInteraction RemotePressedOnButton |> List.singleton |> Gen.constant - genRandomInteractionsExcept light _.IsRemoteInteraction ] + genRandomInteractions light + |> ensureLastRemoteInteractionIs RemotePressedOnButton |> ensureLightHasPower light |> ensureStartsWithTimeChanged |> 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`` (light: Light) = - concatGens - [ genRandomInteractions light - RemoteInteraction RemotePressedLeftButton |> List.singleton |> Gen.constant - genRandomInteractionsExcept light _.IsRemoteInteraction ] + genRandomInteractions light + |> ensureLastRemoteInteractionIs RemotePressedLeftButton |> ensureStartsWithTimeChanged |> ensureLightHasPower light |> Arb.fromGen