@@ -10,39 +10,51 @@ import Test.Hspec(hspec, describe)
10import Test.Hspec.QuickCheck
10import Test.Hspec.QuickCheck
11import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
11import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
13-- Accumulator Tests
25-- Accumulator Tests
15fromFold :: Property
27fromFold :: Property
17− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
29+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
18 case (==) <$> (S.parse (P.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
30 case (==) <$> (S.parse (P.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
19 Right is_equal -> is_equal
31 Right is_equal -> is_equal
20 Left _ -> False
32 Left _ -> False
22any :: Property
34any :: Property
24− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
36+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
25− case S.parse (P.any (> 5000)) (S.fromList ls) of
37+ case S.parse (P.any (> mid_value)) (S.fromList ls) of
26− Right r -> r == (Prelude.any (> 5000) ls)
38+ Right r -> r == (Prelude.any (> mid_value) ls)
27 Left _ -> False
39 Left _ -> False
29all :: Property
41all :: Property
31− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
43+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
32− case S.parse (P.all (> 5000)) (S.fromList ls) of
44+ case S.parse (P.all (> mid_value)) (S.fromList ls) of
33− Right r -> r == (Prelude.all (> 5000) ls)
45+ Right r -> r == (Prelude.all (> mid_value) ls)
34 Left _ -> False
46 Left _ -> False
36yield :: Property
48yield :: Property
38− forAll (chooseInt (0, 10000)) $ \x ->
50+ forAll (chooseInt (min_value, max_value)) $ \x ->
39 case S.parse (P.yield x) (S.fromList [1 :: Int]) of
51 case S.parse (P.yield x) (S.fromList [1 :: Int]) of
40 Right r -> r == x
52 Right r -> r == x
41 Left _ -> False
53 Left _ -> False
43yieldM :: Property
55yieldM :: Property
45− forAll (chooseInt (0, 10000)) $ \x ->
57+ forAll (chooseInt (min_value, max_value)) $ \x ->
46 case S.parse (P.yieldM $ return x) (S.fromList [1 :: Int]) of
58 case S.parse (P.yieldM $ return x) (S.fromList [1 :: Int]) of
47 Right r -> r == x
59 Right r -> r == x
48 Left _ -> False
60 Left _ -> False
@@ -63,24 +75,26 @@ dieM =
64-- Element Parser Tests
76-- Element Parser Tests
66−peek :: Property
78+peekPass :: Property
68− forAll (chooseInt (1, 100)) $ \list_length ->
80+ forAll (chooseInt (1, max_length)) $ \list_length ->
69− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
81+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
70 case S.parse P.peek (S.fromList ls) of
82 case S.parse P.peek (S.fromList ls) of
71 Right head_value -> case ls of
83 Right head_value -> case ls of
72 head_ls : _ -> head_value == head_ls
84 head_ls : _ -> head_value == head_ls
73 _ -> False
85 _ -> False
74 Left _ -> False
86 Left _ -> False
76 property (case S.parse P.peek (S.fromList []) of
90 property (case S.parse P.peek (S.fromList []) of
77 Right _ -> False
91 Right _ -> False
78 Left _ -> True)
92 Left _ -> True)
80eof :: Property
94eof :: Property
82− forAll (chooseInt (1, 100)) $ \list_length ->
96+ forAll (chooseInt (1, max_length)) $ \list_length ->
83− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
97+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
84 case S.parse P.eof (S.fromList ls) of
98 case S.parse P.eof (S.fromList ls) of
85 Right _ -> False
99 Right _ -> False
86 Left _ -> True
100 Left _ -> True
@@ -91,7 +105,7 @@ eof =
92satisfy :: Property
106satisfy :: Property
94− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
108+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
95 case S.parse (P.satisfy predicate) (S.fromList ls) of
109 case S.parse (P.satisfy predicate) (S.fromList ls) of
96 Right r -> case ls of
110 Right r -> case ls of
97 [] -> False
111 [] -> False
@@ -100,22 +114,22 @@ satisfy =
100 [] -> True
114 [] -> True
101 (x : _) -> not $ predicate x
115 (x : _) -> not $ predicate x
103− predicate = (>= 5000)
117+ predicate = (>= mid_value)
105-- Sequence Parsers Tests
119-- Sequence Parsers Tests
107take :: Property
121take :: Property
109− forAll (chooseInt (0, 10000)) $ \n ->
123+ forAll (chooseInt (min_value, max_value)) $ \n ->
110− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
124+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
111 case S.parse (P.take n FL.toList) (S.fromList ls) of
125 case S.parse (P.take n FL.toList) (S.fromList ls) of
112 Right parsed_list -> parsed_list == Prelude.take n ls
126 Right parsed_list -> parsed_list == Prelude.take n ls
113 Left _ -> False
127 Left _ -> False
115takeEQ :: Property
129takeEQ :: Property
117− forAll (chooseInt (0, 10000)) $ \n ->
131+ forAll (chooseInt (min_value, max_value)) $ \n ->
118− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
132+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
120 list_length = Prelude.length ls
134 list_length = Prelude.length ls
@@ -125,8 +139,8 @@ takeEQ =
126takeGE :: Property
140takeGE :: Property
128− forAll (chooseInt (0, 10000)) $ \n ->
142+ forAll (chooseInt (min_value, max_value)) $ \n ->
129− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
143+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
131 list_length = Prelude.length ls
145 list_length = Prelude.length ls
@@ -136,7 +150,7 @@ takeGE =
137lookAhead :: Property
151lookAhead :: Property
138lookAhead =
152lookAhead =
139− forAll (chooseInt (0, 10000)) $ \n ->
153+ forAll (chooseInt (min_value, max_value)) $ \n ->
141 takeWithoutConsume = P.lookAhead $ P.take n FL.toList
155 takeWithoutConsume = P.lookAhead $ P.take n FL.toList
142 parseTwice = do
156 parseTwice = do
@@ -144,7 +158,7 @@ lookAhead =
144 parsed_list_2 <- takeWithoutConsume
158 parsed_list_2 <- takeWithoutConsume
145 return (parsed_list_1, parsed_list_2)
159 return (parsed_list_1, parsed_list_2)
147− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
161+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
148 case S.parse parseTwice (S.fromList ls) of
162 case S.parse parseTwice (S.fromList ls) of
149 Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
163 Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
150 Left _ -> (list_length < n) || (list_length == n && n == 0)
164 Left _ -> (list_length < n) || (list_length == n && n == 0)
@@ -184,7 +198,7 @@ sliceSepBy =
185-- sliceSepByMax :: Property
199-- sliceSepByMax :: Property
186-- sliceSepByMax =
200-- sliceSepByMax =
187−-- forAll (chooseInt (0, 10000)) $ \n ->
201+-- forAll (chooseInt (min_value, max_value)) $ \n ->
188-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
202-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
189-- case S.parse (P.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
203-- case S.parse (P.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
190-- Right parsed_list -> parsed_list == Prelude.take n (Prelude.takeWhile (not . predicate) ls)
204-- Right parsed_list -> parsed_list == Prelude.take n (Prelude.takeWhile (not . predicate) ls)
@@ -192,8 +206,8 @@ sliceSepBy =
193-- predicate = (== 1)
207-- predicate = (== 1)
195−-- splitWith :: Property
209+-- splitWithPass :: Property
196−-- splitWith =
210+-- splitWithPass =
197-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
211-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
198-- case S.parse (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
212-- case S.parse (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
199-- Right (result_first, result_second) -> case ls of
213-- Right (result_first, result_second) -> case ls of
@@ -202,7 +216,9 @@ sliceSepBy =
202-- Left _ -> case ls of
216-- Left _ -> case ls of
203-- 0 : 1 : _ -> False
217-- 0 : 1 : _ -> False
204-- _ -> True
218-- _ -> True
220+-- splitWithFail :: Property
206-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
222-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
207-- Right _ -> False
223-- Right _ -> False
208-- Left _ -> True)
224-- Left _ -> True)
@@ -215,8 +231,8 @@ sliceSepBy =
215-- Right _ -> False
231-- Right _ -> False
216-- Left _ -> True)
232-- Left _ -> True)
218−-- teeWith :: Property
234+-- teeWithPass :: Property
219−-- teeWith =
235+-- teeWithPass =
220-- forAll (chooseInt (0, 10000)) $ \n ->
236-- forAll (chooseInt (0, 10000)) $ \n ->
221-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
237-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
@@ -225,7 +241,9 @@ sliceSepBy =
225-- case S.parse (P.teeWith (,) prsr prsr) (S.fromList ls) of
241-- case S.parse (P.teeWith (,) prsr prsr) (S.fromList ls) of
226-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
242-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
227-- Left _ -> False
243-- Left _ -> False
245+-- teeWithFail :: Property
229-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
247-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
230-- Right _ -> False
248-- Right _ -> False
231-- Left _ -> True)
249-- Left _ -> True)
@@ -250,18 +268,20 @@ sliceSepBy =
250-- prsr_2 = (P.takeWhile (== 1) FL.toList)
268-- prsr_2 = (P.takeWhile (== 1) FL.toList)
251-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
269-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
253−-- shortest :: Property
271+-- shortestPass :: Property
254−-- shortest =
272+-- shortestPass =
255−-- forAll (listOf (chooseInt(0, 10000))) $ \ls ->
273+-- forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
257−-- prsr_1 = P.takeWhile (<= 2500) FL.toList
275+-- prsr_1 = P.takeWhile (<= (mid_value `Prelude.div` 2)) FL.toList
258−-- prsr_2 = P.takeWhile (<= 5000) FL.toList
276+-- prsr_2 = P.takeWhile (<= mid_value) FL.toList
259-- prsr_shortest = P.shortest prsr_1 prsr_2
277-- prsr_shortest = P.shortest prsr_1 prsr_2
261-- case S.parse prsr_shortest (S.fromList ls) of
279-- case S.parse prsr_shortest (S.fromList ls) of
262-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
280-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
263-- Left _ -> False
281-- Left _ -> False
283+-- shortestFail :: Property
265-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
285-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
266-- Right r -> r == 1
286-- Right r -> r == 1
267-- Left _ -> False)
287-- Left _ -> False)
@@ -286,7 +306,8 @@ main = hspec $ do
286 prop "test dieM function" dieM
306 prop "test dieM function" dieM
288 describe "test for element parser" $ do
308 describe "test for element parser" $ do
289− prop "test for peek function" peek
309+ prop "test for peek function" peekPass
310+ prop "test for peek function" peekFail
290 prop "test for eof function" eof
311 prop "test for eof function" eof
291 prop "test for satisfy function" satisfy
312 prop "test for satisfy function" satisfy
@@ -299,7 +320,10 @@ main = hspec $ do
299 prop "test for takeWhile1 function" takeWhile1
320 prop "test for takeWhile1 function" takeWhile1
300 prop "test for sliceSepBy function" sliceSepBy
321 prop "test for sliceSepBy function" sliceSepBy
301 -- prop "test for sliceSepByMax function" sliceSepByMax
322 -- prop "test for sliceSepByMax function" sliceSepByMax
302− -- prop "test for splitWith function" splitWith
323+ -- prop "test for splitWithPass function" splitWithPass
324+ -- prop "test for splitWithFail function" splitWithFail
325+ -- prop "test for teeWithPass function" teeWithPass
303− -- prop "test for teeWith function" teeWith
326+ -- prop "test for teeWithFail function" teeWithFail
304 -- prop "test for deintercalate function" deintercalate
327 -- prop "test for deintercalate function" deintercalate
305− -- prop "test for shortest function" shortest
328+ -- prop "test for shortestPass function" shortestPass
329+ -- prop "test for shortestFail function" shortestFail