@@ -5,8 +5,8 @@ import Prelude
5
5
import Control.Monad.Eff (Eff )
6
6
import Control.Monad.Eff.Console (log , CONSOLE )
7
7
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_ )
10
10
import Data.Maybe (Maybe (..), isNothing , fromJust )
11
11
import Data.NonEmpty ((:|))
12
12
import Data.NonEmpty as NE
@@ -237,9 +237,30 @@ testArray = do
237
237
assert $ (drop (-2 ) [1 , 2 , 3 ]) == [1 , 2 , 3 ]
238
238
239
239
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
243
264
244
265
log " group should group consecutive equal elements into arrays"
245
266
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
308
329
assert $ length arr == n
309
330
assert $ all (_ == elem) arr
310
331
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
+
311
343
nil :: Array Int
312
344
nil = []
313
345
0 commit comments