@@ -5,8 +5,8 @@ import Prelude
55import Control.Monad.Eff (Eff )
66import Control.Monad.Eff.Console (log , CONSOLE )
77
8- import Data.Array (range , replicate , foldM , unzip , zip , zipWithA , zipWith , intersectBy , intersect , (\\), deleteBy , delete , unionBy , union , nubBy , nub , groupBy , group' , group , span , dropWhile , drop , takeWhile , take , sortBy , sort , catMaybes , mapMaybe , mapWithIndex , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , init , tail , last , head , insertBy , insert , snoc , (:), length , null , singleton , fromFoldable )
9- import Data.Foldable (for_ , foldMapDefaultR , class Foldable , all )
8+ import Data.Array (range , replicate , foldM , unzip , zip , zipWithA , zipWith , intersectBy , intersect , (\\), deleteBy , delete , unionBy , union , nubBy , nub , groupBy , group' , group , span , dropWhile , drop , takeWhile , take , sortBy , sort , catMaybes , mapMaybe , mapWithIndex , filterM , filter , concat , concatMap , reverse , alterAt , modifyAt , updateAt , deleteAt , insertAt , findLastIndex , findIndex , elemLastIndex , elemIndex , (!!), uncons , init , tail , last , head , insertBy , insert , snoc , (:), length , null , singleton , fromFoldable , toUnfoldable )
9+ import Data.Foldable (for_ , foldMapDefaultR , class Foldable , all , traverse_ )
1010import Data.Maybe (Maybe (..), isNothing , fromJust )
1111import Data.NonEmpty ((:|))
1212import Data.NonEmpty as NE
@@ -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 ]
@@ -308,6 +329,17 @@ testArray = do
308329 assert $ length arr == n
309330 assert $ all (_ == elem) arr
310331
332+ log " toUnfoldable"
333+ let toUnfoldableId xs = toUnfoldable xs == xs
334+ traverse_ (assert <<< toUnfoldableId)
335+ [ []
336+ , [1 ]
337+ , [1 ,2 ,3 ]
338+ , [2 ,3 ,1 ]
339+ , [4 ,0 ,0 ,1 ,25 ,36 ,458 ,5842 ,23757 ]
340+ ]
341+
342+
311343nil :: Array Int
312344nil = []
313345
0 commit comments