@@ -10,39 +10,51 @@ import Test.Hspec(hspec, describe)
1010import Test.Hspec.QuickCheck
1111import Test.QuickCheck (forAll, chooseInt, Property, property, listOf, vectorOf, (.&&.))
1212
13+min_value :: Int
14+min_value = 0
15+
16+mid_value :: Int
17+mid_value = 5000
18+
19+max_value :: Int
20+max_value = 10000
21+
22+max_length :: Int
23+max_length = 1000
24+
1325-- Accumulator Tests
1426
1527fromFold :: Property
1628fromFold =
17− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
29+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
1830 case (==) <$> (S.parse (P.fromFold FL.sum) (S.fromList ls)) <*> (S.fold FL.sum (S.fromList ls)) of
1931 Right is_equal -> is_equal
2032 Left _ -> False
2133
2234any :: Property
2335any =
24− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
25− case S.parse (P.any (> 5000)) (S.fromList ls) of
26− Right r -> r == (Prelude.any (> 5000) ls)
36+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
37+ case S.parse (P.any (> mid_value)) (S.fromList ls) of
38+ Right r -> r == (Prelude.any (> mid_value) ls)
2739 Left _ -> False
2840
2941all :: Property
3042all =
31− forAll (listOf $ chooseInt (0, 10000)) $ \ls ->
32− case S.parse (P.all (> 5000)) (S.fromList ls) of
33− Right r -> r == (Prelude.all (> 5000) ls)
43+ forAll (listOf $ chooseInt (min_value, max_value)) $ \ls ->
44+ case S.parse (P.all (> mid_value)) (S.fromList ls) of
45+ Right r -> r == (Prelude.all (> mid_value) ls)
3446 Left _ -> False
3547
3648yield :: Property
3749yield =
38− forAll (chooseInt (0, 10000)) $ \x ->
50+ forAll (chooseInt (min_value, max_value)) $ \x ->
3951 case S.parse (P.yield x) (S.fromList [1 :: Int]) of
4052 Right r -> r == x
4153 Left _ -> False
4254
4355yieldM :: Property
4456yieldM =
45− forAll (chooseInt (0, 10000)) $ \x ->
57+ forAll (chooseInt (min_value, max_value)) $ \x ->
4658 case S.parse (P.yieldM $ return x) (S.fromList [1 :: Int]) of
4759 Right r -> r == x
4860 Left _ -> False
@@ -63,24 +75,26 @@ dieM =
6375
6476-- Element Parser Tests
6577
66−peek :: Property
67−peek =
68− forAll (chooseInt (1, 100)) $ \list_length ->
69− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
78+peekPass :: Property
79+peekPass =
80+ forAll (chooseInt (1, max_length)) $ \list_length ->
81+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
7082 case S.parse P.peek (S.fromList ls) of
7183 Right head_value -> case ls of
7284 head_ls : _ -> head_value == head_ls
7385 _ -> False
7486 Left _ -> False
75− .&&.
87+
88+peekFail :: Property
89+peekFail =
7690 property (case S.parse P.peek (S.fromList []) of
7791 Right _ -> False
7892 Left _ -> True)
7993
8094eof :: Property
8195eof =
82− forAll (chooseInt (1, 100)) $ \list_length ->
83− forAll (vectorOf list_length (chooseInt (0, 10000))) $ \ls ->
96+ forAll (chooseInt (1, max_length)) $ \list_length ->
97+ forAll (vectorOf list_length (chooseInt (min_value, max_value))) $ \ls ->
8498 case S.parse P.eof (S.fromList ls) of
8599 Right _ -> False
86100 Left _ -> True
@@ -91,7 +105,7 @@ eof =
91105
92106satisfy :: Property
93107satisfy =
94− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
108+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
95109 case S.parse (P.satisfy predicate) (S.fromList ls) of
96110 Right r -> case ls of
97111 [] -> False
@@ -100,22 +114,22 @@ satisfy =
100114 [] -> True
101115 (x : _) -> not $ predicate x
102116 where
103− predicate = (>= 5000)
117+ predicate = (>= mid_value)
104118
105119-- Sequence Parsers Tests
106120
107121take :: Property
108122take =
109− forAll (chooseInt (0, 10000)) $ \n ->
110− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
123+ forAll (chooseInt (min_value, max_value)) $ \n ->
124+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
111125 case S.parse (P.take n FL.toList) (S.fromList ls) of
112126 Right parsed_list -> parsed_list == Prelude.take n ls
113127 Left _ -> False
114128
115129takeEQ :: Property
116130takeEQ =
117− forAll (chooseInt (0, 10000)) $ \n ->
118− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
131+ forAll (chooseInt (min_value, max_value)) $ \n ->
132+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
119133 let
120134 list_length = Prelude.length ls
121135 in
@@ -125,8 +139,8 @@ takeEQ =
125139
126140takeGE :: Property
127141takeGE =
128− forAll (chooseInt (0, 10000)) $ \n ->
129− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
142+ forAll (chooseInt (min_value, max_value)) $ \n ->
143+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
130144 let
131145 list_length = Prelude.length ls
132146 in
@@ -136,7 +150,7 @@ takeGE =
136150
137151lookAhead :: Property
138152lookAhead =
139− forAll (chooseInt (0, 10000)) $ \n ->
153+ forAll (chooseInt (min_value, max_value)) $ \n ->
140154 let
141155 takeWithoutConsume = P.lookAhead $ P.take n FL.toList
142156 parseTwice = do
@@ -144,7 +158,7 @@ lookAhead =
144158 parsed_list_2 <- takeWithoutConsume
145159 return (parsed_list_1, parsed_list_2)
146160 in
147− forAll (listOf (chooseInt (0, 10000))) $ \ls ->
161+ forAll (listOf (chooseInt (min_value, max_value))) $ \ls ->
148162 case S.parse parseTwice (S.fromList ls) of
149163 Right (ls_1, ls_2) -> (ls_1 == ls_2) && (ls_1 == Prelude.take n ls)
150164 Left _ -> (list_length < n) || (list_length == n && n == 0)
@@ -184,7 +198,7 @@ sliceSepBy =
184198
185199-- sliceSepByMax :: Property
186200-- sliceSepByMax =
187−-- forAll (chooseInt (0, 10000)) $ \n ->
201+-- forAll (chooseInt (min_value, max_value)) $ \n ->
188202-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
189203-- case S.parse (P.sliceSepByMax predicate n FL.toList) (S.fromList ls) of
190204-- Right parsed_list -> parsed_list == Prelude.take n (Prelude.takeWhile (not . predicate) ls)
@@ -192,8 +206,8 @@ sliceSepBy =
192206-- where
193207-- predicate = (== 1)
194208
195−-- splitWith :: Property
196−-- splitWith =
209+-- splitWithPass :: Property
210+-- splitWithPass =
197211-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
198212-- case S.parse (P.splitWith (,) (P.satisfy (== 0)) (P.satisfy (== 1))) (S.fromList ls) of
199213-- Right (result_first, result_second) -> case ls of
@@ -202,7 +216,9 @@ sliceSepBy =
202216-- Left _ -> case ls of
203217-- 0 : 1 : _ -> False
204218-- _ -> True
205−-- .&&.
219+
220+-- splitWithFail :: Property
221+-- splitWithFail =
206222-- property (case S.parse (P.splitWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
207223-- Right _ -> False
208224-- Left _ -> True)
@@ -215,8 +231,8 @@ sliceSepBy =
215231-- Right _ -> False
216232-- Left _ -> True)
217233
218−-- teeWith :: Property
219−-- teeWith =
234+-- teeWithPass :: Property
235+-- teeWithPass =
220236-- forAll (chooseInt (0, 10000)) $ \n ->
221237-- forAll (listOf (chooseInt (0, 1))) $ \ls ->
222238-- let
@@ -225,7 +241,9 @@ sliceSepBy =
225241-- case S.parse (P.teeWith (,) prsr prsr) (S.fromList ls) of
226242-- Right (ls_1, ls_2) -> (Prelude.take n ls == ls_1) && (ls_1 == ls_2)
227243-- Left _ -> False
228−-- .&&.
244+
245+-- teeWithFail :: Property
246+-- teeWithFail =
229247-- property (case S.parse (P.teeWith (,) (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
230248-- Right _ -> False
231249-- Left _ -> True)
@@ -250,18 +268,20 @@ sliceSepBy =
250268-- prsr_2 = (P.takeWhile (== 1) FL.toList)
251269-- concatFold = FL.Fold (\concatList curr_list -> return $ concatList ++ curr_list) (return []) return
252270
253−-- shortest :: Property
254−-- shortest =
255−-- forAll (listOf (chooseInt(0, 10000))) $ \ls ->
271+-- shortestPass :: Property
272+-- shortestPass =
273+-- forAll (listOf (chooseInt(min_value, max_value))) $ \ls ->
256274-- let
257−-- prsr_1 = P.takeWhile (<= 2500) FL.toList
258−-- prsr_2 = P.takeWhile (<= 5000) FL.toList
275+-- prsr_1 = P.takeWhile (<= (mid_value `Prelude.div` 2)) FL.toList
276+-- prsr_2 = P.takeWhile (<= mid_value) FL.toList
259277-- prsr_shortest = P.shortest prsr_1 prsr_2
260278-- in
261279-- case S.parse prsr_shortest (S.fromList ls) of
262280-- Right short_list -> short_list == Prelude.takeWhile (<= 2500) ls
263281-- Left _ -> False
264−-- .&&.
282+
283+-- shortestFail :: Property
284+-- shortestFail =
265285-- property (case S.parse (P.shortest (P.die "die") (P.yield (1 :: Int))) (S.fromList [1 :: Int]) of
266286-- Right r -> r == 1
267287-- Left _ -> False)
@@ -286,7 +306,8 @@ main = hspec $ do
286306 prop "test dieM function" dieM
287307
288308 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
290311 prop "test for eof function" eof
291312 prop "test for satisfy function" satisfy
292313
@@ -299,7 +320,10 @@ main = hspec $ do
299320 prop "test for takeWhile1 function" takeWhile1
300321 prop "test for sliceSepBy function" sliceSepBy
301322 -- prop "test for sliceSepByMax function" sliceSepByMax
302− -- prop "test for splitWith function" splitWith
303− -- prop "test for teeWith function" teeWith
323+ -- prop "test for splitWithPass function" splitWithPass
324+ -- prop "test for splitWithFail function" splitWithFail
325+ -- prop "test for teeWithPass function" teeWithPass
326+ -- prop "test for teeWithFail function" teeWithFail
304327 -- 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