From 2da1972b06d933900f3d4924a8300eda0b1b3f21 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Thu, 8 Jan 2026 22:30:07 +0100 Subject: [PATCH] Get rid of the [...]AndEndWith helper I introduced this to test a very specific edge case right after initialization, but it made all tests harder to read. --- .../InteractionListGenerators.fs | 16 +++++----------- NightLight.Core.Tests/NightLightTests.fs | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index 641d87c..2f2b529 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -24,18 +24,12 @@ let genInitialInteractions biasTowardsLight = Gen.listOf <| genInteraction biasTowardsLight ] |> concatGens -let genInitialInteractionsAndEndWith biasTowardsLight (endsWith: Interaction) = - let genNonTrivialList = - genInitialInteractions biasTowardsLight - |> Gen.map (fun lst -> lst @ [ endsWith ]) - - match endsWith with - | Interaction.TimeChanged _ -> - let genTrivialList = Gen.constant <| List.singleton endsWith - Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ] - | _ -> genNonTrivialList - let genInteractionsExcept biasTowardsLight disqualifier = genInteraction biasTowardsLight |> Gen.filter (not << disqualifier) |> Gen.listOf + +let genInitialInteractionsExcept biasTowardsLight disqualifier = + [ genTimeChanged |> Gen.map List.singleton + genInteractionsExcept biasTowardsLight disqualifier ] + |> concatGens diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 35ec4cf..f306268 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -38,7 +38,8 @@ type NightLightTests() = [ |])>] let ``All lights should be either off, white or yellow during the day`` (light: Light) = concatGens - [ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomDayTime + [ genInitialInteractions light + genTimeChangedToRandomDayTime |> Gen.map List.singleton genInteractionsExcept light isTimeChangedToAnyNightTime ] |> Arb.fromGen |> Prop.forAll @@ -52,7 +53,8 @@ type NightLightTests() = [ |])>] let ``All lights should be either off or red during the night`` (light: Light) = concatGens - [ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomNightTime + [ genInitialInteractions light + genTimeChangedToRandomNightTime |> Gen.map List.singleton genInteractionsExcept light isTimeChangedToAnyDayTime ] |> Arb.fromGen |> Prop.forAll @@ -75,9 +77,7 @@ type NightLightTests() = let ``All remote controlled lights with power should be on if the 'Off' button on the remote was never pressed`` (light: Light) = - concatGens - [ genTimeChanged |> Gen.map List.singleton - genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ] + genInitialInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) |> Arb.fromGen |> Prop.forAll <| fun interactions -> @@ -91,7 +91,8 @@ type NightLightTests() = (light: Light) = concatGens - [ genInitialInteractionsAndEndWith light (HumanInteraction RemotePressedOnButton) + [ genInitialInteractions light + HumanInteraction RemotePressedOnButton |> List.singleton |> Gen.constant genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ] |> Arb.fromGen |> Prop.forAll @@ -106,7 +107,8 @@ type NightLightTests() = (light: Light) = concatGens - [ genInitialInteractionsAndEndWith light =<< genTimeChangedToRandomNightTime + [ genInitialInteractions light + genTimeChangedToRandomNightTime |> Gen.map List.singleton genInteractionsExcept light isTimeChangedToAnyDayTime genTimeChangedToRandomDayTime |> Gen.map List.singleton genInteractionsExcept light ((=) (HumanInteraction RemotePressedOffButton)) ] @@ -123,7 +125,8 @@ type NightLightTests() = (light: Light) = concatGens - [ genInitialInteractionsAndEndWith light (HumanInteraction RemotePressedOffButton) + [ genInitialInteractions light + HumanInteraction RemotePressedOffButton |> List.singleton |> Gen.constant genInteractionsExcept light (fun interaction -> interaction = HumanInteraction RemotePressedOnButton || interaction |> isTimeChangedToAnyDayTime) ]