1module Streamly.Test.Data.Fold.Window (main) where
3import Streamly.Internal.Data.Fold.Window
4import Test.Hspec (hspec, describe, it, runIO)
5import qualified Streamly.Internal.Data.Ring.Unboxed as Ring
6import qualified Streamly.Internal.Data.Stream as S
7import qualified Streamly.Internal.Data.Fold as Fold
9import Prelude hiding (sum, maximum, minimum)
16 describe moduleName $ do
19 testCaseChunk = [9007199254740992, 1, 1.0 :: Double,
20 9007199254740992, 1, 1, 1, 9007199254740992]
21 testCase = take numElem $ cycle testCaseChunk
24 let c = S.fromList testCase
25 a <- runIO $ S.fold (Ring.slidingWindow winSize f) c
26 b <- runIO $ S.fold f $ S.drop (numElem - winSize)
29 it ("should not deviate more than " ++ show deviationLimit)
30 $ c1 >= -1 * deviationLimit && c1 <= deviationLimit
32 describe "Sum" $ testFunc sum
33 describe "mean" $ testFunc mean
35 describe "Correctness" $ do
38 [1.0, 4.0, 3.0, 2.1, -5.1, -2.0, 7.0, 3.0, -2.5] :: [Double]
40 testCase2 = replicate 5 1.0 ++ [7.0]
42 testFunc tc f sI sW = do
44 a <- runIO $ S.fold Fold.toList $ S.postscan f $ fmap (, Nothing) c
45 b <- runIO $ S.fold Fold.toList $ S.postscan
46 (Ring.slidingWindow winSize f) c
47 it "Infinite" $ a == sI
48 it ("Finite " ++ show winSize) $ b == sW
50 testFunc2 tc expec f = do
52 a <- runIO $ S.fold (f winSize) c
53 it (show tc) $ a == expec
55 describe "minimum" $ do
56 testFunc2 testCase1 (Just (-2.5)) minimum
57 describe "maximum" $ do
58 testFunc2 testCase1 (Just 7.0) maximum
60 testFunc2 testCase1 (Just (-2.5, 7.0)) range
62 let scanInf = [1, 2, 3, 4, 5, 12] :: [Double]
63 scanWin = [1, 2, 3, 3, 3, 9] :: [Double]
64 testFunc testCase2 sum scanInf scanWin
66 let scanInf = [1, 1, 1, 1, 1, 2] :: [Double]
67 scanWin = [1, 1, 1, 1, 1, 3] :: [Double]
68 testFunc testCase2 mean scanInf scanWin
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list