-
Notifications
You must be signed in to change notification settings - Fork 1
/
TotalSpec.hs
95 lines (83 loc) · 2.82 KB
/
TotalSpec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{-# LANGUAGE ScopedTypeVariables #-}
module TauSigma.Statistics.TotalSpec where
import qualified Data.Vector.Unboxed as U
import Pipes
import TauSigma.Statistics.Total (totdevs, (!*))
import TauSigma.Statistics.SlopeTest
import TauSigma.Util.Pipes.Noise
( whitePhase
, flickerPhase
, whiteFrequency
, flickerFrequency
, randomWalkFrequency
, toPhase
, octaves
)
import Test.Hspec (Spec, describe, it)
import Test.QuickCheck (property)
spec :: Spec
spec = do
describe "reflection" $
it "A reflected time sequence is defined correctly at all of its range" $
property prop_reflection
describe "totdev" (mapM_ slopeTest totdevCases)
prop_reflection :: Int -> Bool
prop_reflection size = map (xs!*) xs' == xs'
where xs :: U.Vector Int
xs = U.generate size id
xs' :: [Int]
xs' = [2 - size .. 2*size - 3]
totdevCases :: [TestCase]
totdevCases =
[ TestCase { name = "wpm"
, description = "Slope of white phase noise ~ -1.0"
, samples = sampleSize
, taus = (10, 20)
, expected = (-1.0)
, tolerance = 0.1
, statistic = totdevs 1
, noise = wpm
}
, TestCase { name = "fpm"
, description = "Slope of flicker phase noise ~ -1.0"
, samples = sampleSize
, taus = (10, 20)
, expected = (-1.0)
, tolerance = 0.18
, statistic = totdevs 1
, noise = fpm
}
, TestCase { name = "wfm"
, description = "Slope of white frequency noise ~ -0.5"
, samples = sampleSize
, taus = (10, 20)
, expected = (-0.5)
, tolerance = 0.05
, statistic = totdevs 1
, noise = wfm
}
, TestCase { name = "ffm"
, description = "Slope of flicker frequency noise ~ 0.0"
, samples = sampleSize
, taus = (10, 20)
, expected = (0.0)
, tolerance = 0.055
, statistic = totdevs 1
, noise = ffm
}
, TestCase { name = "rwfm"
, description = "Slope of random walk frequency noise ~ 0.5"
, samples = sampleSize
, taus = (10, 20)
, expected = (0.5)
, tolerance = 0.05
, statistic = totdevs 1
, noise = rwfm
}
]
where sampleSize = 200000
wpm = whitePhase 1.0
fpm = flickerPhase (octaves sampleSize) 1.0
wfm = whiteFrequency 1.0 >-> toPhase
ffm = flickerFrequency (octaves sampleSize) 1.0 >-> toPhase
rwfm = randomWalkFrequency 1.0 >-> toPhase