1{-# LANGUAGE OverloadedStrings #-} 2 3module System.IO.Streams.Tests.List (tests) where 4 5------------------------------------------------------------------------------ 6import Control.Monad hiding (mapM) 7import Prelude hiding (mapM, read) 8import Test.Framework 9import Test.Framework.Providers.HUnit 10import Test.HUnit hiding (Test) 11------------------------------------------------------------------------------ 12import System.IO.Streams.List 13------------------------------------------------------------------------------ 14import System.IO.Streams.Tests.Common (expectExceptionH) 15 16tests :: [Test] 17tests = [ testChunkJoin, testChunkWithJoin ] 18 19 20 21testChunkJoin :: Test 22testChunkJoin = testCase "list/chunkList and join" $ do 23 expectExceptionH (fromList [1..10::Int] >>= chunkList 0 >>= toList) 24 25 fromList [1..10 :: Int] >>= chunkList 3 26 >>= toList 27 >>= assertEqual "chunkList" [ [1,2,3] 28 , [4,5,6] 29 , [7,8,9] 30 , [10] 31 ] 32 fromList [1..12 :: Int] >>= chunkList 3 33 >>= concatLists 34 >>= toList 35 >>= assertEqual "concatlists" [1..12] 36 37testChunkWithJoin :: Test 38testChunkWithJoin = testCase "list/chunkListWith and join" $ do 39 fromList [1..10 :: Int] >>= chunkListWith (\_ n -> n>=3) 40 >>= toList 41 >>= assertEqual "chunkListWith" [ [1,2,3] 42 , [4,5,6] 43 , [7,8,9] 44 , [10] 45 ] 46 fromList [1..12 :: Int] >>= chunkListWith (\_ n -> n>=3) 47 >>= concatLists 48 >>= toList 49 >>= assertEqual "concatlists" [1..12] 50 51 fromList ['a'..'z' :: Char] 52 >>= chunkListWith (\x n -> n>=4 && x `elem` ("aeiouy" :: String)) 53 >>= toList 54 >>= assertEqual "chunkListWith" [ "abcde" 55 , "fghi" 56 , "jklmno" 57 , "pqrstu" 58 , "vwxy" 59 , "z" 60 ] 61