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.Foreign as Ring
6import qualified Streamly.Prelude as S
8import Prelude hiding (sum, maximum, minimum)
15 describe moduleName $ do
18 testCaseChunk = [9007199254740992, 1, 1.0 :: Double,
19 9007199254740992, 1, 1, 1, 9007199254740992]
20 testCase = take numElem $ cycle testCaseChunk
23 let c = S.fromList testCase
24 a <- runIO $ S.fold (Ring.slidingWindow winSize f) c
25 b <- runIO $ S.fold f $ S.drop (numElem - winSize)
28 it ("should not deviate more than " ++ show deviationLimit)
29 $ c1 >= -1 * deviationLimit && c1 <= deviationLimit
31 describe "Sum" $ testFunc sum
32 describe "mean" $ testFunc mean
34 describe "Correctness" $ do
36 testCase1 = [31, 41, 59, 26, 53, 58, 97] :: [Double]
37 testCase2 = replicate 5 1.0 ++ [7.0]
39 testFunc tc f sI sW = do
41 a <- runIO $ S.toList $ S.postscan f $ S.map (, Nothing) c
42 b <- runIO $ S.toList $ S.postscan
43 (Ring.slidingWindow winSize f) c
44 it "Infinite" $ a == sI
45 it ("Finite " ++ show winSize) $ b == sW
47 describe "minimum" $ do
48 let scanInf = [31, 31, 31, 26, 26, 26, 26] :: [Double]
49 scanWin = [31, 31, 31, 26, 26, 26, 53] :: [Double]
50 testFunc testCase1 minimum scanInf scanWin
51 describe "maximum" $ do
52 let scanInf = [31, 41, 59, 59, 59, 59, 97] :: [Double]
53 scanWin = [31, 41, 59, 59, 59, 58, 97] :: [Double]
54 testFunc testCase1 maximum scanInf scanWin
56 let scanInf = [0, 10, 28, 33, 33, 33, 71] :: [Double]
57 scanWin = [0, 10, 28, 33, 33, 32, 44] :: [Double]
58 testFunc testCase1 range scanInf scanWin
60 let scanInf = [1, 2, 3, 4, 5, 12] :: [Double]
61 scanWin = [1, 2, 3, 3, 3, 9] :: [Double]
62 testFunc testCase2 sum scanInf scanWin
64 let scanInf = [1, 1, 1, 1, 1, 2] :: [Double]
65 scanWin = [1, 1, 1, 1, 1, 3] :: [Double]
66 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