Explicit state
This commit is contained in:
@@ -72,7 +72,6 @@ spec = describe "AFRP" $ do
|
||||
lMergeSpec
|
||||
changesSpec
|
||||
edgeSpec
|
||||
dropFirstSpec
|
||||
filterASpec
|
||||
slidingSpec
|
||||
mapAccumSpec
|
||||
@@ -81,7 +80,6 @@ spec = describe "AFRP" $ do
|
||||
delayEventSpec
|
||||
debounceSpec
|
||||
rollupSpec
|
||||
fixedSpec
|
||||
effSpec
|
||||
switchSpec
|
||||
mapAccumRequestSpec
|
||||
@@ -211,19 +209,6 @@ edgeSpec = describe "edge" $ do
|
||||
else o' === Tick
|
||||
_ -> failure
|
||||
|
||||
dropFirstSpec :: Spec
|
||||
dropFirstSpec = describe "dropFirst" $ do
|
||||
it "drops the first Event, passes the rest" $
|
||||
runPure dropFirst [Tick, Event 1, Event 2, Event 3]
|
||||
`shouldBe` [Tick, Tick, Event 2, Event 3 :: Event Int]
|
||||
|
||||
it "passes Tick through untouched before first Event" $
|
||||
runPure dropFirst [Tick, Tick, Tick :: Event Int]
|
||||
`shouldBe` [Tick, Tick, Tick :: Event Int]
|
||||
|
||||
it "drops only the first Event, Ticks before it are inert" $
|
||||
runPure dropFirst [Tick, Tick, Event 'a', Tick, Event 'b']
|
||||
`shouldBe` [Tick, Tick, Tick, Tick, Event 'b' :: Event Char]
|
||||
|
||||
filterASpec :: Spec
|
||||
filterASpec = describe "filterA" $ do
|
||||
@@ -407,36 +392,6 @@ rollupSpec = describe "rollup" $ do
|
||||
emitted = concat [xs | Event xs <- out]
|
||||
sort emitted === sort [x | Event x <- evs]
|
||||
|
||||
fixedSpec :: Spec
|
||||
fixedSpec = describe "fixed" $ do
|
||||
it "accumulates events within a window and rolls over on expiry" $
|
||||
runTimed (fixed 10)
|
||||
[ (0, Event 'a'), (1, Event 'b'), (2, Tick)
|
||||
, (12, Event 'c'), (13, Tick)
|
||||
]
|
||||
`shouldBe` [ ['a'], ['a', 'b'], ['a', 'b']
|
||||
, ['c'], ['c']
|
||||
]
|
||||
|
||||
it "starts a window even on a leading Tick" $
|
||||
runTimed (fixed 10)
|
||||
[ (0, Tick), (1, Event 'a')
|
||||
, (12, Tick), (13, Tick)
|
||||
, (25, Event 'b')
|
||||
]
|
||||
`shouldBe` [ [], ['a'], [], [], ['b'] ]
|
||||
|
||||
it "output is always the current window's accumulated list" $
|
||||
hedgehog $ do
|
||||
w <- forAll $ Gen.int (Range.constant 1 10)
|
||||
evs <- forAll $ Gen.list (Range.linear 0 30) eventGen
|
||||
let out = runTimed (fixed w) (zip [0 ..] evs)
|
||||
expected =
|
||||
[ [ x | Event x <- take (i - lo + 1) (drop lo evs) ]
|
||||
| i <- [0 .. length evs - 1]
|
||||
, let lo = (i `div` w) * w
|
||||
]
|
||||
out === expected
|
||||
|
||||
eventGen :: Gen (Event Char)
|
||||
eventGen = Gen.frequency
|
||||
|
||||
+3
-1
@@ -18,6 +18,7 @@ import Data.Time (UTCTime (..), utc)
|
||||
import Data.UUID (nil)
|
||||
import AFRP (Mealy (..), Pair (..), Request (..))
|
||||
import HomeAssistant.Controller (HASSEff (..), Service)
|
||||
import AFRP (stepAuto)
|
||||
|
||||
fakeRequest :: Request
|
||||
fakeRequest = Request (sec 0) utc nil
|
||||
@@ -51,7 +52,8 @@ interp (Trace _ _) = pure ()
|
||||
runHASS :: Mealy HASSEff a b -> [a] -> [(b, [Service])]
|
||||
runHASS _ [] = []
|
||||
runHASS m (a : as) =
|
||||
case runAcc (runMealy m interp fakeRequest a) [] of
|
||||
let w = runMealy m interp
|
||||
in case runAcc (stepAuto w fakeRequest a) [] of
|
||||
(Pair b m', svcs) -> (b, svcs) : runHASS m' as
|
||||
|
||||
services :: [(b, [Service])] -> [[Service]]
|
||||
|
||||
Reference in New Issue
Block a user