|
1 | 1 | module Test.Data.List (testList) where
|
2 | 2 |
|
3 | 3 | import Prelude
|
| 4 | +import Control.Monad |
4 | 5 | import Control.Monad.Eff.Console (log)
|
| 6 | +import Data.Foldable |
| 7 | +import Data.Monoid.Additive |
5 | 8 | import Data.List
|
6 | 9 | import Data.Maybe (Maybe(..), isNothing)
|
7 | 10 | import Data.Maybe.Unsafe (fromJust)
|
@@ -46,6 +49,9 @@ testList = do
|
46 | 49 | assert $ length (toList [1]) == 1
|
47 | 50 | assert $ length (toList [1, 2, 3, 4, 5]) == 5
|
48 | 51 |
|
| 52 | + log "length should be stack-safe" |
| 53 | + void $ pure $ length (range 1 100000) |
| 54 | + |
49 | 55 | log "snoc should add an item to the end of an list"
|
50 | 56 | assert $ toList [1, 2, 3] `snoc` 4 == toList [1, 2, 3, 4]
|
51 | 57 | assert $ nil `snoc` 1 == toList [1]
|
@@ -271,6 +277,15 @@ testList = do
|
271 | 277 | assert $ foldM (\x y -> Just (x + y)) 0 (range 1 10) == Just 55
|
272 | 278 | assert $ foldM (\_ _ -> Nothing) 0 (range 1 10) == Nothing
|
273 | 279 |
|
| 280 | + log "foldl should be stack-safe" |
| 281 | + void $ pure $ foldl (+) 0 $ range 1 100000 |
| 282 | + |
| 283 | + log "foldMap should be stack-safe" |
| 284 | + void $ pure $ foldMap Additive $ range 1 100000 |
| 285 | + |
| 286 | + log "foldMap should be left-to-right" |
| 287 | + assert $ foldMap show (range 1 5) == "12345" |
| 288 | + |
274 | 289 | -- log "can find the first 10 primes using lazy lists"
|
275 | 290 | -- let eratos :: L.List Number -> L.List Number
|
276 | 291 | -- eratos xs = Control.Lazy.defer \_ ->
|
|
0 commit comments