Get rid of arbitraries that are only used once

This commit is contained in:
Sven van Heugten 2026-01-05 22:34:21 +01:00
parent 7472825140
commit bb528e9942
5 changed files with 40 additions and 40 deletions

View file

@ -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<DateTime>
|> Gen.filter isDay
|> Gen.bind genInteractionListThatEndsAtTime
|> Arb.fromGen
type ArbitraryInteractionListThatEndsDuringTheNight =
static member InteractionsList() =
ArbMap.defaults
|> ArbMap.generate<DateTime>
|> Gen.filter (not << isDay)
|> Gen.bind genInteractionListThatEndsAtTime
|> Arb.fromGen

View file

@ -44,6 +44,3 @@ let genInteractionListContaining containingInteraction afterFilter =
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
| _ -> genNonTrivialList
}
let genInteractionListThatEndsAtTime time =
genInteractionListContaining (Interaction.TimeChanged time) (not << _.IsTimeChanged)

View file

@ -9,7 +9,7 @@
<ItemGroup>
<Compile Include="FakeHome.fs" />
<Compile Include="InteractionListGenerators.fs" />
<Compile Include="ArbitraryInteractionLists.fs" />
<Compile Include="TimeChangedGenerators.fs" />
<Compile Include="NightLightTests.fs" />
</ItemGroup>

View file

@ -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,13 +23,23 @@ type NightLightTests() =
fakeHome
[<Property(Arbitrary = [| typeof<ArbitraryInteractionListThatEndsDuringTheDay> |])>]
let ``All lights that are on should be white or yellow during the day`` (interactions: Interaction list) =
[<Property>]
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)
[<Property(Arbitrary = [| typeof<ArbitraryInteractionListThatEndsDuringTheNight> |])>]
let ``All lights that are on should be red during the night`` (interactions: Interaction list) =
[<Property>]
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)

View file

@ -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<DateTime>
|> Gen.filter isDay
|> Gen.map Interaction.TimeChanged
let genTimeChangedToNight =
ArbMap.defaults
|> ArbMap.generate<DateTime>
|> Gen.filter (not << isDay)
|> Gen.map Interaction.TimeChanged