Bias the TimeChanged generator to make alarms more likely
This commit is contained in:
parent
fd7d927775
commit
59a1b1e41d
3 changed files with 26 additions and 4 deletions
|
|
@ -2,10 +2,33 @@ module NightLight.Core.Tests.InteractionListGenerators
|
|||
|
||||
open System
|
||||
open NightLight.Core.Models
|
||||
open NightLight.Core.Tests.InteractionListHelpers
|
||||
open FsCheck.FSharp
|
||||
|
||||
let private genTimeChanged =
|
||||
ArbMap.defaults |> ArbMap.generate<DateTime> |> Gen.map Interaction.TimeChanged
|
||||
let genDate = ArbMap.defaults |> ArbMap.generate<DateTime> |> Gen.map _.Date
|
||||
|
||||
let genTimeSpanBetween (l: TimeSpan) (h: TimeSpan) =
|
||||
Gen.choose (int l.TotalSeconds, int h.TotalSeconds)
|
||||
|> Gen.map int64
|
||||
|> Gen.map TimeSpan.FromSeconds
|
||||
|
||||
let (+) = Gen.map2 (+)
|
||||
|
||||
let genDayBoundaryDateTime =
|
||||
genDate
|
||||
+ Gen.elements [ startOfDay; endOfDay ]
|
||||
+ genTimeSpanBetween (-TimeSpan.FromMinutes 20.0) (TimeSpan.FromMinutes 20.0)
|
||||
|
||||
let genStartOfDayDateTime =
|
||||
genDate
|
||||
+ Gen.constant startOfDay
|
||||
+ genTimeSpanBetween TimeSpan.Zero (TimeSpan.FromMinutes 20.0)
|
||||
|
||||
let genAnyDateTime = ArbMap.defaults |> ArbMap.generate<DateTime>
|
||||
|
||||
Gen.frequency [ 4, genStartOfDayDateTime; 2, genDayBoundaryDateTime; 1, genAnyDateTime ]
|
||||
|> Gen.map Interaction.TimeChanged
|
||||
|
||||
let private genHumanInteraction =
|
||||
Gen.elements lights
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="FakeHome.fs" />
|
||||
<Compile Include="GenHelpers.fs" />
|
||||
<Compile Include="InteractionListGenerators.fs" />
|
||||
<Compile Include="InteractionListHelpers.fs" />
|
||||
<Compile Include="InteractionListGenerators.fs" />
|
||||
<Compile Include="LightArbitraries.fs" />
|
||||
<Compile Include="NightLightTests.fs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ type NightLightTests() =
|
|||
|> Prop.label fakeHome.Label
|
||||
|> Prop.trivial (fakeHome.LightsThatAreOn.Length = 0)
|
||||
|
||||
// TODO: Bias generator for alarm cases so that `MaxTest` can be reduced
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |], MaxTest = 10_000)>]
|
||||
[<Property(Arbitrary = [| typeof<ArbitraryInteractions> |])>]
|
||||
let ``All lights should either be off or have a brightness that fits its color`` (interactions: Interaction list) =
|
||||
let fakeHome = createFakeHomeWithNightLightAndInteract interactions
|
||||
let time = getTimeAfterInteractions interactions |> _.TimeOfDay
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue