Commit ca8f2364 authored by sewardj's avatar sewardj
Browse files

[project @ 2001-06-26 11:53:11 by sewardj]

Add the numeric/ tests.
parent 58bbfc5d
include ($confdir ++ "/../vanilla-test.T")
-- Args to vt are: extra compile flags
-- extra run flags
-- expected process return value, if not zero
test "arith001" { vt("", "", "") }
test "arith002" { vt("", "", "") }
test "arith003" { vt("", "", "") }
test "arith004" { vt("", "", "") }
test "arith005" { vt("", "", "") }
test "arith006" { vt("-package lang", "", "") }
test "arith007" { vt("", "", "") }
test "arith008" { vt("", "", "") }
test "arith009" { vt("", "", "") }
test "arith010" { vt("-package lang", "", "") }
test "arith011" { vt("-package lang", "", "") }
test "arith012" { vt("-package lang", "", "") }
test "arith013" { vt("", "", "") }
test "num001" { vt("", "", "") }
test "num002" { vt("", "", "") }
test "num003" { vt("", "", "") }
test "num004" { vt("", "", "") }
test "num005" { vt("", "", "") }
test "num006" { vt("-package lang", "", "") }
test "num007" { vt("", "", "") }
test "num008" { vt("", "", "") }
test "num009" { vt("", "", "") }
test "num010" { vt("", "", "") }
test "num011" { vt("", "", "") }
-- !!! conversions: Double <=> Rational/Integer things
--
import Ratio
main = putStr (show r42 ++ "\n" ++
show nu42 ++ ", " ++
show de42 ++ "\n" ++
show nu42d ++ ", " ++
show de42d ++ "\n" ++
show s2 ++ ", " ++
show e2 ++ "\n" ++
show s ++ ", " ++
show e ++ "\n" )
where
d42 :: Double
r42 :: Rational
nu42, de42 :: Integer
nu42d, de42d :: Double
d42 = 42
r42 = toRational d42
nu42 = numerator r42
de42 = denominator r42
nu42d= fromInteger nu42
de42d= fromInteger de42
(s,e)= decodeFloat (nu42d / de42d )
(s2,e2) = decodeFloat d42
42 % 1
42, 1
42.0, 1.0
5910974510923776, -47
5910974510923776, -47
-- !!! basic Rational operations
--
import Ratio
main
= putStr
(-- Ratio Ints
show [i0a, i0b, i0c, i2a, i2b, im2a, im2b, i_pi, i_misc]
++ "\n"
-- the Ints
++ show ((map numerator [i0a, i0b, i0c, i2a, i2b, im2a, im2b, i_pi, i_misc])
++(map denominator [i0a, i0b, i0c, i2a, i2b, im2a, im2b, i_pi, i_misc]))
++ "\n"
-- Booleans
-- ++ show []
-- ++ "\n"
-- Rationals (Ratio Integers)
++ show [r0a, r0b, r0c, r2a, r2b, rm2a, rm2b, r_pi, r_misc]
++ "\n"
-- the Integers
++ show ((map numerator [r0a, r0b, r0c, r2a, r2b, rm2a, rm2b, r_pi, r_misc])
++(map denominator [r0a, r0b, r0c, r2a, r2b, rm2a, rm2b, r_pi, r_misc]))
++ "\n"
-- Booleans
-- ++ show []
-- ++ "\n"
)
where
i0a, i0b, i0c, i2a, i2b, im2a, im2b, i_pi, i_misc :: Ratio Int
i0a = 0 % 1
i0b = (-0) % 1
i0c = 0 % (-1)
i2a = 4 % 2
i2b = (-4) % (-2)
im2a = (-4) % 2
im2b = 4 % (-2)
i_pi = 22 % 7
i_misc = 2 % 10000
r0a, r0b, r0c, r2a, r2b, rm2a, rm2b, r_pi, r_misc :: Rational
r0a = 0 % 1
r0b = (-0) % 1
r0c = 0 % (-1)
r2a = 4 % 2
r2b = (-4) % (-2)
rm2a = (-4) % 2
rm2b = 4 % (-2)
r_pi = 22 % 7
r_misc = 2 % 10000
[0 % 1,0 % 1,0 % 1,2 % 1,2 % 1,-2 % 1,-2 % 1,22 % 7,1 % 5000]
[0,0,0,2,2,-2,-2,22,1,1,1,1,1,1,1,1,7,5000]
[0 % 1,0 % 1,0 % 1,2 % 1,2 % 1,-2 % 1,-2 % 1,22 % 7,1 % 5000]
[0,0,0,2,2,-2,-2,22,1,1,1,1,1,1,1,1,7,5000]
-- $Id: arith003.hs,v 1.1 2001/06/26 11:53:11 sewardj Exp $
--
-- !!! test Int/Integer arithmetic operations from the Prelude.
--
main
= putStr
(
showit (do_ops int_ops) ++
showit (do_ops integer_ops)
)
showit :: Integral a => [(String, a, a, a)] -> String
showit stuff = concat
[ str ++ " " ++ show l ++ " " ++ show r ++ " = " ++ show result ++ "\n"
| (str, l, r, result) <- stuff
]
do_ops :: Integral a => [((a -> a -> a), String, [(a,a)])]
-> [(String, a, a, a)]
do_ops ops = [ (str, l, r, l `op` r) | (op,str,args) <- ops, (l,r) <- args ]
small_operands, non_min_operands, operands, non_max_operands
:: Integral a => [a]
small_operands = [ 0, 1, -1, 2, -2 ]
operands = small_operands ++ [ fromIntegral minInt, fromIntegral maxInt ]
non_min_operands = small_operands ++ [ fromIntegral maxInt ]
non_max_operands = small_operands ++ [ fromIntegral minInt ]
large_operands :: [ Integer ]
large_operands = operands ++
[ fromIntegral minInt - 1,
fromIntegral maxInt + 1,
fromIntegral minInt * 2,
fromIntegral maxInt * 2,
fromIntegral minInt ^ 2,
fromIntegral maxInt ^ 2
]
integer_ops :: [((Integer -> Integer -> Integer), String, [(Integer,Integer)])]
integer_ops = [
((+), "(+)", all_ok),
((-), "(-)", all_ok),
(div, "div", large_non_zero_r),
(mod, "mod", large_non_zero_r),
(quot, "quot", large_non_zero_r),
(rem, "rem", large_non_zero_r),
(gcd, "gcd", either_non_zero),
(lcm, "lcm", either_non_zero)
]
int_ops :: [((Int -> Int -> Int), String, [(Int,Int)])]
int_ops = [
((+), "(+)", all_ok),
((-), "(-)", all_ok),
((^), "(^)", small_non_neg_r),
(div, "div", non_min_l_or_zero_r),
(mod, "mod", non_min_l_or_zero_r),
(quot, "quot", non_min_l_or_zero_r),
(rem, "rem", non_min_l_or_zero_r),
(gcd, "gcd", either_non_zero),
(lcm, "lcm", non_max_r_either_non_zero)
]
all_ok, non_zero_r, either_non_zero, non_min_l_or_zero_r,
non_max_r_either_non_zero, small_non_neg_r
:: Integral a => [(a,a)]
all_ok = [ (l,r) | l <- operands, r <- operands ]
large_non_zero_r = [ (l,r) | l <- operands, r <- large_operands, r /= 0 ]
non_zero_r = [ (l,r) | l <- operands, r <- operands, r /= 0 ]
either_non_zero = [ (l,r) | l <- operands, r <- operands, l /= 0 || r /= 0 ]
small_non_neg_r = [ (l,r) | l <- operands, r <- small_operands, r >= 0 ]
non_min_l_or_zero_r = [ (l,r) | l <- non_min_operands, r <- operands, r /= 0 ]
non_max_r_either_non_zero = [ (l,r) | l <- operands, r <- non_max_operands, l /= 0 || r /= 0 ]
minInt = minBound :: Int
maxInt = maxBound :: Int
(+) 0 0 = 0
(+) 0 1 = 1
(+) 0 -1 = -1
(+) 0 2 = 2
(+) 0 -2 = -2
(+) 0 -2147483648 = -2147483648
(+) 0 2147483647 = 2147483647
(+) 1 0 = 1
(+) 1 1 = 2
(+) 1 -1 = 0
(+) 1 2 = 3
(+) 1 -2 = -1
(+) 1 -2147483648 = -2147483647
(+) 1 2147483647 = -2147483648
(+) -1 0 = -1
(+) -1 1 = 0
(+) -1 -1 = -2
(+) -1 2 = 1
(+) -1 -2 = -3
(+) -1 -2147483648 = 2147483647
(+) -1 2147483647 = 2147483646
(+) 2 0 = 2
(+) 2 1 = 3
(+) 2 -1 = 1
(+) 2 2 = 4
(+) 2 -2 = 0
(+) 2 -2147483648 = -2147483646
(+) 2 2147483647 = -2147483647
(+) -2 0 = -2
(+) -2 1 = -1
(+) -2 -1 = -3
(+) -2 2 = 0
(+) -2 -2 = -4
(+) -2 -2147483648 = 2147483646
(+) -2 2147483647 = 2147483645
(+) -2147483648 0 = -2147483648
(+) -2147483648 1 = -2147483647
(+) -2147483648 -1 = 2147483647
(+) -2147483648 2 = -2147483646
(+) -2147483648 -2 = 2147483646
(+) -2147483648 -2147483648 = 0
(+) -2147483648 2147483647 = -1
(+) 2147483647 0 = 2147483647
(+) 2147483647 1 = -2147483648
(+) 2147483647 -1 = 2147483646
(+) 2147483647 2 = -2147483647
(+) 2147483647 -2 = 2147483645
(+) 2147483647 -2147483648 = -1
(+) 2147483647 2147483647 = -2
(-) 0 0 = 0
(-) 0 1 = -1
(-) 0 -1 = 1
(-) 0 2 = -2
(-) 0 -2 = 2
(-) 0 -2147483648 = -2147483648
(-) 0 2147483647 = -2147483647
(-) 1 0 = 1
(-) 1 1 = 0
(-) 1 -1 = 2
(-) 1 2 = -1
(-) 1 -2 = 3
(-) 1 -2147483648 = -2147483647
(-) 1 2147483647 = -2147483646
(-) -1 0 = -1
(-) -1 1 = -2
(-) -1 -1 = 0
(-) -1 2 = -3
(-) -1 -2 = 1
(-) -1 -2147483648 = 2147483647
(-) -1 2147483647 = -2147483648
(-) 2 0 = 2
(-) 2 1 = 1
(-) 2 -1 = 3
(-) 2 2 = 0
(-) 2 -2 = 4
(-) 2 -2147483648 = -2147483646
(-) 2 2147483647 = -2147483645
(-) -2 0 = -2
(-) -2 1 = -3
(-) -2 -1 = -1
(-) -2 2 = -4
(-) -2 -2 = 0
(-) -2 -2147483648 = 2147483646
(-) -2 2147483647 = 2147483647
(-) -2147483648 0 = -2147483648
(-) -2147483648 1 = 2147483647
(-) -2147483648 -1 = -2147483647
(-) -2147483648 2 = 2147483646
(-) -2147483648 -2 = -2147483646
(-) -2147483648 -2147483648 = 0
(-) -2147483648 2147483647 = 1
(-) 2147483647 0 = 2147483647
(-) 2147483647 1 = 2147483646
(-) 2147483647 -1 = -2147483648
(-) 2147483647 2 = 2147483645
(-) 2147483647 -2 = -2147483647
(-) 2147483647 -2147483648 = -1
(-) 2147483647 2147483647 = 0
(^) 0 0 = 1
(^) 0 1 = 0
(^) 0 2 = 0
(^) 1 0 = 1
(^) 1 1 = 1
(^) 1 2 = 1
(^) -1 0 = 1
(^) -1 1 = -1
(^) -1 2 = 1
(^) 2 0 = 1
(^) 2 1 = 2
(^) 2 2 = 4
(^) -2 0 = 1
(^) -2 1 = -2
(^) -2 2 = 4
(^) -2147483648 0 = 1
(^) -2147483648 1 = -2147483648
(^) -2147483648 2 = 0
(^) 2147483647 0 = 1
(^) 2147483647 1 = 2147483647
(^) 2147483647 2 = 1
div 0 1 = 0
div 0 -1 = 0
div 0 2 = 0
div 0 -2 = 0
div 0 -2147483648 = 0
div 0 2147483647 = 0
div 1 1 = 1
div 1 -1 = -1
div 1 2 = 0
div 1 -2 = -1
div 1 -2147483648 = 1
div 1 2147483647 = 0
div -1 1 = -1
div -1 -1 = 1
div -1 2 = -1
div -1 -2 = 0
div -1 -2147483648 = 0
div -1 2147483647 = -1
div 2 1 = 2
div 2 -1 = -2
div 2 2 = 1
div 2 -2 = -1
div 2 -2147483648 = 0
div 2 2147483647 = 0
div -2 1 = -2
div -2 -1 = 2
div -2 2 = -1
div -2 -2 = 1
div -2 -2147483648 = 0
div -2 2147483647 = -1
div 2147483647 1 = 2147483647
div 2147483647 -1 = -2147483647
div 2147483647 2 = 1073741823
div 2147483647 -2 = 1073741824
div 2147483647 -2147483648 = 0
div 2147483647 2147483647 = 1
mod 0 1 = 0
mod 0 -1 = 0
mod 0 2 = 0
mod 0 -2 = 0
mod 0 -2147483648 = 0
mod 0 2147483647 = 0
mod 1 1 = 0
mod 1 -1 = 0
mod 1 2 = 1
mod 1 -2 = -1
mod 1 -2147483648 = -2147483647
mod 1 2147483647 = 1
mod -1 1 = 0
mod -1 -1 = 0
mod -1 2 = 1
mod -1 -2 = -1
mod -1 -2147483648 = -1
mod -1 2147483647 = 2147483646
mod 2 1 = 0
mod 2 -1 = 0
mod 2 2 = 0
mod 2 -2 = 0
mod 2 -2147483648 = -2147483646
mod 2 2147483647 = 2
mod -2 1 = 0
mod -2 -1 = 0
mod -2 2 = 0
mod -2 -2 = 0
mod -2 -2147483648 = -2
mod -2 2147483647 = 2147483645
mod 2147483647 1 = 0
mod 2147483647 -1 = 0
mod 2147483647 2 = 1
mod 2147483647 -2 = -1
mod 2147483647 -2147483648 = -1
mod 2147483647 2147483647 = 0
quot 0 1 = 0
quot 0 -1 = 0
quot 0 2 = 0
quot 0 -2 = 0
quot 0 -2147483648 = 0
quot 0 2147483647 = 0
quot 1 1 = 1
quot 1 -1 = -1
quot 1 2 = 0
quot 1 -2 = 0
quot 1 -2147483648 = 0
quot 1 2147483647 = 0
quot -1 1 = -1
quot -1 -1 = 1
quot -1 2 = 0
quot -1 -2 = 0
quot -1 -2147483648 = 0
quot -1 2147483647 = 0
quot 2 1 = 2
quot 2 -1 = -2
quot 2 2 = 1
quot 2 -2 = -1
quot 2 -2147483648 = 0
quot 2 2147483647 = 0
quot -2 1 = -2
quot -2 -1 = 2
quot -2 2 = -1
quot -2 -2 = 1
quot -2 -2147483648 = 0
quot -2 2147483647 = 0
quot 2147483647 1 = 2147483647
quot 2147483647 -1 = -2147483647
quot 2147483647 2 = 1073741823
quot 2147483647 -2 = -1073741823
quot 2147483647 -2147483648 = 0
quot 2147483647 2147483647 = 1
rem 0 1 = 0
rem 0 -1 = 0
rem 0 2 = 0
rem 0 -2 = 0
rem 0 -2147483648 = 0
rem 0 2147483647 = 0
rem 1 1 = 0
rem 1 -1 = 0
rem 1 2 = 1
rem 1 -2 = 1
rem 1 -2147483648 = 1
rem 1 2147483647 = 1
rem -1 1 = 0
rem -1 -1 = 0
rem -1 2 = -1
rem -1 -2 = -1
rem -1 -2147483648 = -1
rem -1 2147483647 = -1
rem 2 1 = 0
rem 2 -1 = 0
rem 2 2 = 0
rem 2 -2 = 0
rem 2 -2147483648 = 2
rem 2 2147483647 = 2
rem -2 1 = 0
rem -2 -1 = 0
rem -2 2 = 0
rem -2 -2 = 0
rem -2 -2147483648 = -2
rem -2 2147483647 = -2
rem 2147483647 1 = 0
rem 2147483647 -1 = 0
rem 2147483647 2 = 1
rem 2147483647 -2 = 1
rem 2147483647 -2147483648 = 2147483647
rem 2147483647 2147483647 = 0
gcd 0 1 = 1
gcd 0 -1 = 1
gcd 0 2 = 2
gcd 0 -2 = 2
gcd 0 -2147483648 = -2147483648
gcd 0 2147483647 = 2147483647
gcd 1 0 = 1
gcd 1 1 = 1
gcd 1 -1 = 1
gcd 1 2 = 1
gcd 1 -2 = 1
gcd 1 -2147483648 = 1
gcd 1 2147483647 = 1
gcd -1 0 = 1
gcd -1 1 = 1
gcd -1 -1 = 1
gcd -1 2 = 1
gcd -1 -2 = 1
gcd -1 -2147483648 = 1
gcd -1 2147483647 = 1
gcd 2 0 = 2
gcd 2 1 = 1
gcd 2 -1 = 1
gcd 2 2 = 2
gcd 2 -2 = 2
gcd 2 -2147483648 = 2
gcd 2 2147483647 = 1
gcd -2 0 = 2
gcd -2 1 = 1
gcd -2 -1 = 1
gcd -2 2 = 2
gcd -2 -2 = 2
gcd -2 -2147483648 = 2
gcd -2 2147483647 = 1
gcd -2147483648 0 = -2147483648
gcd -2147483648 1 = 1
gcd -2147483648 -1 = 1
gcd -2147483648 2 = 2
gcd -2147483648 -2 = 2
gcd -2147483648 -2147483648 = -2147483648
gcd -2147483648 2147483647 = -1
gcd 2147483647 0 = 2147483647
gcd 2147483647 1 = 1
gcd 2147483647 -1 = 1
gcd 2147483647 2 = 1
gcd 2147483647 -2 = 1
gcd 2147483647 -2147483648 = -1
gcd 2147483647 2147483647 = 2147483647
lcm 0 1 = 0
lcm 0 -1 = 0
lcm 0 2 = 0
lcm 0 -2 = 0
lcm 0 -2147483648 = 0
lcm 1 0 = 0
lcm 1 1 = 1
lcm 1 -1 = 1
lcm 1 2 = 2
lcm 1 -2 = 2
lcm 1 -2147483648 = -2147483648
lcm -1 0 = 0
lcm -1 1 = 1
lcm -1 -1 = 1
lcm -1 2 = 2
lcm -1 -2 = 2
lcm -1 -2147483648 = -2147483648
lcm 2 0 = 0
lcm 2 1 = 2
lcm 2 -1 = 2
lcm 2 2 = 2
lcm 2 -2 = 2
lcm 2 -2147483648 = -2147483648
lcm -2 0 = 0
lcm -2 1 = 2
lcm -2 -1 = 2
lcm -2 2 = 2
lcm -2 -2 = 2
lcm -2 -2147483648 = -2147483648
lcm -2147483648 0 = 0
lcm -2147483648 1 = -2147483648
lcm -2147483648 -1 = -2147483648
lcm -2147483648 2 = -2147483648
lcm -2147483648 -2 = -2147483648
lcm -2147483648 -2147483648 = -2147483648
lcm 2147483647 0 = 0
lcm 2147483647 1 = 2147483647
lcm 2147483647 -1 = 2147483647
lcm 2147483647 2 = 2
lcm 2147483647 -2 = 2
lcm 2147483647 -2147483648 = -2147483648
(+) 0 0 = 0
(+) 0 1 = 1
(+) 0 -1 = -1
(+) 0 2 = 2
(+) 0 -2 = -2
(+) 0 -2147483648 = -2147483648
(+) 0 2147483647 = 2147483647
(+) 1 0 = 1
(+) 1 1 = 2
(+) 1 -1 = 0
(+) 1 2 = 3
(+) 1 -2 = -1
(+) 1 -2147483648 = -2147483647
(+) 1 2147483647 = 2147483648
(+) -1 0 = -1
(+) -1 1 = 0
(+) -1 -1 = -2
(+) -1 2 = 1
(+) -1 -2 = -3
(+) -1 -2147483648 = -2147483649
(+) -1 2147483647 = 2147483646
(+) 2 0 = 2
(+) 2 1 = 3
(+) 2 -1 = 1
(+) 2 2 = 4
(+) 2 -2 = 0
(+) 2 -2147483648 = -2147483646
(+) 2 2147483647 = 2147483649
(+) -2 0 = -2
(+) -2 1 = -1
(+) -2 -1 = -3
(+) -2 2 = 0
(+) -2 -2 = -4
(+) -2 -2147483648 = -2147483650
(+) -2 2147483647 = 2147483645
(+) -2147483648 0 = -2147483648
(+) -2147483648 1 = -2147483647
(+) -2147483648 -1 = -2147483649
(+) -2147483648 2 = -2147483646
(+) -2147483648 -2 = -2147483650
(+) -2147483648 -2147483648 = -4294967296
(+) -2147483648 2147483647 = -1
(+) 2147483647 0 = 2147483647