on master help sign in
remove prefix test from test function names

fix indentation change repo token for travis build fix do block indentation

commit03ee5ef784eff9b3fcf8aa7f909132d7a1525a39 authorShruti_Umat <111701027@smail.iitpkd.ac.in> dateFri 5 Jun 2020, 23:07 (6 years ago) parent374668f
2 files changed+112−102
.travis.yml+1−1 test/Streamly/Test/Internal/Data/Fold.hs+111−101
.travis.yml+1−1
@@ -208,7 +208,7 @@ matrix:
208208 # --------------------------------------------------------------------------
209209
210210 - 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=""
212212 addons: {apt: {packages: [cabal-install-3.2,ghc-8.10.1], sources: [hvr-ghc]}}
213213
214214 # --------------------------------------------------------------------------
test/Streamly/Test/Internal/Data/Fold.hs+111−101
@@ -1,6 +1,7 @@
11module Main (main) where
22
3−import Streamly.Internal.Data.Fold
3+import Prelude hiding (maximum, minimum, elem, notElem, null, product, sum, head, last)
4+import qualified Streamly.Internal.Data.Fold as F
45import qualified Streamly.Prelude as S
56import qualified Streamly.Data.Fold as FL
67
@@ -22,33 +23,33 @@ intMax = maxBound
2223{-# INLINE intMin #-}
2324{-# INLINE intMax #-}
2425
25−testRollingHashFirstN :: Property
26−testRollingHashFirstN =
26+rollingHashFirstN :: Property
27+rollingHashFirstN =
2728 forAll (choose (0, maxStreamLen)) $ \len ->
2829 forAll (choose (0, len)) $ \n ->
2930 forAll (vectorOf len (arbitrary :: Gen Int)) $ \vec -> monadicIO $ do
30− a <- run $ S.fold rollingHash $ S.take n $ S.fromList vec
31− b <- run $ S.fold (rollingHashFirstN n) $ S.fromList vec
31+ a <- run $ S.fold F.rollingHash $ S.take n $ S.fromList vec
32+ b <- run $ S.fold (F.rollingHashFirstN n) $ S.fromList vec
3233 assert $ a == b
3334
3435
35−testHead :: [Int] -> Expectation
36−testHead ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
36+head :: [Int] -> Expectation
37+head ls = S.fold FL.head (S.fromList ls) `shouldReturn` headl ls
3738 where
3839 headl [] = Nothing
3940 headl (x:_) = Just x
4041
4142
42−testLength :: [Int] -> Expectation
43−testLength ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
43+length :: [Int] -> Expectation
44+length ls = S.fold FL.length (S.fromList ls) `shouldReturn` Prelude.length ls
4445
4546
46−testSum :: [Int] -> Expectation
47−testSum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` foldl (+) 0 ls
47+sum :: [Int] -> Expectation
48+sum ls = S.fold FL.sum (S.fromList ls) `shouldReturn` foldl (+) 0 ls
4849
4950
50−testProduct :: [Int] -> Expectation
51−testProduct ls = S.fold FL.product (S.fromList ls) `shouldReturn` foldl (*) 1 ls
51+product :: [Int] -> Expectation
52+product ls = S.fold FL.product (S.fromList ls) `shouldReturn` foldl (*) 1 ls
5253
5354
5455lesser :: (a -> a -> Ordering) -> a -> a -> a
@@ -60,29 +61,30 @@ greater f x y = if f x y == GT then x else y
6061
6162
6263foldMaybe :: (b -> a -> b) -> b -> [a] -> Maybe b
63−foldMaybe f acc ls = case ls of
64− [] -> Nothing
65− _ -> Just (foldl f acc ls)
64+foldMaybe f acc ls =
65+ case ls of
66+ [] -> Nothing
67+ _ -> Just (foldl f acc ls)
6668
6769
68−testMaximumBy :: (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
70+maximumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
71+maximumBy genmin f ls = S.fold (FL.maximumBy f) (S.fromList ls) `shouldReturn` foldMaybe (greater f) genmin ls
7072
7173
72−testMaximum :: (Show a, Ord a) => a -> [a] -> Expectation
73−testMaximum genmin ls = S.fold FL.maximum (S.fromList ls) `shouldReturn` foldMaybe (greater compare) genmin ls
74+maximum :: (Show a, Ord a) => a -> [a] -> Expectation
75+maximum genmin ls = S.fold FL.maximum (S.fromList ls) `shouldReturn` foldMaybe (greater compare) genmin ls
7476
7577
76−testMinimumBy :: (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
78+minimumBy :: (Ord a, Show a) => a -> (a -> a -> Ordering) -> [a] -> Expectation
79+minimumBy genmax f ls = S.fold (FL.minimumBy f) (S.fromList ls) `shouldReturn` foldMaybe (lesser f) genmax ls
7880
7981
80−testMinimum :: (Show a, Ord a) => a -> [a] -> Expectation
81−testMinimum genmax ls = S.fold FL.minimum (S.fromList ls) `shouldReturn` foldMaybe (lesser compare) genmax ls
82+minimum :: (Show a, Ord a) => a -> [a] -> Expectation
83+minimum genmax ls = S.fold FL.minimum (S.fromList ls) `shouldReturn` foldMaybe (lesser compare) genmax ls
8284
8385
84−testToList :: [Int] -> Expectation
85−testToList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
86+toList :: [Int] -> Expectation
87+toList ls = S.fold FL.toList (S.fromList ls) `shouldReturn` ls
8688
8789
8890safeLast :: [a] -> Maybe a
@@ -91,8 +93,8 @@ safeLast (x:[]) = Just x
9193safeLast (_:xs) = safeLast xs
9294
9395
94−testLast :: [String] -> Expectation
95−testLast ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
96+last :: [String] -> Expectation
97+last ls = S.fold FL.last (S.fromList ls) `shouldReturn` safeLast ls
9698
9799
98100nth :: Int -> [a] -> Maybe a
@@ -104,102 +106,110 @@ nth idx (x:xs) = if idx == 0
104106nth _ [] = Nothing
105107
106108
107−testIndex :: Int -> [String] -> Expectation
108−testIndex idx ls = let
109− x = S.fold (FL.index idx) (S.fromList ls)
110− in
111− x `shouldReturn` (nth idx ls)
109+index :: Int -> [String] -> Expectation
110+index idx ls = let x = S.fold (FL.index idx) (S.fromList ls)
111+ in x `shouldReturn` (nth idx ls)
112112
113113
114−testFind :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
115−testFind f ls = do
116− let x = S.fold (FL.findIndex f) (S.fromList ls)
117− y <- x
118− case y of
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
114+find :: (Show a, Eq a) => (a -> Bool) -> [a] -> Expectation
115+find f ls = do
116+ let x = S.fold (FL.findIndex f) (S.fromList ls)
117+ y <- x
118+ case y of
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
121121
122122
123123neg :: (a -> Bool) -> a -> Bool
124124neg f x = if f x == True then False else True
125125
126−testFindIndex :: (a -> Bool) -> [a] -> Expectation
127−testFindIndex f ls = do
128− let x = S.fold (FL.findIndex f) (S.fromList ls)
129− y <- x
130− case y of
131− Nothing -> S.fold (FL.all $ neg f) (S.fromList ls) `shouldReturn` True
132− Just idx -> if idx == 0
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
126+findIndex :: (a -> Bool) -> [a] -> Expectation
127+findIndex f ls = do
128+ let x = S.fold (FL.findIndex f) (S.fromList ls)
129+ y <- x
130+ case y of
131+ Nothing -> S.fold (FL.all $ neg f) (S.fromList ls) `shouldReturn` True
132+ Just idx -> if idx == 0
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
135135
136136predicate :: Int -> Bool
137137predicate x = if x * x < 100 then True else False
138138
139−testElemIndex :: Int -> [Int] -> Expectation
140−testElemIndex elm ls = do
141− let x = S.fold (FL.elemIndex elm) (S.fromList ls)
142− y <- x
143− case y of
144− Nothing -> S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` False
145− Just idx -> S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList $ (take idx ls)) `shouldReturn` False
139+elemIndex :: Int -> [Int] -> Expectation
140+elemIndex elm ls = do
141+ let x = S.fold (FL.elemIndex elm) (S.fromList ls)
142+ y <- x
143+ case y of
144+ Nothing -> S.fold (FL.any (\z -> if z == elm
145+ then True
146+ else False)) (S.fromList ls) `shouldReturn` False
147+ Just idx -> S.fold (FL.any (\z -> if z == elm
148+ then True
149+ else False)) (S.fromList $ (take idx ls)) `shouldReturn` False
146150
147−testNull :: [Int] -> Expectation
148−testNull ls = S.fold FL.null (S.fromList ls) `shouldReturn` case ls of
149− [] -> True
150− _ -> False
151−testElem :: Int -> [Int] -> Expectation
152−testElem elm ls = do
153− let x = S.fold (FL.elem elm) (S.fromList ls)
154− y <- x
155− S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` y
151+null :: [Int] -> Expectation
152+null ls = S.fold FL.null (S.fromList ls) `shouldReturn` case ls of
153+ [] -> True
154+ _ -> False
155+elem :: Int -> [Int] -> Expectation
156+elem elm ls = do
157+ let x = S.fold (FL.elem elm) (S.fromList ls)
158+ y <- x
159+ S.fold (FL.any (\z -> if z == elm
160+ then True
161+ else False)) (S.fromList ls) `shouldReturn` y
156162
157163
158−testNotElem :: Int -> [Int] -> Expectation
159−testNotElem elm ls = do
160− let x = S.fold (FL.notElem elm) (S.fromList ls)
161− y <- x
162− S.fold (FL.any (\z -> if z == elm then True else False)) (S.fromList ls) `shouldReturn` (if y == True then False else True)
164+notElem :: Int -> [Int] -> Expectation
165+notElem elm ls = do
166+ let x = S.fold (FL.notElem elm) (S.fromList ls)
167+ y <- x
168+ S.fold (FL.any (\z -> if z == elm
169+ then True
170+ else False)) (S.fromList ls) `shouldReturn` (if y == True
171+ then False
172+ else True)
163173
164174
165−testAll :: (a -> Bool) -> [a] -> Expectation
166−testAll f ls = S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.and (map f ls)
175+all :: (a -> Bool) -> [a] -> Expectation
176+all f ls = S.fold (FL.all f) (S.fromList ls) `shouldReturn` Prelude.and (map f ls)
167177
168178
169−testAny :: (a -> Bool) -> [a] -> Expectation
170−testAny f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
179+any :: (a -> Bool) -> [a] -> Expectation
180+any f ls = S.fold (FL.any f) (S.fromList ls) `shouldReturn` Prelude.any f ls
171181
172182
173−testAnd :: [Bool] -> Expectation
174−testAnd ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
183+and :: [Bool] -> Expectation
184+and ls = S.fold FL.and (S.fromList ls) `shouldReturn` Prelude.and ls
175185
176186
177−testOr :: [Bool] -> Expectation
178−testOr ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
187+or :: [Bool] -> Expectation
188+or ls = S.fold FL.or (S.fromList ls) `shouldReturn` Prelude.or ls
179189
180190
181191main :: IO ()
182192main = hspec $
183− describe "Fold Tests" $ do
184− prop "testRollingHashFirstN" testRollingHashFirstN
185− prop "testIndex" $ testIndex
186− prop "testHead" testHead
187− prop "testLast" testLast
188− prop "testLength" testLength
189− prop "testSum" testSum
190− prop "testProduct" testProduct
191− prop "testMaximumBy" $ testMaximumBy intMin compare
192− prop "testMaximum" $ testMaximum intMin
193− prop "testMinimumBy" $ testMinimumBy intMax compare
194− prop "testMinimum" $ testMinimum intMax
195− prop "testToList" testToList
196− prop "testFind" $ testFind predicate
197− prop "testFindIndex" $ testFindIndex predicate
198− prop "testElemIndex" $ testElemIndex 10
199− prop "testNull" testNull
200− prop "testElem" $ testElem 10
201− prop "testNotElem" $ testNotElem 10
202− prop "testAll" $ testAll predicate
203− prop "testAny" $ testAny predicate
204− prop "testAnd" testAnd
205− prop "testOr" testOr
193+ describe "Fold s" $ do
194+ prop "RollingHashFirstN" rollingHashFirstN
195+ prop "Index" $ index
196+ prop "Head" head
197+ prop "Last" last
198+ prop "Length" Main.length
199+ prop "Sum" sum
200+ prop "Product" product
201+ prop "MaximumBy" $ maximumBy intMin compare
202+ prop "Maximum" $ maximum intMin
203+ prop "MinimumBy" $ minimumBy intMax compare
204+ prop "Minimum" $ minimum intMax
205+ prop "ToList" toList
206+ prop "Find" $ find predicate
207+ prop "FindIndex" $ findIndex predicate
208+ prop "ElemIndex" $ elemIndex 10
209+ prop "Null" null
210+ prop "Elem" $ elem 10
211+ prop "NotElem" $ notElem 10
212+ prop "All" $ Main.all predicate
213+ prop "Any" $ Main.any predicate
214+ prop "And" Main.and
215+ prop "Or" Main.or