source: sizechecking/branches/macs/tests/OpsTest.hs @ 24

Last change on this file since 24 was 24, checked in by gobi, 11 years ago

expressions

File size: 1.0 KB
Line 
1{-# LANGUAGE NoMonomorphismRestriction #-}
2
3module Tests.OpsTest where
4
5import Ops
6import Lambda
7import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool )
8import qualified Control.Monad
9
10test1 :: (LOps l) => l Int
11test1 = app (lam $ \x -> lit 3 + x) (lit 2)
12
13test2 :: (LOps l) => l Int
14test2 = app (lam $ \x -> lit 3 * x) (lit 2)
15
16test3 :: (LOps l) => l Int
17test3 = app (lam $ \x -> lit 2 * x + lit 1) (lit 5 - lit 2)
18
19
20test1ast :: IO Bool
21test1ast = do
22    t <- ast test1
23    return $ t "" == "(λa.3+a) 2"
24
25test1eval :: IO Bool
26test1eval = return $ eval test1 == 5
27
28test2ast :: IO Bool
29test2ast = do
30    t <- ast test2
31    return $ t "" == "(λa.3*a) 2"
32
33test2eval :: IO Bool
34test2eval = return $ eval test2 == 6
35
36test3ast :: IO Bool
37test3ast = do
38    t <- ast test3
39    return $ t "" == "(λa.2*a+1) (5-2)"
40
41test3eval :: IO Bool
42test3eval = return $ eval test3 == 7
43
44tests :: [IO Bool]
45tests = [ 
46      test1ast
47    , test1eval
48    ]
49
50runTests :: IO Bool
51runTests = Control.Monad.liftM and $ sequence tests
Note: See TracBrowser for help on using the repository browser.