on master help sign in
Add tests for ParserD.groupByRolling
commite40c09ccaa8b86bf336e67758b86c31f79764df9 authorAdithya Kumar <adithya@composewell.com> dateSun 24 Jan 2021, 12:49 (6 years ago) parentd601012
1 file changed+20
test/Streamly/Test/Data/Parser/ParserD.hs+20
test/Streamly/Test/Data/Parser/ParserD.hs+20
@@ -335,6 +335,25 @@ groupBy =
335335 | null lst = []
336336 | otherwise = head $ List.groupBy cmp lst
337337
338+groupByRolling :: Property
339+groupByRolling =
340+ forAll (listOf (chooseInt (0, 1)))
341+ $ \ls ->
342+ case S.parseD parser (S.fromList ls) of
343+ Right parsed -> checkListEqual parsed (groupByLF Nothing ls)
344+ Left _ -> property False
345+
346+ where
347+
348+ cmp = (==)
349+ parser = P.groupBy cmp FL.toList
350+ groupByLF _ [] = []
351+ groupByLF Nothing (x:xs) = x : groupByLF (Just x) xs
352+ groupByLF (Just y) (x:xs) =
353+ if cmp y x
354+ then x : groupByLF (Just x) xs
355+ else []
356+
338357sliceSepByMax :: Property
339358sliceSepByMax =
340359 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -696,6 +715,7 @@ main =
696715 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
697716 prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
698717 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
718+ prop "groupByRolling" groupByRolling
699719 prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
700720 prop "many (P.wordBy ' ') = words'" wordBy
701721 prop "parse 0, then 1, else fail" splitWith