Add tests for colors
This commit is contained in:
parent
7125fee28e
commit
48aaabde3b
2 changed files with 45 additions and 9 deletions
|
|
@ -1,16 +1,29 @@
|
|||
namespace NightLight.Core.Tests
|
||||
|
||||
open System
|
||||
open FsCheck.Xunit
|
||||
open FsCheck.FSharp
|
||||
|
||||
[<Properties(Arbitrary = [| typeof<Arbitraries> |])>]
|
||||
type NightLightTests() =
|
||||
[<Property>]
|
||||
let ``Brightness should always be under 255`` (fakeHome: FakeHome) (interactions: Interaction list) =
|
||||
interactions |> Seq.iter (fun interaction -> fakeHome.Interact interaction)
|
||||
let ``Brightness should always be under 255`` (now: DateTime) (interactions: Interaction list) =
|
||||
let fakeHome = FakeHome now
|
||||
fakeHome.Interact interactions
|
||||
fakeHome.ForAllLightsThatAreOn(fun (_, brightness, _) -> brightness < 255uy)
|
||||
|
||||
fakeHome.LightStates
|
||||
|> Seq.choose (fun (_, state) ->
|
||||
match state with
|
||||
| On(brightness, _) -> Some brightness
|
||||
| Off -> None)
|
||||
|> Seq.forall (fun brightness -> brightness < 255uy)
|
||||
[<Property>]
|
||||
let ``Lights should be red during the night`` (now: DateTime) (interactions: Interaction list) =
|
||||
let fakeHome = FakeHome now
|
||||
fakeHome.Interact interactions
|
||||
|
||||
fakeHome.IsNight()
|
||||
==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = Red)
|
||||
|
||||
[<Property>]
|
||||
let ``Lights should be white or yellow during the day`` (now: DateTime) (interactions: Interaction list) =
|
||||
let fakeHome = FakeHome now
|
||||
fakeHome.Interact interactions
|
||||
|
||||
fakeHome.IsDay()
|
||||
==> fakeHome.ForAllLightsThatAreOn(fun (_, _, color) -> color = White || color = Yellow)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue