1 -- $Id: arith003.hs,v 1.4 2000/01/20 13:38:42 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
38 integer_ops :: [((Integer -> Integer -> Integer), String, [(Integer,Integer)])]
42 (div, "div", large_non_zero_r),
43 (mod, "mod", large_non_zero_r),
44 (quot, "quot", large_non_zero_r),
45 (rem, "rem", large_non_zero_r),
46 (gcd, "gcd", either_non_zero),
47 (lcm, "lcm", either_non_zero)
50 int_ops :: [((Int -> Int -> Int), String, [(Int,Int)])]
54 ((^), "(^)", small_non_neg_r),
55 (div, "div", non_min_l_or_zero_r),
56 (mod, "mod", non_min_l_or_zero_r),
57 (quot, "quot", non_min_l_or_zero_r),
58 (rem, "rem", non_min_l_or_zero_r),
59 (gcd, "gcd", either_non_zero),
60 (lcm, "lcm", non_max_r_either_non_zero)
63 all_ok, non_zero_r, either_non_zero, non_min_l_or_zero_r,
64 non_max_r_either_non_zero, small_non_neg_r
65 :: Integral a => [(a,a)]
67 all_ok = [ (l,r) | l <- operands, r <- operands ]
68 large_non_zero_r = [ (l,r) | l <- operands, r <- large_operands, r /= 0 ]
69 non_zero_r = [ (l,r) | l <- operands, r <- operands, r /= 0 ]
70 either_non_zero = [ (l,r) | l <- operands, r <- operands, l /= 0 || r /= 0 ]
71 small_non_neg_r = [ (l,r) | l <- operands, r <- small_operands, r >= 0 ]
72 non_min_l_or_zero_r = [ (l,r) | l <- non_min_operands, r <- operands, r /= 0 ]
73 non_max_r_either_non_zero = [ (l,r) | l <- operands, r <- non_max_operands, l /= 0 || r /= 0 ]
75 minInt = minBound :: Int
76 maxInt = maxBound :: Int