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

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

Expressions

File size: 1.0 KB
RevLine 
[21]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 -> const 3 + x) (const 2)
12
[22]13test2 :: (LOps l) => l Int
14test2 = app (lam $ \x -> const 3 * x) (const 2)
15
16test3 :: (LOps l) => l Int
17test3 = app (lam $ \x -> const 2 * x + const 1) (const 5 - const 2)
18
19
[21]20test1ast :: IO Bool
21test1ast = do
22    t <- ast test1
23    return $ t "" == "(λa.3+a) 2"
[22]24
[21]25test1eval :: IO Bool
26test1eval = return $ eval test1 == 5
27
[22]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
[21]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.