on master help sign in
remove prefix test from test function names
03ee5efShruti_Umat
.travis.yml+1−1
@@ -208,7 +208,7 @@ matrix:
208 # --------------------------------------------------------------------------
208 # --------------------------------------------------------------------------
209
209
210 - name: "GHC 8.10.1+inspection+Werror+coverage"
210 - name: "GHC 8.10.1+inspection+Werror+coverage"
211− env: BUILD=cabal-v2 COVERALLS_OPTIONS=" --repo-token=\"$REPO_TOKEN\" --coverage-mode=StrictlyFullLines --exclude-dir=test" CABAL_PROJECT="cabal.project.coverage" GHC_OPTIONS=""
211+ env: BUILD=cabal-v2 COVERALLS_OPTIONS=" --repo-token=9ezA743hCAcmzX3Ic273LhNlIXVdl7D1l --coverage-mode=StrictlyFullLines --exclude-dir=test" CABAL_PROJECT="cabal.project.coverage" GHC_OPTIONS=""
212 addons: {apt: {packages: [cabal-install-3.2,ghc-8.10.1], sources: [hvr-ghc]}}
212 addons: {apt: {packages: [cabal-install-3.2,ghc-8.10.1], sources: [hvr-ghc]}}
213
213
214 # --------------------------------------------------------------------------
214 # --------------------------------------------------------------------------
test/Streamly/Test/Internal/Data/Fold.hs+111−101
@@ -1,6 +1,7 @@
1module Main (main) where
1module Main (main) where
2
2
3+import Prelude hiding (maximum, minimum, elem, notElem, null, product, sum, head, last)
3−import Streamly.Internal.Data.Fold
4+import qualified Streamly.Internal.Data.Fold as F
4import qualified Streamly.Prelude as S
5import qualified Streamly.Prelude as S
5import qualified Streamly.Data.Fold as FL
6import qualified Streamly.Data.Fold as FL
6
7
@@ -22,33 +23,33 @@ intMax = maxBound
22{-# INLINE intMin #-}
23{-# INLINE intMin #-}
23{-# INLINE intMax #-}
24{-# INLINE intMax #-}
24
25
25−testRollingHashFirstN :: Property
26+rollingHashFirstN :: Property
26−testRollingHashFirstN =
27+rollingHashFirstN =
27 forAll (choose (0, maxStreamLen)) $ \len ->
28 forAll (choose (0, maxStreamLen)) $ \len ->
28 forAll (choose (0, len)) $ \n ->
29 forAll (choose (0, len)) $ \n ->
29 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
30 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
30− a <- run $ S.fold rollingHash $ S.take n $ S.fromList vec
31+ a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
31− b <- run $ S.fold (rollingHashFirstN n) $ S.fromList vec
32+ b <- run $ S.fold (F.rollingHashFirstN n) $ S.fromList vec
32 assert $ a == b
33 assert $ a == b
33
34
34
35
35−testHead :: [Int] -> Expectation
36+head :: [Int] -> Expectation
36−testHead ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
37+head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
37 where
38 where
38 headl [] = Nothing
39 headl [] = Nothing
39 headl (x:_) = Just x
40 headl (x:_) = Just x
40
41
41
42
42−testLength :: [Int] -> Expectation
43+length :: [Int] -> Expectation
43−testLength ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
44+length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
44
45
45
46
46−testSum :: [Int] -> Expectation
47+sum :: [Int] -> Expectation
47−testSum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` foldl (+) 0 ls
48+sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` foldl (+) 0 ls
48
49
49
50
50−testProduct :: [Int] -> Expectation
51+product :: [Int] -> Expectation
51−testProduct ls = S.fold FL.product (S.fromList ls) `shouldReturn` foldl (*) 1 ls
52+product ls = S.fold FL.product (S.fromList ls) `shouldReturn` foldl (*) 1 ls
52
53
53
54
54lesser :: (a -> a -> Ordering) -> a -> a -> a
55lesser :: (a -> a -> Ordering) -> a -> a -> a
@@ -60,29 +61,30 @@ greater f x y = if f x y == GT then x else y
60
61
61
62
62foldMaybe :: (b -> a -> b) -> b -> [a] -> Maybe b
63foldMaybe :: (b -> a -> b) -> b -> [a] -> Maybe b
63−foldMaybe f acc ls = case ls of
64+foldMaybe f acc ls =
65+ case ls of
64− [] -> Nothing
66+ [] -> Nothing
65− _ -> Just (foldl f acc ls)
67+ _ -> Just (foldl f acc ls)
66
68
67
69
68−testMaximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
70+maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
69−testMaximumBy genmin f ls = S.fold (FL.maximumBy f) (S.fromList ls) `shouldReturn` foldMaybe (greater f) genmin ls
71+maximumBy genmin f ls = S.fold (FL.maximumBy f) (S.fromList ls) `shouldReturn` foldMaybe (greater f) genmin ls
70
72
71
73
72−testMaximum :: (Show a, Ord a) => a -> [a] -> Expectation
74+maximum :: (Show a, Ord a) => a -> [a] -> Expectation
73−testMaximum genmin ls = S.fold FL.maximum (S.fromList ls) `shouldReturn` foldMaybe (greater compare) genmin ls
75+maximum genmin ls = S.fold FL.maximum (S.fromList ls) `shouldReturn` foldMaybe (greater compare) genmin ls
74
76
75
77
76−testMinimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
78+minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
77−testMinimumBy genmax f ls = S.fold (FL.minimumBy f) (S.fromList ls) `shouldReturn` foldMaybe (lesser f) genmax ls
79+minimumBy genmax f ls = S.fold (FL.minimumBy f) (S.fromList ls) `shouldReturn` foldMaybe (lesser f) genmax ls
78
80
79
81
80−testMinimum :: (Show a, Ord a) => a -> [a] -> Expectation
82+minimum :: (Show a, Ord a) => a -> [a] -> Expectation
81−testMinimum genmax ls = S.fold FL.minimum (S.fromList ls) `shouldReturn` foldMaybe (lesser compare) genmax ls
83+minimum genmax ls = S.fold FL.minimum (S.fromList ls) `shouldReturn` foldMaybe (lesser compare) genmax ls
82
84
83
85
84−testToList :: [Int] -> Expectation
86+toList :: [Int] -> Expectation
85−testToList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
87+toList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
86
88
87
89
88safeLast :: [a] -> Maybe a
90safeLast :: [a] -> Maybe a
@@ -91,8 +93,8 @@ safeLast (x:[]) = Just x
91safeLast (_:xs) = safeLast xs
93safeLast (_:xs) = safeLast xs
92
94
93
95
94−testLast :: [String] -> Expectation
96+last :: [String] -> Expectation
95−testLast ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
97+last ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
96
98
97
99
98nth :: Int -> [a] -> Maybe a
100nth :: Int -> [a] -> Maybe a
@@ -104,102 +106,110 @@ nth idx (x:xs) = if idx == 0
104nth _ [] = Nothing
106nth _ [] = Nothing
105
107
106
108
107−testIndex :: Int -> [String] -> Expectation
109+index :: Int -> [String] -> Expectation
108−testIndex idx ls = let
109− x = S.fold (FL.index idx) (S.fromList ls)
110+index idx ls = let x = S.fold (FL.index idx) (S.fromList ls)
110− in
111− x `shouldReturn` (nth idx ls)
111+ in x `shouldReturn` (nth idx ls)
112
112
113
113
114−testFind :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
114+find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
115−testFind f ls = do
115+find f ls = do
116− let x = S.fold (FL.findIndex f) (S.fromList ls)
116+ let x = S.fold (FL.findIndex f) (S.fromList ls)
117− y <- x
117+ y <- x
118− case y of
118+ case y of
119− Nothing -> S.fold (FL.find f) (S.fromList ls) `shouldReturn` Nothing
119+ Nothing -> S.fold (FL.find f) (S.fromList ls) `shouldReturn` Nothing
120− Just idx -> S.fold (FL.any f) (S.fromList $ take idx ls) `shouldReturn` False
120+ Just idx -> S.fold (FL.any f) (S.fromList $ take idx ls) `shouldReturn` False
121
121
122
122
123neg :: (a -> Bool) -> a -> Bool
123neg :: (a -> Bool) -> a -> Bool
124neg f x = if f x == True then False else True
124neg f x = if f x == True then False else True
125
125
126−testFindIndex :: (a -> Bool) -> [a] -> Expectation
126+findIndex :: (a -> Bool) -> [a] -> Expectation
127−testFindIndex f ls = do
127+findIndex f ls = do
128− let x = S.fold (FL.findIndex f) (S.fromList ls)
128+ let x = S.fold (FL.findIndex f) (S.fromList ls)
129− y <- x
129+ y <- x
130− case y of
130+ case y of
131− Nothing -> S.fold (FL.all $ neg f) (S.fromList ls) `shouldReturn` True
131+ Nothing -> S.fold (FL.all $ neg f) (S.fromList ls) `shouldReturn` True
132− Just idx -> if idx == 0
132+ Just idx -> if idx == 0
133− then S.fold (FL.all f) (S.fromList []) `shouldReturn` True
133+ then S.fold (FL.all f) (S.fromList []) `shouldReturn` True
134− else S.fold (FL.all f) (S.fromList $ (take idx ls)) `shouldReturn` False
134+ else S.fold (FL.all f) (S.fromList $ (take idx ls)) `shouldReturn` False
135
135
136predicate :: Int -> Bool
136predicate :: Int -> Bool
137predicate x = if x * x < 100 then True else False
137predicate x = if x * x < 100 then True else False
138
138
139−testElemIndex :: Int -> [Int] -> Expectation
139+elemIndex :: Int -> [Int] -> Expectation
140−testElemIndex elm ls = do
140+elemIndex elm ls = do
141− let x = S.fold (FL.elemIndex elm) (S.fromList ls)
141+ let x = S.fold (FL.elemIndex elm) (S.fromList ls)
142− y <- x
142+ y <- x
143− case y of
143+ case y of
144+ Nothing -> S.fold (FL.any (\z -> if z == elm
145+ then True
144− Nothing -> S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` False
146+ else False)) (S.fromList ls) `shouldReturn` False
147+ Just idx -> S.fold (FL.any (\z -> if z == elm
148+ then True
145− Just idx -> S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList $ (take idx ls)) `shouldReturn` False
149+ else False)) (S.fromList $ (take idx ls)) `shouldReturn` False
146
150
147−testNull :: [Int] -> Expectation
151+null :: [Int] -> Expectation
148−testNull ls = S.fold FL.null (S.fromList ls) `shouldReturn` case ls of
152+null ls = S.fold FL.null (S.fromList ls) `shouldReturn` case ls of
149− [] -> True
153+ [] -> True
150− _ -> False
154+ _ -> False
151−testElem :: Int -> [Int] -> Expectation
155+elem :: Int -> [Int] -> Expectation
152−testElem elm ls = do
156+elem elm ls = do
153− let x = S.fold (FL.elem elm) (S.fromList ls)
157+ let x = S.fold (FL.elem elm) (S.fromList ls)
154− y <- x
158+ y <- x
159+ S.fold (FL.any (\z -> if z == elm
160+ then True
155− S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` y
161+ else False)) (S.fromList ls) `shouldReturn` y
156
162
157
163
158−testNotElem :: Int -> [Int] -> Expectation
164+notElem :: Int -> [Int] -> Expectation
159−testNotElem elm ls = do
165+notElem elm ls = do
160− let x = S.fold (FL.notElem elm) (S.fromList ls)
166+ let x = S.fold (FL.notElem elm) (S.fromList ls)
161− y <- x
167+ y <- x
168+ S.fold (FL.any (\z -> if z == elm
169+ then True
162− S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` (if y == True then False else True)
170+ else False)) (S.fromList ls) `shouldReturn` (if y == True
171+ then False
172+ else True)
163
173
164
174
165−testAll :: (a -> Bool) -> [a] -> Expectation
175+all :: (a -> Bool) -> [a] -> Expectation
166−testAll f ls = S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.and (map f ls)
176+all f ls = S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.and (map f ls)
167
177
168
178
169−testAny :: (a -> Bool) -> [a] -> Expectation
179+any :: (a -> Bool) -> [a] -> Expectation
170−testAny f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
180+any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
171
181
172
182
173−testAnd :: [Bool] -> Expectation
183+and :: [Bool] -> Expectation
174−testAnd ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
184+and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
175
185
176
186
177−testOr :: [Bool] -> Expectation
187+or :: [Bool] -> Expectation
178−testOr ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
188+or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
179
189
180
190
181main :: IO ()
191main :: IO ()
182main = hspec $
192main = hspec $
183− describe "Fold Tests" $ do
193+ describe "Fold s" $ do
184− prop "testRollingHashFirstN" testRollingHashFirstN
194+ prop "RollingHashFirstN" rollingHashFirstN
185− prop "testIndex" $ testIndex
195+ prop "Index" $ index
186− prop "testHead" testHead
196+ prop "Head" head
187− prop "testLast" testLast
197+ prop "Last" last
188− prop "testLength" testLength
198+ prop "Length" Main.length
189− prop "testSum" testSum
199+ prop "Sum" sum
190− prop "testProduct" testProduct
200+ prop "Product" product
191− prop "testMaximumBy" $ testMaximumBy intMin compare
201+ prop "MaximumBy" $ maximumBy intMin compare
192− prop "testMaximum" $ testMaximum intMin
202+ prop "Maximum" $ maximum intMin
193− prop "testMinimumBy" $ testMinimumBy intMax compare
203+ prop "MinimumBy" $ minimumBy intMax compare
194− prop "testMinimum" $ testMinimum intMax
204+ prop "Minimum" $ minimum intMax
195− prop "testToList" testToList
205+ prop "ToList" toList
196− prop "testFind" $ testFind predicate
206+ prop "Find" $ find predicate
197− prop "testFindIndex" $ testFindIndex predicate
207+ prop "FindIndex" $ findIndex predicate
198− prop "testElemIndex" $ testElemIndex 10
208+ prop "ElemIndex" $ elemIndex 10
199− prop "testNull" testNull
209+ prop "Null" null
200− prop "testElem" $ testElem 10
210+ prop "Elem" $ elem 10
201− prop "testNotElem" $ testNotElem 10
211+ prop "NotElem" $ notElem 10
202− prop "testAll" $ testAll predicate
212+ prop "All" $ Main.all predicate
203− prop "testAny" $ testAny predicate
213+ prop "Any" $ Main.any predicate
204− prop "testAnd" testAnd
214+ prop "And" Main.and
205− prop "testOr" testOr
215+ prop "Or" Main.or