diff --git a/NightLight.Core.Tests/ArbitraryInteractionLists.fs b/NightLight.Core.Tests/ArbitraryInteractionLists.fs deleted file mode 100644 index 906ae6d..0000000 --- a/NightLight.Core.Tests/ArbitraryInteractionLists.fs +++ /dev/null @@ -1,26 +0,0 @@ -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 - && time.TimeOfDay < TimeSpan.FromHours 20.5 - -type ArbitraryInteractionListThatEndsDuringTheDay = - static member InteractionsList() = - ArbMap.defaults - |> ArbMap.generate - |> Gen.filter isDay - |> Gen.bind genInteractionListThatEndsAtTime - |> Arb.fromGen - -type ArbitraryInteractionListThatEndsDuringTheNight = - static member InteractionsList() = - ArbMap.defaults - |> ArbMap.generate - |> Gen.filter (not << isDay) - |> Gen.bind genInteractionListThatEndsAtTime - |> Arb.fromGen diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index 144579f..d901847 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -44,6 +44,3 @@ let genInteractionListContaining containingInteraction afterFilter = Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ] | _ -> genNonTrivialList } - -let genInteractionListThatEndsAtTime time = - genInteractionListContaining (Interaction.TimeChanged time) (not << _.IsTimeChanged) diff --git a/NightLight.Core.Tests/NightLight.Core.Tests.fsproj b/NightLight.Core.Tests/NightLight.Core.Tests.fsproj index 66f25e0..8dbe2c5 100644 --- a/NightLight.Core.Tests/NightLight.Core.Tests.fsproj +++ b/NightLight.Core.Tests/NightLight.Core.Tests.fsproj @@ -9,7 +9,7 @@ - + diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 4ca2fb7..292a417 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -1,9 +1,8 @@ namespace NightLight.Core.Tests open NightLight.Core.Core -open NightLight.Core.Tests.ArbitraryInteractionLists +open NightLight.Core.Tests.TimeChangedGenerators open NightLight.Core.Tests.InteractionListGenerators -open FsCheck open FsCheck.Xunit open FsCheck.FSharp @@ -24,15 +23,25 @@ type NightLightTests() = fakeHome - [ |])>] - let ``All lights that are on should be white or yellow during the day`` (interactions: Interaction list) = - let fakeHome = createFakeHomeWithNightLightAndInteract interactions - fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow) + [] + let ``All lights that are on should be white or yellow during the day`` () = + genTimeChangedToDay + |> Gen.bind (fun timeChangedToDay -> genInteractionListContaining timeChangedToDay (not << _.IsTimeChanged)) + |> Arb.fromGen + |> Prop.forAll + <| fun interactions -> + let fakeHome = createFakeHomeWithNightLightAndInteract interactions + fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow) - [ |])>] - 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 ``All lights that are on should be red during the night`` () = + genTimeChangedToNight + |> Gen.bind (fun timeChangedToNight -> genInteractionListContaining timeChangedToNight (not << _.IsTimeChanged)) + |> Arb.fromGen + |> Prop.forAll + <| fun interactions -> + 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`` diff --git a/NightLight.Core.Tests/TimeChangedGenerators.fs b/NightLight.Core.Tests/TimeChangedGenerators.fs new file mode 100644 index 0000000..6f1300d --- /dev/null +++ b/NightLight.Core.Tests/TimeChangedGenerators.fs @@ -0,0 +1,20 @@ +module NightLight.Core.Tests.TimeChangedGenerators + +open System +open FsCheck.FSharp + +let private isDay (time: DateTime) = + time.TimeOfDay >= TimeSpan.FromHours 5.5 + && time.TimeOfDay < TimeSpan.FromHours 20.5 + +let genTimeChangedToDay = + ArbMap.defaults + |> ArbMap.generate + |> Gen.filter isDay + |> Gen.map Interaction.TimeChanged + +let genTimeChangedToNight = + ArbMap.defaults + |> ArbMap.generate + |> Gen.filter (not << isDay) + |> Gen.map Interaction.TimeChanged