1 --!!! Testing Int and Word
9 testIntlike "Int8" (0::Int8)
10 testIntlike "Int16" (0::Int16)
11 testIntlike "Int32" (0::Int32)
12 testIntlike "Word8" (0::Word8)
13 testIntlike "Word16" (0::Word16)
14 testIntlike "Word32" (0::Word32)
16 testIntlike :: (Bounded a, Integral a, Ix a, Read a, Bits a) => String -> a -> IO ()
17 testIntlike name zero = do
18 putStrLn $ "--------------------------------"
19 putStrLn $ "--Testing " ++ name
20 putStrLn $ "--------------------------------"
30 putStrLn $ "--------------------------------"
32 -- In all these tests, zero is a dummy element used to get
33 -- the overloading to work
36 putStrLn "testBounded"
37 print $ (minBound-1, minBound, minBound+1) `asTypeOf` (zero,zero,zero)
38 print $ (maxBound-1, maxBound, maxBound+1) `asTypeOf` (zero,zero,zero)
42 print $ take 10 [zero .. ] -- enumFrom
43 print $ take 10 [zero, toEnum 2 .. ] -- enumFromThen
44 print [zero .. toEnum 20] -- enumFromTo
45 print [zero, toEnum 2 .. toEnum 20] -- enumFromThenTo
47 samples :: (Num a, Enum a) => a -> ([a], [a])
48 samples zero = ([-3 .. -1]++[0 .. 3], [-3 .. -1]++[1 .. 3])
50 table1 :: (Show a, Show b) => String -> (a -> b) -> [a] -> IO ()
52 sequence [ f' x | x <- xs ]
55 f' x = putStrLn (nm ++ " " ++ show x ++ " = " ++ show (f x))
57 table2 :: (Show a, Show b, Show c) => String -> (a -> b -> c) -> [a] -> [b] -> IO ()
58 table2 nm op xs ys = do
59 sequence [ sequence [ op' x y | y <- ys ] >> putStrLn " "
64 op' x y = putStrLn (show x ++ " " ++ nm ++ " " ++ show y
65 ++ " = " ++ show (op x y))
67 testReadShow zero = do
68 putStrLn "testReadShow"
70 print (map read_show xs)
72 (xs,zs) = samples zero
73 read_show x = (read (show x) `asTypeOf` zero)
77 table2 "==" (==) xs xs
78 table2 "/=" (/=) xs xs
80 (xs,ys) = samples zero
84 table2 "<=" (<=) xs xs
87 table2 ">=" (>=) xs xs
88 table2 "`compare`" compare xs xs
90 (xs,ys) = samples zero
97 table1 "negate" negate xs
99 (xs,ys) = samples zero
103 table1 "toRational" toRational xs
105 (xs,ys) = samples zero
107 testIntegral zero = do
108 putStrLn "testIntegral"
109 table2 "`divMod` " divMod xs ys
110 table2 "`div` " div xs ys
111 table2 "`mod` " mod xs ys
112 table2 "`quotRem`" quotRem xs ys
113 table2 "`quot` " quot xs ys
114 table2 "`rem` " rem xs ys
116 (xs,ys) = samples zero
120 table2 ".&. " (.&.) xs ys
121 table2 ".|. " (.|.) xs ys
122 table2 "`xor`" xor xs ys
123 table1 "complement" complement xs
124 table2 "`shift`" shift xs [0..3]
125 -- table2 "`rotate`" rotate xs [0..3]
126 -- table1 "bit" bit xs
127 table2 "`setBit`" setBit xs [0..3]
128 table2 "`clearBit`" clearBit xs [0..3]
129 table2 "`complementBit`" complementBit xs [0..3]
130 table2 "`testBit`" testBit xs [0..3]
131 table1 "bitSize" bitSize xs
132 table1 "isSigned" isSigned xs
134 (xs,ys) = samples zero