Get rid of arbitraries that are only used once
This commit is contained in:
parent
7472825140
commit
bb528e9942
5 changed files with 40 additions and 40 deletions
|
|
@ -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
|
|
||||||
|
|
@ -44,6 +44,3 @@ let genInteractionListContaining containingInteraction afterFilter =
|
||||||
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
|
Gen.frequency [ 1, genTrivialList; 9, genNonTrivialList ]
|
||||||
| _ -> genNonTrivialList
|
| _ -> genNonTrivialList
|
||||||
}
|
}
|
||||||
|
|
||||||
let genInteractionListThatEndsAtTime time =
|
|
||||||
genInteractionListContaining (Interaction.TimeChanged time) (not << _.IsTimeChanged)
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="FakeHome.fs" />
|
<Compile Include="FakeHome.fs" />
|
||||||
<Compile Include="InteractionListGenerators.fs" />
|
<Compile Include="InteractionListGenerators.fs" />
|
||||||
<Compile Include="ArbitraryInteractionLists.fs" />
|
<Compile Include="TimeChangedGenerators.fs" />
|
||||||
<Compile Include="NightLightTests.fs" />
|
<Compile Include="NightLightTests.fs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
namespace NightLight.Core.Tests
|
namespace NightLight.Core.Tests
|
||||||
|
|
||||||
open NightLight.Core.Core
|
open NightLight.Core.Core
|
||||||
open NightLight.Core.Tests.ArbitraryInteractionLists
|
open NightLight.Core.Tests.TimeChangedGenerators
|
||||||
open NightLight.Core.Tests.InteractionListGenerators
|
open NightLight.Core.Tests.InteractionListGenerators
|
||||||
open FsCheck
|
|
||||||
open FsCheck.Xunit
|
open FsCheck.Xunit
|
||||||
open FsCheck.FSharp
|
open FsCheck.FSharp
|
||||||
|
|
||||||
|
|
@ -24,15 +23,25 @@ type NightLightTests() =
|
||||||
|
|
||||||
fakeHome
|
fakeHome
|
||||||
|
|
||||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractionListThatEndsDuringTheDay> |])>]
|
[<Property>]
|
||||||
let ``All lights that are on should be white or yellow during the day`` (interactions: Interaction list) =
|
let ``All lights that are on should be white or yellow during the day`` () =
|
||||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
genTimeChangedToDay
|
||||||
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)
|
|> 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> |])>]
|
[<Property>]
|
||||||
let ``All lights that are on should be red during the night`` (interactions: Interaction list) =
|
let ``All lights that are on should be red during the night`` () =
|
||||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
genTimeChangedToNight
|
||||||
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
|
|> Gen.bind (fun timeChangedToNight -> genInteractionListContaining timeChangedToNight (not << _.IsTimeChanged))
|
||||||
|
|> Arb.fromGen
|
||||||
|
|> Prop.forAll
|
||||||
|
<| fun interactions ->
|
||||||
|
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||||
|
fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
|
||||||
|
|
||||||
[<Property>]
|
[<Property>]
|
||||||
let ``After pressing 'Off' on the remote, the remotely controlled lights should stay off until 'On' is pressed again``
|
let ``After pressing 'Off' on the remote, the remotely controlled lights should stay off until 'On' is pressed again``
|
||||||
|
|
|
||||||
20
NightLight.Core.Tests/TimeChangedGenerators.fs
Normal file
20
NightLight.Core.Tests/TimeChangedGenerators.fs
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue