1 -- $Id: arith003.hs,v 1.5 2000/03/23 09:32:36 simonmar Exp $
3 -- !!! test Int/Integer arithmetic operations from the Prelude.
9 showit (do_ops int_ops) ++
10 showit (do_ops integer_ops)
13 showit :: Integral a => [(String, a, a, a)] -> String
15 [ str ++ " " ++ show l ++ " " ++ show r ++ " = " ++ show result ++ "\n"
16 | (str, l, r, result) <- stuff
19 do_ops :: Integral a => [((a -> a -> a), String, [(a,a)])]
20 -> [(String, a, a, a)]
21 do_ops ops = [ (str, l, r, l `op` r) | (op,str,args) <- ops, (l,r) <- args ]
23 small_operands, non_min_operands, operands, non_max_operands
25 small_operands = [ 0, 1, -1, 2, -2 ]
26 operands = small_operands ++ [ fromIntegral minInt, fromIntegral maxInt ]
27 non_min_operands = small_operands ++ [ fromIntegral maxInt ]
28 non_max_operands = small_operands ++ [ fromIntegral minInt ]
30 large_operands :: [ Integer ]
31 large_operands = operands ++
32 [ fromIntegral minInt - 1,
33 fromIntegral maxInt + 1,
34 fromIntegral minInt * 2,
35 fromIntegral maxInt * 2,
36 fromIntegral minInt ^ 2,
37 fromIntegral maxInt ^ 2
40 integer_ops :: [((Integer -> Integer -> Integer), String, [(Integer,Integer)])]
44 (div, "div", large_non_zero_r),
45 (mod, "mod", large_non_zero_r),
46 (quot, "quot", large_non_zero_r),
47 (rem, "rem", large_non_zero_r),
48 (gcd, "gcd", either_non_zero),
49 (lcm, "lcm", either_non_zero)
52 int_ops :: [((Int -> Int -> Int), String, [(Int,Int)])]
56 ((^), "(^)", small_non_neg_r),
57 (div, "div", non_min_l_or_zero_r),
58 (mod, "mod", non_min_l_or_zero_r),
59 (quot, "quot", non_min_l_or_zero_r),
60 (rem, "rem", non_min_l_or_zero_r),
61 (gcd, "gcd", either_non_zero),
62 (lcm, "lcm", non_max_r_either_non_zero)
65 all_ok, non_zero_r, either_non_zero, non_min_l_or_zero_r,
66 non_max_r_either_non_zero, small_non_neg_r
67 :: Integral a => [(a,a)]
69 all_ok = [ (l,r) | l <- operands, r <- operands ]
70 large_non_zero_r = [ (l,r) | l <- operands, r <- large_operands, r /= 0 ]
71 non_zero_r = [ (l,r) | l <- operands, r <- operands, r /= 0 ]
72 either_non_zero = [ (l,r) | l <- operands, r <- operands, l /= 0 || r /= 0 ]
73 small_non_neg_r = [ (l,r) | l <- operands, r <- small_operands, r >= 0 ]
74 non_min_l_or_zero_r = [ (l,r) | l <- non_min_operands, r <- operands, r /= 0 ]
75 non_max_r_either_non_zero = [ (l,r) | l <- operands, r <- non_max_operands, l /= 0 || r /= 0 ]
77 minInt = minBound :: Int
78 maxInt = maxBound :: Int