on master help sign in
Add tests for take, takeEQ, takeGE with n <= 0.
f38b672pranaysashank
src/Streamly/Internal/Data/Parser/ParserD.hs+3−1
@@ -334,10 +334,12 @@ take n (Fold fstep finitial fextract) = Parser step initial extract
334--
334--
335{-# INLINE takeEQ #-}
335{-# INLINE takeEQ #-}
336takeEQ :: MonadThrow m => Int -> Fold m a b -> Parser m a b
336takeEQ :: MonadThrow m => Int -> Fold m a b -> Parser m a b
337−takeEQ n (Fold fstep finitial fextract) = Parser step initial extract
337+takeEQ cnt (Fold fstep finitial fextract) = Parser step initial extract
338
338
339 where
339 where
340
340
341+ n = max cnt 0
342+
341 initial = Tuple' 0 <$> finitial
343 initial = Tuple' 0 <$> finitial
342
344
343 step (Tuple' i r) a
345 step (Tuple' i r) a
test/Streamly/Test/Internal/Data/Parser.hs+36−3
@@ -6,9 +6,11 @@ import qualified Streamly.Internal.Data.Fold as FL
6
6
7-- import Data.List (partition)
7-- import Data.List (partition)
8
8
9−import Test.Hspec(hspec, describe)
9+import Test.Hspec(Spec, hspec, describe)
10+import qualified Test.Hspec as H
10import Test.Hspec.QuickCheck
11import Test.Hspec.QuickCheck
12+import Test.QuickCheck (arbitrary, forAll, choose, elements, Property,
11−import Test.QuickCheck (forAll, choose, Property, property, listOf, vectorOf, counterexample, Gen)
13+ property, listOf, vectorOf, counterexample, Gen)
12
14
13import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
15import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
14import Control.Exception (SomeException(..), displayException)
16import Control.Exception (SomeException(..), displayException)
@@ -16,6 +18,9 @@ import Control.Monad.IO.Class (MonadIO(..))
16import Control.Monad (when)
18import Control.Monad (when)
17import Data.List ((\\))
19import Data.List ((\\))
18
20
21+maxTestCount :: Int
22+maxTestCount = 100
23+
19min_value :: Int
24min_value :: Int
20min_value = 0
25min_value = 0
21
26
@@ -227,6 +232,30 @@ takeGE =
227 property False
232 property False
228 Left _ -> property (n > list_length)
233 Left _ -> property (n > list_length)
229
234
235+nLessThanEqual0 ::
236+ ( Int
237+ -> FL.Fold (Either SomeException) Int [Int]
238+ -> P.Parser (Either SomeException) Int [Int]
239+ )
240+ -> (Int -> [Int] -> [Int])
241+ -> Property
242+nLessThanEqual0 tk ltk =
243+ forAll (elements [0, (-1)]) $ \n ->
244+ forAll (listOf arbitrary) $ \ls ->
245+ case S.parse (tk n FL.toList) (S.fromList ls) of
246+ Right parsed_list -> checkListEqual parsed_list (ltk n ls)
247+ Left _ -> property False
248+
249+takeProperties :: Spec
250+takeProperties =
251+ describe "take combinators when n <= 0/" $ do
252+ prop "take n FL.toList = []" $
253+ nLessThanEqual0 P.take (\_ -> const [])
254+ prop "takeEQ n FL.toList = []" $
255+ nLessThanEqual0 P.takeEQ (\_ -> const [])
256+ prop "takeGE n FL.toList xs = xs" $
257+ nLessThanEqual0 P.takeGE (\_ -> id)
258+
230-- lookAheadPass :: Property
259-- lookAheadPass :: Property
231-- lookAheadPass =
260-- lookAheadPass =
232-- forAll (chooseInt (min_value + 1, max_value)) $ \n ->
261-- forAll (chooseInt (min_value + 1, max_value)) $ \n ->
@@ -422,7 +451,10 @@ sliceSepBy =
422-- Left _ -> True)
451-- Left _ -> True)
423
452
424main :: IO ()
453main :: IO ()
454+main =
425−main = hspec $ do
455+ hspec $
456+ H.parallel $
457+ modifyMaxSuccess (const maxTestCount) $ do
426 describe "test for accumulator" $ do
458 describe "test for accumulator" $ do
427 prop "P.fromFold FL.sum = FL.sum" fromFold
459 prop "P.fromFold FL.sum = FL.sum" fromFold
428 prop "P.any = Prelude.any" Main.any
460 prop "P.any = Prelude.any" Main.any
@@ -467,3 +499,4 @@ main = hspec $ do
467 -- prop "left fail test for shortest function" shortestFailLeft
499 -- prop "left fail test for shortest function" shortestFailLeft
468 -- prop "right fail test for shortest function" shortestFailRight
500 -- prop "right fail test for shortest function" shortestFailRight
469 -- prop "both fail test for shortest function" shortestFailBoth
501 -- prop "both fail test for shortest function" shortestFailBoth
502+ takeProperties
test/Streamly/Test/Internal/Data/Parser/ParserD.hs+135−114
@@ -1,20 +1,27 @@
1module Main (main) where
1module Main (main) where
2
2
3−import qualified Streamly.Internal.Data.Parser.ParserD as D
3+import qualified Streamly.Internal.Data.Parser.ParserD as P
4import qualified Streamly.Internal.Prelude as S
4import qualified Streamly.Internal.Prelude as S
5import qualified Streamly.Internal.Data.Fold as FL
5import qualified Streamly.Internal.Data.Fold as FL
6
6
7-- import Data.List (partition)
7-- import Data.List (partition)
8
8
9−import Test.Hspec(hspec, describe)
9+import Test.Hspec(Spec, hspec, describe)
10+import qualified Test.Hspec as H
10import Test.Hspec.QuickCheck
11import Test.Hspec.QuickCheck
12+import Test.QuickCheck (arbitrary, forAll, choose, elements, Property,
11−import Test.QuickCheck (forAll, choose, Property, property, listOf, vectorOf, counterexample, (.&&.), Gen)
13+ property, listOf, vectorOf, counterexample,
14+ (.&&.), Gen)
12
15
13import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
16import Test.QuickCheck.Monadic (monadicIO, PropertyM, assert, monitor)
17+import Control.Exception (SomeException(..))
14import Control.Monad.IO.Class (MonadIO(..))
18import Control.Monad.IO.Class (MonadIO(..))
15import Control.Monad (when)
19import Control.Monad (when)
16import Data.List ((\\))
20import Data.List ((\\))
17
21
22+maxTestCount :: Int
23+maxTestCount = 100
24+
18min_value :: Int
25min_value :: Int
19min_value = 0
26min_value = 0
20
27
@@ -56,59 +63,59 @@ chooseInt = choose
56fromFold :: Property
63fromFold :: Property
57fromFold =
64fromFold =
58 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
65 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
59− case (==) <$> (S.parseD (D.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
66+ case (==) <$> (S.parseD (P.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
60 Right is_equal -> is_equal
67 Right is_equal -> is_equal
61 Left _ -> False
68 Left _ -> False
62
69
63any :: Property
70any :: Property
64any =
71any =
65 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
72 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
66− case S.parseD (D.any (> mid_value)) (S.fromList ls) of
73+ case S.parseD (P.any (> mid_value)) (S.fromList ls) of
67 Right r -> r == (Prelude.any (> mid_value) ls)
74 Right r -> r == (Prelude.any (> mid_value) ls)
68 Left _ -> False
75 Left _ -> False
69
76
70all :: Property
77all :: Property
71all =
78all =
72 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
79 forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
73− case S.parseD (D.all (> mid_value)) (S.fromList ls) of
80+ case S.parseD (P.all (> mid_value)) (S.fromList ls) of
74 Right r -> r == (Prelude.all (> mid_value) ls)
81 Right r -> r == (Prelude.all (> mid_value) ls)
75 Left _ -> False
82 Left _ -> False
76
83
77yield :: Property
84yield :: Property
78−yield =
85+yield =
79 forAll (chooseInt (min_value, max_value)) $ \x ->
86 forAll (chooseInt (min_value, max_value)) $ \x ->
80− case S.parseD (D.yield x) (S.fromList [1 :: Int]) of
87+ case S.parseD (P.yield x) (S.fromList [1 :: Int]) of
81 Right r -> r == x
88 Right r -> r == x
82 Left _ -> False
89 Left _ -> False
83
90
84yieldM :: Property
91yieldM :: Property
85yieldM =
92yieldM =
86 forAll (chooseInt (min_value, max_value)) $ \x ->
93 forAll (chooseInt (min_value, max_value)) $ \x ->
87− case S.parseD (D.yieldM $ return x) (S.fromList [1 :: Int]) of
94+ case S.parseD (P.yieldM $ return x) (S.fromList [1 :: Int]) of
88 Right r -> r == x
95 Right r -> r == x
89 Left _ -> False
96 Left _ -> False
90
97
91die :: Property
98die :: Property
92die =
99die =
93 property $
100 property $
94− case S.parseD (D.die "die test") (S.fromList [0 :: Int]) of
101+ case S.parseD (P.die "die test") (S.fromList [0 :: Int]) of
95 Right _ -> False
102 Right _ -> False
96 Left _ -> True
103 Left _ -> True
97
104
98dieM :: Property
105dieM :: Property
99dieM =
106dieM =
100 property $
107 property $
101− case S.parseD (D.dieM (Right "die test")) (S.fromList [0 :: Int]) of
108+ case S.parseD (P.dieM (Right "die test")) (S.fromList [0 :: Int]) of
102 Right _ -> False
109 Right _ -> False
103 Left _ -> True
110 Left _ -> True
104
111
105-- Element Parser Tests
112-- Element Parser Tests
106
113
107peekPass :: Property
114peekPass :: Property
108−peekPass =
115+peekPass =
109 forAll (chooseInt (1, max_length)) $ \list_length ->
116 forAll (chooseInt (1, max_length)) $ \list_length ->
110 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
117 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
111− case S.parseD D.peek (S.fromList ls) of
118+ case S.parseD P.peek (S.fromList ls) of
112 Right head_value -> case ls of
119 Right head_value -> case ls of
113 head_ls : _ -> head_value == head_ls
120 head_ls : _ -> head_value == head_ls
114 _ -> False
121 _ -> False
@@ -116,40 +123,40 @@ peekPass =
116
123
117peekFail :: Property
124peekFail :: Property
118peekFail =
125peekFail =
119− property (case S.parseD D.peek (S.fromList []) of
126+ property (case S.parseD P.peek (S.fromList []) of
120 Right _ -> False
127 Right _ -> False
121 Left _ -> True)
128 Left _ -> True)
122
129
123eofPass :: Property
130eofPass :: Property
124−eofPass =
131+eofPass =
125− property (case S.parseD D.eof (S.fromList []) of
132+ property (case S.parseD P.eof (S.fromList []) of
126 Right _ -> True
133 Right _ -> True
127 Left _ -> False)
134 Left _ -> False)
128
135
129eofFail :: Property
136eofFail :: Property
130−eofFail =
137+eofFail =
131 forAll (chooseInt (1, max_length)) $ \list_length ->
138 forAll (chooseInt (1, max_length)) $ \list_length ->
132 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
139 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
133− case S.parseD D.eof (S.fromList ls) of
140+ case S.parseD P.eof (S.fromList ls) of
134 Right _ -> False
141 Right _ -> False
135 Left _ -> True
142 Left _ -> True
136
143
137satisfyPass :: Property
144satisfyPass :: Property
138−satisfyPass =
145+satisfyPass =
139 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
146 forAll (chooseInt (mid_value, max_value)) $ \first_element ->
140 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
147 forAll (listOf (chooseInt (min_value, max_value))) $ \ls_tail ->
141 let
148 let
142 ls = first_element : ls_tail
149 ls = first_element : ls_tail
143 predicate = (>= mid_value)
150 predicate = (>= mid_value)
144 in
151 in
145− case S.parseD (D.satisfy predicate) (S.fromList ls) of
152+ case S.parseD (P.satisfy predicate) (S.fromList ls) of
146 Right r -> r == first_element
153 Right r -> r == first_element
147 Left _ -> False
154 Left _ -> False
148
155
149satisfy :: Property
156satisfy :: Property
150−satisfy =
157+satisfy =
151 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
158 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
152− case S.parseD (D.satisfy predicate) (S.fromList ls) of
159+ case S.parseD (P.satisfy predicate) (S.fromList ls) of
153 Right r -> case ls of
160 Right r -> case ls of
154 [] -> False
161 [] -> False
155 (x : _) -> predicate x && (r == x)
162 (x : _) -> predicate x && (r == x)
@@ -162,19 +169,19 @@ satisfy =
162-- Sequence Parsers Tests
169-- Sequence Parsers Tests
163
170
164take :: Property
171take :: Property
165−take =
172+take =
166 forAll (chooseInt (min_value, max_value)) $ \n ->
173 forAll (chooseInt (min_value, max_value)) $ \n ->
167 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
174 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
168− case S.parseD (D.take n FL.toList) (S.fromList ls) of
175+ case S.parseD (P.take n FL.toList) (S.fromList ls) of
169 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
176 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
170 Left _ -> property False
177 Left _ -> property False
171
178
172takeEQPass :: Property
179takeEQPass :: Property
173−takeEQPass =
180+takeEQPass =
174 forAll (chooseInt (min_value, max_value)) $ \n ->
181 forAll (chooseInt (min_value, max_value)) $ \n ->
175 forAll (chooseInt (n, max_value)) $ \list_length ->
182 forAll (chooseInt (n, max_value)) $ \list_length ->
176 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
183 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
177− case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
184+ case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
178 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
185 Right parsed_list -> checkListEqual parsed_list (Prelude.take n ls)
179 Left _ -> property False
186 Left _ -> property False
180
187
@@ -182,11 +189,11 @@ takeEQ :: Property
182takeEQ =
189takeEQ =
183 forAll (chooseInt (min_value, max_value)) $ \n ->
190 forAll (chooseInt (min_value, max_value)) $ \n ->
184 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
191 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
185− let
192+ let
186 list_length = Prelude.length ls
193 list_length = Prelude.length ls
187 in
194 in
188− case S.parseD (D.takeEQ n FL.toList) (S.fromList ls) of
195+ case S.parseD (P.takeEQ n FL.toList) (S.fromList ls) of
189− Right parsed_list ->
196+ Right parsed_list ->
190 if (n <= list_length) then
197 if (n <= list_length) then
191 checkListEqual parsed_list (Prelude.take n ls)
198 checkListEqual parsed_list (Prelude.take n ls)
192 else
199 else
@@ -194,11 +201,11 @@ takeEQ =
194 Left _ -> property (n > list_length)
201 Left _ -> property (n > list_length)
195
202
196takeGEPass :: Property
203takeGEPass :: Property
197−takeGEPass =
204+takeGEPass =
198 forAll (chooseInt (min_value, max_value)) $ \n ->
205 forAll (chooseInt (min_value, max_value)) $ \n ->
199 forAll (chooseInt (n, max_value)) $ \list_length ->
206 forAll (chooseInt (n, max_value)) $ \list_length ->
200 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
207 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
201− case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
208+ case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
202 Right parsed_list -> checkListEqual parsed_list ls
209 Right parsed_list -> checkListEqual parsed_list ls
203 Left _ -> property False
210 Left _ -> property False
204
211
@@ -206,54 +213,65 @@ takeGE :: Property
206takeGE =
213takeGE =
207 forAll (chooseInt (min_value, max_value)) $ \n ->
214 forAll (chooseInt (min_value, max_value)) $ \n ->
208 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
215 forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
209− let
216+ let
210 list_length = Prelude.length ls
217 list_length = Prelude.length ls
211 in
218 in
212− case S.parseD (D.takeGE n FL.toList) (S.fromList ls) of
219+ case S.parseD (P.takeGE n FL.toList) (S.fromList ls) of
213− Right parsed_list ->
220+ Right parsed_list ->
214 if (n <= list_length) then
221 if (n <= list_length) then
215 checkListEqual parsed_list ls
222 checkListEqual parsed_list ls
216 else
223 else
217 property False
224 property False
218 Left _ -> property (n > list_length)
225 Left _ -> property (n > list_length)
219
226
227+nLessThanEqual0 ::
228+ ( Int
229+ -> FL.Fold (Either SomeException) Int [Int]
230+ -> P.Parser (Either SomeException) Int [Int]
231+ )
232+ -> (Int -> [Int] -> [Int])
233+ -> Property
234+nLessThanEqual0 tk ltk =
235+ forAll (elements [0, (-1)]) $ \n ->
236+ forAll (listOf arbitrary) $ \ls ->
237+ case S.parseD (tk n FL.toList) (S.fromList ls) of
238+ Right parsed_list -> checkListEqual parsed_list (ltk n ls)
239+ Left _ -> property False
240+
241+takeProperties :: Spec
242+takeProperties =
243+ describe "take combinators when n <= 0/" $ do
244+ prop "take n FL.toList = []" $
245+ nLessThanEqual0 P.take (\_ -> const [])
246+ prop "takeEQ n FL.toList = []" $
247+ nLessThanEqual0 P.takeEQ (\_ -> const [])
248+ prop "takeGE n FL.toList xs = xs" $
249+ nLessThanEqual0 P.takeGE (\_ -> id)
250+
251+
252+-- XXX lookAhead can't deal with EOF which in this case means when
253+-- n==list_length, this test will fail. So excluding that case for now.
220lookAheadPass :: Property
254lookAheadPass :: Property
221lookAheadPass =
255lookAheadPass =
222− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
256+ forAll (chooseInt (min_value, max_value)) $ \n ->
223 let
257 let
224− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
258+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
225 parseTwice = do
259 parseTwice = do
226 parsed_list_1 <- takeWithoutConsume
260 parsed_list_1 <- takeWithoutConsume
227 parsed_list_2 <- takeWithoutConsume
261 parsed_list_2 <- takeWithoutConsume
228 return (parsed_list_1, parsed_list_2)
262 return (parsed_list_1, parsed_list_2)
229 in
263 in
230− forAll (chooseInt (n, max_value)) $ \list_length ->
264+ forAll (chooseInt (n+1, max_value)) $ \list_length ->
231 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
265 forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
232 case S.parseD parseTwice (S.fromList ls) of
266 case S.parseD parseTwice (S.fromList ls) of
233 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
267 Right (ls_1, ls_2) -> checkListEqual ls_1 ls_2 .&&. checkListEqual ls_1 (Prelude.take n ls)
234 Left _ -> property $ False
268 Left _ -> property $ False
235
269
236−lookAheadFail :: Property
237−lookAheadFail =
238− forAll (chooseInt (min_value + 1, max_value)) $ \n ->
239− let
240− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
241− parseTwice = do
242− parsed_list_1 <- takeWithoutConsume
243− parsed_list_2 <- takeWithoutConsume
244− return (parsed_list_1, parsed_list_2)
245− in
246− forAll (chooseInt (min_value, n - 1)) $ \list_length ->
247− forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
248− case S.parseD parseTwice (S.fromList ls) of
249− Right _ -> False
250− Left _ -> True
251−
252lookAhead :: Property
270lookAhead :: Property
253lookAhead =
271lookAhead =
254− forAll (chooseInt (min_value, max_value)) $ \n ->
272+ forAll (chooseInt (min_value, max_value)) $ \n ->
255 let
273 let
256− takeWithoutConsume = D.lookAhead $ D.take n FL.toList
274+ takeWithoutConsume = P.lookAhead $ P.take n FL.toList
257 parseTwice = do
275 parseTwice = do
258 parsed_list_1 <- takeWithoutConsume
276 parsed_list_1 <- takeWithoutConsume
259 parsed_list_2 <- takeWithoutConsume
277 parsed_list_2 <- takeWithoutConsume
@@ -269,7 +287,7 @@ lookAhead =
269takeWhile :: Property
287takeWhile :: Property
270takeWhile =
288takeWhile =
271 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
289 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
272− case S.parseD (D.takeWhile predicate FL.toList) (S.fromList ls) of
290+ case S.parseD (P.takeWhile predicate FL.toList) (S.fromList ls) of
273 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
291 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile predicate ls)
274 Left _ -> property False
292 Left _ -> property False
275 where
293 where
@@ -278,10 +296,10 @@ takeWhile =
278takeWhile1 :: Property
296takeWhile1 :: Property
279takeWhile1 =
297takeWhile1 =
280 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
298 forAll (listOf (chooseInt (0, 1))) $ \ ls ->
281− case S.parseD (D.takeWhile1 predicate FL.toList) (S.fromList ls) of
299+ case S.parseD (P.takeWhile1 predicate FL.toList) (S.fromList ls) of
282 Right parsed_list -> case ls of
300 Right parsed_list -> case ls of
283 [] -> property False
301 [] -> property False
284− (x : _) ->
302+ (x : _) ->
285 if predicate x then
303 if predicate x then
286 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
304 checkListEqual parsed_list (Prelude.takeWhile predicate ls)
287 else
305 else
@@ -291,21 +309,21 @@ takeWhile1 =
291 (x : _) -> property (not $ predicate x)
309 (x : _) -> property (not $ predicate x)
292 where
310 where
293 predicate = (== 0)
311 predicate = (== 0)
294−
312+
295sliceSepBy :: Property
313sliceSepBy :: Property
296sliceSepBy =
314sliceSepBy =
297 forAll (listOf (chooseInt (0, 1))) $ \ls ->
315 forAll (listOf (chooseInt (0, 1))) $ \ls ->
298− case S.parseD (D.sliceSepBy predicate FL.toList) (S.fromList ls) of
316+ case S.parseD (P.sliceSepBy predicate FL.toList) (S.fromList ls) of
299 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
317 Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile (not . predicate) ls)
300 Left _ -> property False
318 Left _ -> property False
301 where
319 where
302 predicate = (== 1)
320 predicate = (== 1)
303
321
304sliceSepByMax :: Property
322sliceSepByMax :: Property
305−sliceSepByMax =
323+sliceSepByMax =
306 forAll (chooseInt (min_value, max_value)) $ \n ->
324 forAll (chooseInt (min_value, max_value)) $ \n ->
307 forAll (listOf (chooseInt (0, 1))) $ \ls ->
325 forAll (listOf (chooseInt (0, 1))) $ \ls ->
308− case S.parseD (D.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
326+ case S.parseD (P.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
309 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
327 Right parsed_list -> checkListEqual parsed_list (Prelude.take n (Prelude.takeWhile (not . predicate) ls))
310 Left _ -> property False
328 Left _ -> property False
311 where
329 where
@@ -314,7 +332,7 @@ sliceSepByMax =
314splitWith :: Property
332splitWith :: Property
315splitWith =
333splitWith =
316 forAll (listOf (chooseInt (0, 1))) $ \ls ->
334 forAll (listOf (chooseInt (0, 1))) $ \ls ->
317− case S.parseD (D.splitWith (,) (D.satisfy (== 0)) (D.satisfy (== 1))) (S.fromList ls) of
335+ case S.parseD (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
318 Right (result_first, result_second) -> case ls of
336 Right (result_first, result_second) -> case ls of
319 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
337 0 : 1 : _ -> (result_first == 0) && (result_second == 1)
320 _ -> False
338 _ -> False
@@ -324,48 +342,48 @@ splitWith =
324
342
325splitWithFailLeft :: Property
343splitWithFailLeft :: Property
326splitWithFailLeft =
344splitWithFailLeft =
327− property (case S.parseD (D.splitWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
345+ property (case S.parseD (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
328 Right _ -> False
346 Right _ -> False
329 Left _ -> True)
347 Left _ -> True)
330
348
331splitWithFailRight :: Property
349splitWithFailRight :: Property
332splitWithFailRight =
350splitWithFailRight =
333− property (case S.parseD (D.splitWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
351+ property (case S.parseD (P.splitWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
334 Right _ -> False
352 Right _ -> False
335 Left _ -> True)
353 Left _ -> True)
336
354
337splitWithFailBoth :: Property
355splitWithFailBoth :: Property
338splitWithFailBoth =
356splitWithFailBoth =
339− property (case S.parseD (D.splitWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
357+ property (case S.parseD (P.splitWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
340 Right _ -> False
358 Right _ -> False
341 Left _ -> True)
359 Left _ -> True)
342
360
343teeWithPass :: Property
361teeWithPass :: Property
344−teeWithPass =
362+teeWithPass =
345 forAll (chooseInt (min_value, max_value)) $ \n ->
363 forAll (chooseInt (min_value, max_value)) $ \n ->
346 forAll (listOf (chooseInt (0, 1))) $ \ls ->
364 forAll (listOf (chooseInt (0, 1))) $ \ls ->
347 let
365 let
348− prsr = D.take n FL.toList
366+ prsr = P.take n FL.toList
349 in
367 in
350− case S.parseD (D.teeWith (,) prsr prsr) (S.fromList ls) of
368+ case S.parseD (P.teeWith (,) prsr prsr) (S.fromList ls) of
351 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
369 Right (ls_1, ls_2) -> checkListEqual (Prelude.take n ls) ls_1 .&&. checkListEqual ls_1 ls_2
352 Left _ -> property False
370 Left _ -> property False
353
371
354teeWithFailLeft :: Property
372teeWithFailLeft :: Property
355−teeWithFailLeft =
373+teeWithFailLeft =
356− property (case S.parseD (D.teeWith (,) (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
374+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
357 Right _ -> False
375 Right _ -> False
358 Left _ -> True)
376 Left _ -> True)
359
377
360teeWithFailRight :: Property
378teeWithFailRight :: Property
361−teeWithFailRight =
379+teeWithFailRight =
362− property (case S.parseD (D.teeWith (,) (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
380+ property (case S.parseD (P.teeWith (,) (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
363 Right _ -> False
381 Right _ -> False
364 Left _ -> True)
382 Left _ -> True)
365
383
366teeWithFailBoth :: Property
384teeWithFailBoth :: Property
367−teeWithFailBoth =
385+teeWithFailBoth =
368− property (case S.parseD (D.teeWith (,) (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
386+ property (case S.parseD (P.teeWith (,) (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
369 Right _ -> False
387 Right _ -> False
370 Left _ -> True)
388 Left _ -> True)
371
389
@@ -374,9 +392,9 @@ shortestPass =
374 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
392 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
375 let
393 let
376 half_mid_value = mid_value `Prelude.div` 2
394 half_mid_value = mid_value `Prelude.div` 2
377− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
395+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
378− prsr_2 = D.takeWhile (<= mid_value) FL.toList
396+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
379− prsr_shortest = D.shortest prsr_1 prsr_2
397+ prsr_shortest = P.shortest prsr_1 prsr_2
380 in
398 in
381 case S.parseD prsr_shortest (S.fromList ls) of
399 case S.parseD prsr_shortest (S.fromList ls) of
382 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
400 Right short_list -> checkListEqual short_list (Prelude.takeWhile (<= half_mid_value) ls)
@@ -384,19 +402,19 @@ shortestPass =
384
402
385shortestPassLeft :: Property
403shortestPassLeft :: Property
386shortestPassLeft =
404shortestPassLeft =
387− property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
405+ property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
388 Right r -> r == 1
406 Right r -> r == 1
389 Left _ -> False)
407 Left _ -> False)
390
408
391shortestPassRight :: Property
409shortestPassRight :: Property
392shortestPassRight =
410shortestPassRight =
393− property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
411+ property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
394 Right r -> r == 1
412 Right r -> r == 1
395 Left _ -> False)
413 Left _ -> False)
396
414
397shortestFailBoth :: Property
415shortestFailBoth :: Property
398shortestFailBoth =
416shortestFailBoth =
399− property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
417+ property (case S.parseD (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
400 Right _ -> False
418 Right _ -> False
401 Left _ -> True)
419 Left _ -> True)
402
420
@@ -405,9 +423,9 @@ longestPass =
405 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
423 forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
406 let
424 let
407 half_mid_value = mid_value `Prelude.div` 2
425 half_mid_value = mid_value `Prelude.div` 2
408− prsr_1 = D.takeWhile (<= half_mid_value) FL.toList
426+ prsr_1 = P.takeWhile (<= half_mid_value) FL.toList
409− prsr_2 = D.takeWhile (<= mid_value) FL.toList
427+ prsr_2 = P.takeWhile (<= mid_value) FL.toList
410− prsr_longest = D.longest prsr_1 prsr_2
428+ prsr_longest = P.longest prsr_1 prsr_2
411 in
429 in
412 case S.parseD prsr_longest (S.fromList ls) of
430 case S.parseD prsr_longest (S.fromList ls) of
413 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
431 Right long_list -> long_list == Prelude.takeWhile (<= mid_value) ls
@@ -415,67 +433,70 @@ longestPass =
415
433
416longestPassLeft :: Property
434longestPassLeft :: Property
417longestPassLeft =
435longestPassLeft =
418− property (case S.parseD (D.shortest (D.die "die") (D.yield (1 :: Int))) (S.fromList [1 :: Int]) of
436+ property (case S.parseD (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
419 Right r -> r == 1
437 Right r -> r == 1
420 Left _ -> False)
438 Left _ -> False)
421
439
422longestPassRight :: Property
440longestPassRight :: Property
423longestPassRight =
441longestPassRight =
424− property (case S.parseD (D.shortest (D.yield (1 :: Int)) (D.die "die")) (S.fromList [1 :: Int]) of
442+ property (case S.parseD (P.shortest (P.yield (1 :: Int)) (P.die "die")) (S.fromList [1 :: Int]) of
425 Right r -> r == 1
443 Right r -> r == 1
426 Left _ -> False)
444 Left _ -> False)
427
445
428longestFailBoth :: Property
446longestFailBoth :: Property
429longestFailBoth =
447longestFailBoth =
430− property (case S.parseD (D.shortest (D.die "die") (D.die "die")) (S.fromList [1 :: Int]) of
448+ property (case S.parseD (P.shortest (P.die "die") (P.die "die")) (S.fromList [1 :: Int]) of
431 Right _ -> False
449 Right _ -> False
432 Left _ -> True)
450 Left _ -> True)
433
451
434many :: Property
452many :: Property
435−many =
453+many =
436 forAll (listOf (chooseInt (0, 1))) $ \ls ->
454 forAll (listOf (chooseInt (0, 1))) $ \ls ->
437 let
455 let
438 concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
456 concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
439− prsr = D.many concatFold $ D.sliceSepBy (== 1) FL.toList
457+ prsr = P.many concatFold $ P.sliceSepBy (== 1) FL.toList
440 in
458 in
441 case S.parseD prsr (S.fromList ls) of
459 case S.parseD prsr (S.fromList ls) of
442 Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
460 Right res_list -> checkListEqual res_list (Prelude.filter (== 0) ls)
443 Left _ -> property False
461 Left _ -> property False
444
462
445many_empty :: Property
463many_empty :: Property
446−many_empty =
464+many_empty =
447− property (case S.parseD (D.many FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
465+ property (case S.parseD (P.many FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
448 Right res_list -> checkListEqual res_list ([] :: [Int])
466 Right res_list -> checkListEqual res_list ([] :: [Int])
449 Left _ -> property False)
467 Left _ -> property False)
450
468
451-- some :: Property
469-- some :: Property
452−-- some =
470+-- some =
453-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
471-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
454-- let
472-- let
455-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
473-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
456−-- prsr = D.some concatFold $ D.sliceSepBy (== 1) FL.toList
474+-- prsr = P.some concatFold $ P.sliceSepBy (== 1) FL.toList
457-- in
475-- in
458-- case S.parseD prsr (S.fromList ls) of
476-- case S.parseD prsr (S.fromList ls) of
459-- Right res_list -> res_list == Prelude.filter (== 0) ls
477-- Right res_list -> res_list == Prelude.filter (== 0) ls
460-- Left _ -> False
478-- Left _ -> False
461
479
462-- someFail :: Property
480-- someFail :: Property
463−-- someFail =
481+-- someFail =
464−-- property (case S.parseD (D.some FL.toList (D.die "die")) (S.fromList [1 :: Int]) of
482+-- property (case S.parseD (P.some FL.toList (P.die "die")) (S.fromList [1 :: Int]) of
465-- Right _ -> False
483-- Right _ -> False
466-- Left _ -> True)
484-- Left _ -> True)
467
485
468main :: IO ()
486main :: IO ()
487+main =
469−main = hspec $ do
488+ hspec $
489+ H.parallel $
490+ modifyMaxSuccess (const maxTestCount) $ do
470 describe "test for accumulator" $ do
491 describe "test for accumulator" $ do
471− prop "D.fromFold FL.sum = FL.sum" fromFold
492+ prop "P.fromFold FL.sum = FL.sum" fromFold
472− prop "D.any = Prelude.any" Main.any
493+ prop "P.any = Prelude.any" Main.any
473− prop "D.all = Prelude.all" Main.all
494+ prop "P.all = Prelude.all" Main.all
474 prop "yield value provided" yield
495 prop "yield value provided" yield
475 prop "yield monadic value provided" yieldM
496 prop "yield monadic value provided" yieldM
476 prop "always fail" die
497 prop "always fail" die
477 prop "always fail but monadic" dieM
498 prop "always fail but monadic" dieM
478−
499+
479 describe "test for element parser" $ do
500 describe "test for element parser" $ do
480 prop "peek = head with list length > 0" peekPass
501 prop "peek = head with list length > 0" peekPass
481 prop "peek fail on []" peekFail
502 prop "peek fail on []" peekFail
@@ -485,18 +506,17 @@ main = hspec $ do
485 prop "check first element exists and satisfies predicate" satisfy
506 prop "check first element exists and satisfies predicate" satisfy
486
507
487 describe "test for sequence parser" $ do
508 describe "test for sequence parser" $ do
488− prop "D.take = Prelude.take" Main.take
509+ prop "P.take = Prelude.take" Main.take
489− prop "D.takeEQ = Prelude.take when len >= n" takeEQPass
510+ prop "P.takeEQ = Prelude.take when len >= n" takeEQPass
490− prop "D.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
511+ prop "P.takeEQ = Prelude.take when len >= n and fail otherwise" Main.takeEQ
491− prop "D.takeGE n ls = ls when len >= n" takeGEPass
512+ prop "P.takeGE n ls = ls when len >= n" takeGEPass
492− prop "D.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
513+ prop "P.takeGE n ls = ls when len >= n and fail otherwise" Main.takeGE
493 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
514 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
494− prop "Fail when stream length exceeded" lookAheadFail
495 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
515 prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
496− prop "D.takeWhile = Prelude.takeWhile" Main.takeWhile
516+ prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
497− prop "D.takeWhile = Prelude.takeWhile if taken something, else check why failed" takeWhile1
517+ prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
498− prop "D.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
518+ prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
499− prop "D.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
519+ prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
500 prop "parse 0, then 1, else fail" splitWith
520 prop "parse 0, then 1, else fail" splitWith
501 prop "fail due to die as left parser" splitWithFailLeft
521 prop "fail due to die as left parser" splitWithFailLeft
502 prop "fail due to die as right parser" splitWithFailRight
522 prop "fail due to die as right parser" splitWithFailRight
@@ -505,15 +525,16 @@ main = hspec $ do
505 prop "fail due to die as left parser" teeWithFailLeft
525 prop "fail due to die as left parser" teeWithFailLeft
506 prop "fail due to die as right parser" teeWithFailRight
526 prop "fail due to die as right parser" teeWithFailRight
507 prop "fail due to die as both parsers" teeWithFailBoth
527 prop "fail due to die as both parsers" teeWithFailBoth
508− prop "D.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
528+ prop "P.takeWhile (<= half_mid_value) = Prelude.takeWhile half_mid_value" shortestPass
509 prop "pass even if die is left parser" shortestPassLeft
529 prop "pass even if die is left parser" shortestPassLeft
510 prop "pass even if die is right parser" shortestPassRight
530 prop "pass even if die is right parser" shortestPassRight
511 prop "fail due to die as both parsers" shortestFailBoth
531 prop "fail due to die as both parsers" shortestFailBoth
512− prop "D.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
532+ prop "P.takeWhile (<= mid_value) = Prelude.takeWhile (<= mid_value)" longestPass
513 prop "pass even if die is left parser" longestPassLeft
533 prop "pass even if die is left parser" longestPassLeft
514 prop "pass even if die is right parser" longestPassRight
534 prop "pass even if die is right parser" longestPassRight
515 prop "fail due to die as both parsers" longestFailBoth
535 prop "fail due to die as both parsers" longestFailBoth
516− prop "D.many concatFold $ D.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
536+ prop "P.many concatFold $ P.sliceSepBy (== 1) FL.toList = Prelude.filter (== 0)" many
517 prop "[] due to parser being die" many_empty
537 prop "[] due to parser being die" many_empty
518 -- prop "" some
538 -- prop "" some
519− -- prop "fail due to parser being die" someFail
539+ -- prop "fail due to parser being die" someFail
540+ takeProperties