[project @ 1998-08-21 17:23:03 by simonm]
[ghc-hetmet.git] / ghc / tests / lib / should_run / list001.hs
1 module Main where
2
3 import List
4 import Exception
5 import Prelude hiding (catch)
6
7 -- This module briefly tests all the functions in PrelList and a few
8 -- from List.
9
10 -- ToDo: test strictness properties.
11
12 main = do
13
14   -- head
15   print (head [1,2,3,4], head "a")
16   catchOne (print (head [] :: String)) (\_ -> putStr "head []\n")
17
18   -- tail
19   print (tail [1,2,3,4], tail "a")
20   catchOne (print (tail [] :: String)) (\_ -> putStr "tail []\n")
21
22   -- init
23   print (init [1,2,3,4], init "a")
24   catchOne (print (init [] :: String)) (\_ -> putStr "init []\n")
25
26   -- last
27   print (last [1,2,3,4], last "a")
28   catchOne (print (last [] :: String)) (\_ -> putStr "last []\n")
29
30   -- null
31   print [null [], null "abc"]
32
33   -- length
34   print (length [1..10])
35
36   -- foldl
37   print (foldl  (+) 1 [1..10])
38
39   -- foldl1
40   print (foldl1 (+) [1..10])
41   catchOne (print (foldl1 (+) [] :: Int)) (\_ -> putStr "foldl1 []\n")
42
43   -- scanl
44   print (scanl  (+) 1 [1..10])
45
46   -- scanl1
47   print (scanl1 (+) [1..10])
48   catchOne (print (scanl1 (+) [] :: [Int])) (\_ -> putStr "scanl1 []\n")
49
50   -- foldr1
51   print (foldr1 (+) [1..10])
52   catchOne (print (foldr1 (+) [] :: Int)) (\_ -> putStr "foldr1 []\n")
53
54   -- scanr
55   print (scanr  (+) 1 [1..10])
56
57   -- scanr1
58   print (scanr1 (+) [1..10])
59   catchOne (print (scanr1 (+) [] :: [Int])) (\_ -> putStr "scanr1 []\n")
60
61   -- iterate
62   print (take 10 (cycle (take 4 (iterate (+1) 1))))
63
64   -- take
65   print (take 4 (repeat "x"), take 0 (repeat "x"), take 5 [1..4])
66   catchOne (print (take (-1) [1..10])) (\_ -> putStr "take (-1)\n")
67
68   -- replicate
69   print [replicate 2 "abc", replicate 0 "abc", replicate 3 []]
70
71   -- drop
72   print [drop 5 [1..10], drop 0 [1..10], drop 5 [1..4]]
73   catchOne (print (drop (-1) [1..10])) (\_ -> putStr "drop (-1)\n")
74
75   -- splitAt
76   print [splitAt 5 [1..10], splitAt 5 [1..4]]
77   catchOne (print (splitAt (-1) [1..10])) (\_ -> putStr "splitAt (-1)\n")
78
79   -- scan
80   print (span (<5) [1..10])
81
82   -- break
83   print (break (<5) [1..10])
84
85   -- reverse
86   print [reverse [1..10], reverse []]
87
88   -- and
89   print [and [], and [True], and [False]]
90
91   -- or
92   print [or [], or [True], or [False]]
93
94   -- elem
95   print [elem 5 [1..10], elem 0 [1..10], elem 1 []]
96
97   -- notElem
98   print [notElem 5 [1..10], notElem 0 [1..10], notElem 1 []]
99
100   -- lookkup
101   print (lookup 4 (zip [1..10] (reverse [1..10])))
102
103   -- sum
104   print [sum [1..10], sum []]
105
106   -- product
107   print [product [1..10], product []]
108
109   -- maximum
110   print (maximum [1..10])
111   catchOne (print (maximum [] :: Int)) (\_ -> putStr "maximum []\n")
112
113   -- minimum
114   print (minimum [1..10])
115   catchOne (print (minimum [] :: Int)) (\_ -> putStr "minimum []\n")
116
117   -- concatMap
118   print (concatMap (:[]) [(1::Int)..10])
119
120   -- zip
121   print [zip [1] [2], zip [1] [], zip [] [2], zip [1..5] [2..6]]
122
123   -- zip3
124   print (zip3 [1,2] [3,4] [5,6])
125
126   -- zipWith
127   print [zipWith (+) [1,2] [3,4], zipWith (+) [1] [], zipWith (+) [] []]
128
129   -- unzip
130   print [unzip [(1,2),(3,4)], unzip []]
131
132   -- unzip3
133   print [unzip3 [(1,2,3),(3,4,5)], unzip3 []]
134
135   -- unlines
136   print (unlines (lines "a\nb\nc\n"), lines "", unlines [])
137
138   -- words
139   print (unwords (words "a b c d"),   words "", unwords [])
140
141   -- deleteBy
142   print [deleteBy (==) 1 [0,1,1,2,3,4], 
143          deleteBy (==) (error "deleteBy") []]
144
145   -- delete
146   print [delete 1 [0,1,1,2,3,4], 
147          delete (error "delete") []]
148   
149   -- \\
150   print [ [0,1,1,2,3,4] \\ [3,2,1],  
151           [1,2,3,4] \\ [],  
152           [] \\ [error "\\\\"] ]