[project @ 2001-03-15 07:40:06 by qrczak]
[ghc-hetmet.git] / ghc / tests / numeric / should_run / arith011.hs
index 6499e01..1dbd52d 100644 (file)
@@ -1,4 +1,4 @@
---!!! Testing Int and Word
+-- !!! Testing Int and Word
 module Main(main) where
 import Int
 import Word
@@ -10,12 +10,16 @@ main = test
 
 test :: IO ()
 test = do
-   testIntlike "Int8"   (0::Int8)     
-   testIntlike "Int16"  (0::Int16)    
-   testIntlike "Int32"  (0::Int32)    
-   testIntlike "Word8"  (0::Word8)    
-   testIntlike "Word16" (0::Word16)   
-   testIntlike "Word32" (0::Word32)   
+   testIntlike "Int"    (0::Int)
+   testIntlike "Int8"   (0::Int8)
+   testIntlike "Int16"  (0::Int16)
+   testIntlike "Int32"  (0::Int32)
+   testIntlike "Int64"  (0::Int64)
+   testIntlike "Word8"  (0::Word8)
+   testIntlike "Word16" (0::Word16)
+   testIntlike "Word32" (0::Word32)
+   testIntlike "Word64" (0::Word64)
+   testInteger
 
 testIntlike :: (Bounded a, Integral a, Ix a, Read a, Bits a) => String -> a -> IO ()
 testIntlike name zero = do
@@ -30,8 +34,22 @@ testIntlike name zero = do
   testNum      zero
   testReal     zero
   testIntegral zero
-  testBits     zero
+  testConversions zero
+  testBits     zero True
+
+testInteger  = do
+  let zero = 0 :: Integer
+  putStrLn $ "--------------------------------"
+  putStrLn $ "--Testing Integer"
   putStrLn $ "--------------------------------"
+  testEnum     zero
+  testReadShow zero
+  testEq       zero
+  testOrd      zero
+  testNum      zero
+  testReal     zero
+  testIntegral zero
+  testBits     zero False
 
 -- In all these tests, zero is a dummy element used to get
 -- the overloading to work
@@ -48,8 +66,23 @@ testEnum zero = do
   print [zero .. toEnum 20]            -- enumFromTo
   print [zero, toEnum 2 .. toEnum 20]  -- enumFromThenTo
 
-samples :: (Num a, Enum a) => a -> ([a], [a])
-samples zero = ([-3 .. -1]++[0 .. 3], [-3 .. -1]++[1 .. 3])
+testConversions zero = do
+  putStrLn "testConversions"
+  putStr "Integer : " >> print (map fromIntegral numbers :: [Integer])
+  putStr "Int     : " >> print (map fromIntegral numbers :: [Int])
+  putStr "Int8    : " >> print (map fromIntegral numbers :: [Int8])
+  putStr "Int16   : " >> print (map fromIntegral numbers :: [Int16])
+  putStr "Int32   : " >> print (map fromIntegral numbers :: [Int32])
+  putStr "Int64   : " >> print (map fromIntegral numbers :: [Int64])
+  putStr "Word8   : " >> print (map fromIntegral numbers :: [Word8])
+  putStr "Word16  : " >> print (map fromIntegral numbers :: [Word16])
+  putStr "Word32  : " >> print (map fromIntegral numbers :: [Word32])
+  putStr "Word64  : " >> print (map fromIntegral numbers :: [Word64])
+  where numbers = [minBound, 0, maxBound] `asTypeOf` [zero]
+
+samples :: (Num a) => a -> ([a], [a])
+samples zero = (map fromInteger ([-3 .. -1]++[0 .. 3]),
+                map fromInteger ([-3 .. -1]++[1 .. 3]))
   
 table1 :: (Show a, Show b) => String -> (a -> b) -> [a] -> IO ()
 table1 nm f xs = do
@@ -119,20 +152,21 @@ testIntegral zero = do
  where
   (xs,ys) = samples zero
 
-testBits zero = do
+testBits zero do_bitsize = do
   putStrLn "testBits"
   table2 ".&.  "            (.&.)         xs ys
   table2 ".|.  "            (.|.)         xs ys
   table2 "`xor`"            xor           xs ys
   table1 "complement"       complement    xs
-  table2 "`shift`"          shift         xs [0..3] 
+  table2 "`shiftL`"         shiftL        xs ([0..3] ++ [32])
+  table2 "`shiftR`"         shiftR        xs ([0..3] ++ [32]) 
   table2 "`rotate`"         rotate        xs ([-3..3])
   table1 "bit"              (\ x -> (bit x) `asTypeOf` zero)   [(0::Int)..3]
-  table2 "`setBit`"         setBit        xs [0..3]
-  table2 "`clearBit`"       clearBit      xs [0..3]
-  table2 "`complementBit`"  complementBit xs [0..3]
-  table2 "`testBit`"        testBit       xs [0..3]
-  table1 "bitSize"          bitSize       xs
+  table2 "`setBit`"         setBit        xs ([0..3] ++ [32])
+  table2 "`clearBit`"       clearBit      xs ([0..3] ++ [32])
+  table2 "`complementBit`"  complementBit xs ([0..3] ++ [32])
+  table2 "`testBit`"        testBit       xs ([0..3] ++ [32])
+  if do_bitsize then table1 "bitSize" bitSize xs else return ()
   table1 "isSigned"         isSigned      xs
  where
   (xs,ys) = samples zero