source: sizechecking/branches/macs/Tests/ExpTest.hs @ 26

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

expressions

File size: 1.4 KB
Line 
1{-# LANGUAGE NoMonomorphismRestriction #-}
2
3module Tests.ExpTest where
4
5import Lambda
6import Exp
7import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const )
8import qualified Control.Monad
9
10testNil :: Exp e => e [a]
11testNil = nil
12
13testAddOne :: Exp e => e ([Int] -> [Int])
14testAddOne = lam $ \l -> cons (lit 1) l
15
16testHead :: Exp e => e ([a] -> a)
17testHead = lam $ \l -> match l undefined const
18
19testTail :: Exp e => e ([a] -> [a])
20testTail = lam $ \l -> match l undefined $ \_ xs -> xs
21
22testConcat :: Exp e => e ([a] -> [a] -> [a])
23testConcat = lam $ \l1 -> lam $ \l2 -> match l1 l2
24    $ \x xs -> cons x (testConcat `app` xs `app` l2)
25
26testDCons :: Exp e => e [Int]
27testDCons = cons (lit 1) $ cons (lit 2) nil
28
29testD2Cons :: Exp e => e [[Int]]
30testD2Cons = cons (cons (lit 1) nil) nil
31
32checkAST :: S a -> String -> IO Bool
33checkAST exp repr = ast exp >>= (\t -> return $ t "" == repr )
34
35tests :: [ IO Bool ]
36tests = 
37    [ return $ ([]::[Int]) == eval testNil
38    , checkAST testNil "[]"
39    , return $ [1::Int] == eval (testAddOne `app` nil)
40    , checkAST testAddOne "λa.1:a"
41    , return $ [2..6::Int] == eval testTail [1..6]
42    , return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6]
43    , return $ [1,2::Int] == eval testDCons
44    , checkAST testDCons "1:2:[]"
45    , return $ [[1::Int]] == eval testD2Cons
46    , checkAST testD2Cons "(1:[]):[]"
47    ]
48
49
50runTests :: IO Bool
51runTests = Control.Monad.liftM and $ sequence tests
Note: See TracBrowser for help on using the repository browser.