@@ -237,9 +237,30 @@ testArray = do
237237 assert $ (drop (-2 ) [1 , 2 , 3 ]) == [1 , 2 , 3 ]
238238
239239 log " span should split an array in two based on a predicate"
240- let spanResult = span (_ < 4 ) [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
241- assert $ spanResult.init == [1 , 2 , 3 ]
242- assert $ spanResult.rest == [4 , 5 , 6 , 7 ]
240+ let testSpan { p, input, init_, rest_ } = do
241+ let result = span p input
242+ assert $ result.init == init_
243+ assert $ result.rest == rest_
244+
245+ let oneToSeven = [1 , 2 , 3 , 4 , 5 , 6 , 7 ]
246+ testSpan { p: (_ < 4 ), input: oneToSeven, init_: [1 , 2 , 3 ], rest_: [4 , 5 , 6 , 7 ] }
247+
248+ log " span with all elements satisfying the predicate"
249+ testSpan { p: const true , input: oneToSeven, init_: oneToSeven, rest_: [] }
250+
251+ log " span with no elements satisfying the predicate"
252+ testSpan { p: const false , input: oneToSeven, init_: [] , rest_: oneToSeven }
253+
254+ log " span with large inputs: 10000"
255+ let testBigSpan n =
256+ testSpan { p: (_ < n), input: range 1 n, init_: range 1 (n-1 ), rest_: [n] }
257+ testBigSpan 10000
258+
259+ log " span with large inputs: 40000"
260+ testBigSpan 40000
261+
262+ log " span with large inputs: 100000"
263+ testBigSpan 100000
243264
244265 log " group should group consecutive equal elements into arrays"
245266 assert $ group [1 , 2 , 2 , 3 , 3 , 3 , 1 ] == [NE .singleton 1 , 2 :| [2 ], 3 :| [3 , 3 ], NE .singleton 1 ]
0 commit comments