[22] | 1 | {-# LANGUAGE NoMonomorphismRestriction #-} |
---|
| 2 | |
---|
| 3 | module Tests.ExpTest where |
---|
| 4 | |
---|
| 5 | import Lambda |
---|
| 6 | import Exp |
---|
| 7 | import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) |
---|
[23] | 8 | import qualified Control.Monad |
---|
[22] | 9 | |
---|
| 10 | testNil :: Exp e => e [a] |
---|
| 11 | testNil = nil |
---|
| 12 | |
---|
[23] | 13 | testAddOne :: Exp e => e ([Int] -> [Int]) |
---|
| 14 | testAddOne = lam $ \l -> cons (const 1) l |
---|
| 15 | |
---|
| 16 | testHead :: Exp e => e ([a] -> a) |
---|
| 17 | testHead = lam $ \l -> match l undefined $ \x _ -> x |
---|
| 18 | |
---|
| 19 | testTail :: Exp e => e ([a] -> [a]) |
---|
| 20 | testTail = lam $ \l -> match l undefined $ \_ xs -> xs |
---|
| 21 | |
---|
| 22 | testConcat :: Exp e => e ([a] -> [a] -> [a]) |
---|
| 23 | testConcat = lam $ \l1 -> lam $ \l2 -> match l1 l2 |
---|
| 24 | $ \x xs -> cons x (testConcat `app` xs `app` l2) |
---|
| 25 | |
---|
| 26 | testEvalNil :: IO Bool |
---|
| 27 | testEvalNil = return $ ([]::[Int]) == eval testNil |
---|
| 28 | |
---|
| 29 | testEvalAddOne :: IO Bool |
---|
| 30 | testEvalAddOne = return $ [1::Int] == (eval $ testAddOne `app` nil) |
---|
| 31 | |
---|
| 32 | testEvalTail :: IO Bool |
---|
| 33 | testEvalTail = return $ [2..6::Int] == eval testTail [1..6] |
---|
| 34 | |
---|
| 35 | testEvalConcat :: IO Bool |
---|
| 36 | testEvalConcat = return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6] |
---|
| 37 | |
---|
| 38 | tests :: [IO Bool] |
---|
| 39 | |
---|
| 40 | tests = [ testEvalNil |
---|
| 41 | , testEvalAddOne |
---|
| 42 | , testEvalTail |
---|
| 43 | , testEvalConcat |
---|
| 44 | ] |
---|
| 45 | |
---|
| 46 | runTests :: IO Bool |
---|
| 47 | runTests = Control.Monad.liftM and $ sequence tests |
---|