[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / interpreter / test / runtime / r000.hs
1 --!!! Testing bignums
2
3 -- Note: anything which prints an Integer automatically tests
4 -- quotRem.
5
6 egs1 = [-5..5] :: [Integer]
7 egs2 = filter (/=0) egs1   -- avoid division by zero
8
9 t0 = (1::Integer) == (1::Integer)
10
11 t1 = shw $ table (+) egs1 egs1 
12 t2 = shw $ table (-) egs1 egs1 
13 t3 = shw $ table (*) egs1 egs1 
14
15 t4 = shw $ table div  egs1 egs2 
16 t5 = shw $ table mod  egs1 egs2 
17 t6 = shw $ table quot egs1 egs2 
18 t7 = shw $ table rem  egs1 egs2
19
20 u1 = shw $ table (==) egs1 egs1
21 u2 = shw $ table (/=) egs1 egs1
22 u3 = shw $ table (<=) egs1 egs1
23 u4 = shw $ table (<)  egs1 egs1
24 u5 = shw $ table (>)  egs1 egs1
25 u6 = shw $ table (>=) egs1 egs1
26
27
28 -- The implementation is based on 4 digit chunks - so let's test
29 -- the results when we use values near those boundaries.
30
31 egs3 = [9999,10000,10001,99999999,100000000,100000001] :: [Integer]
32 egs4 = filter (/=0) egs3   -- avoid division by zero
33
34 v1 = shw $ table  (+) egs3 egs3 
35 v2 = shw $ table  (-) egs3 egs3 
36 v3 = shw $ table  (*) egs3 egs3 
37  
38 v4 = shw $ table div  egs3 egs4 
39 v5 = shw $ table mod  egs3 egs4 
40 v6 = shw $ table quot egs3 egs4 
41 v7 = shw $ table rem  egs3 egs4
42
43 w1 = shw $ table (==) egs3 egs3
44 w2 = shw $ table (/=) egs3 egs3
45 w3 = shw $ table (<=) egs3 egs3
46 w4 = shw $ table (<)  egs3 egs3
47 w5 = shw $ table (>)  egs3 egs3
48 w6 = shw $ table (>=) egs3 egs3
49
50 -- Some utilities for generating neat tables of test results
51 table :: (a -> a -> b) -> [a] -> [a] -> [[b]]
52 table f xs ys = [ [ x `f` y | x <- xs ] | y <- ys ]
53
54 shw :: Show a => [[a]] -> IO ()
55 shw = putStr . unlines . map (unwords . map show)
56