on master help sign in
Add splitOnSuffixSeq property tests
d644962adithyaov
test/Streamly/Test/Prelude/Serial.hs+43
@@ -134,11 +134,37 @@ seqSplitterProperties sep desc = do
134 -- Exclusive case
134 -- Exclusive case
135 splitIntercalateEqId splitOnSeq_ intercalate
135 splitIntercalateEqId splitOnSeq_ intercalate
136
136
137+ describe (desc <> " splitOnSuffixSeq/intercalate")
138+ $ do
139+ -- Empty seperator
140+ intercalateSplitEqIdNoSepEnd 0
141+ concatSplitIntercalateEqConcat splitOnSuffixSeq_ intercalateSuffix 0
142+
143+ -- Single element seperator
144+ intercalateSplitEqIdNoSepEnd 1
145+ concatSplitIntercalateEqConcat splitOnSuffixSeq_ intercalateSuffix 1
146+
147+ -- Shift Or
148+ intercalateSplitEqIdNoSepEnd 2
149+ concatSplitIntercalateEqConcat splitOnSuffixSeq_ intercalateSuffix 2
150+
151+ -- Karp-Rabin
152+ intercalateSplitEqIdNoSepEnd 4
153+ concatSplitIntercalateEqConcat splitOnSuffixSeq_ intercalateSuffix 4
154+
155+ -- Exclusive case
156+ splitIntercalateEqId splitOnSuffixSeq_ intercalateSuffix
157+
137 where
158 where
138
159
139 splitOnSeq_ xs ys =
160 splitOnSeq_ xs ys =
140 S.toList $ IS.splitOnSeq (A.fromList ys) FL.toList (S.fromList xs)
161 S.toList $ IS.splitOnSeq (A.fromList ys) FL.toList (S.fromList xs)
141
162
163+ splitOnSuffixSeq_ xs ys =
164+ S.toList $ IS.splitOnSuffixSeq (A.fromList ys) FL.toList (S.fromList xs)
165+
166+ intercalateSuffix xs yss = intercalate xs yss ++ xs
167+
142 nonSepElem :: Gen a
168 nonSepElem :: Gen a
143 nonSepElem = suchThat arbitrary (/= sep)
169 nonSepElem = suchThat arbitrary (/= sep)
144
170
@@ -170,6 +196,23 @@ seqSplitterProperties sep desc = do
170 (intercalate (replicate i sep) ys)
196 (intercalate (replicate i sep) ys)
171 xs
197 xs
172
198
199+ intercalateSplitEqIdNoSepEnd i =
200+ let name =
201+ "intercalate . splitOnSuffixSeq_ . (++ [x \\= sep]) == id ("
202+ <> show i <> " element separator)"
203+ in prop name
204+ $ forAll ((,) <$> listWithSep <*> nonSepElem)
205+ $ \(xs_, nonSep) -> do
206+ let xs = xs_ ++ [nonSep]
207+ withMaxSuccess maxTestCount
208+ $ monadicIO
209+ $ do
210+ ys <- splitOnSuffixSeq_ xs (replicate i sep)
211+ listEquals
212+ (==)
213+ (intercalate (replicate i sep) ys)
214+ xs
215+
173 concatSplitIntercalateEqConcat splitter intercalater i =
216 concatSplitIntercalateEqConcat splitter intercalater i =
174 let name =
217 let name =
175 "concat . splitter . intercalater == "
218 "concat . splitter . intercalater == "