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

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

new files

File size: 1.4 KB
RevLine 
[22]1{-# LANGUAGE NoMonomorphismRestriction #-}
2
3module Tests.ExpTest where
4
5import Lambda
6import Exp
[24]7import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const )
[23]8import qualified Control.Monad
[22]9
10testNil :: Exp e => e [a]
11testNil = nil
12
[23]13testAddOne :: Exp e => e ([Int] -> [Int])
[24]14testAddOne = lam $ \l -> cons (lit 1) l
[23]15
16testHead :: Exp e => e ([a] -> a)
[24]17testHead = lam $ \l -> match l undefined const
[23]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
[24]26testDCons :: Exp e => e [Int]
27testDCons = cons (lit 1) $ cons (lit 2) nil
[23]28
[24]29testD2Cons :: Exp e => e [[Int]]
30testD2Cons = cons (cons (lit 1) nil) nil
[23]31
[27]32checkAST :: S SData a -> String -> IO Bool
[24]33checkAST exp repr = ast exp >>= (\t -> return $ t "" == repr )
[23]34
[24]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    ]
[23]48
49
50runTests :: IO Bool
51runTests = Control.Monad.liftM and $ sequence tests
Note: See TracBrowser for help on using the repository browser.