Ignore:
Timestamp:
May 3, 2014, 6:38:40 PM (11 years ago)
Author:
gobi
Message:

expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sizechecking/branches/macs/tests/ExpTest.hs

    r23 r24  
    55import Lambda 
    66import Exp 
    7 import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) 
     7import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) 
    88import qualified Control.Monad 
    99 
     
    1212 
    1313testAddOne :: Exp e => e ([Int] -> [Int]) 
    14 testAddOne = lam $ \l -> cons (const 1) l 
     14testAddOne = lam $ \l -> cons (lit 1) l 
    1515 
    1616testHead :: Exp e => e ([a] -> a) 
    17 testHead = lam $ \l -> match l undefined $ \x _ -> x 
     17testHead = lam $ \l -> match l undefined const 
    1818 
    1919testTail :: Exp e => e ([a] -> [a]) 
     
    2424    $ \x xs -> cons x (testConcat `app` xs `app` l2) 
    2525 
    26 testEvalNil :: IO Bool 
    27 testEvalNil = return $ ([]::[Int]) == eval testNil 
     26testDCons :: Exp e => e [Int] 
     27testDCons = cons (lit 1) $ cons (lit 2) nil 
    2828 
    29 testEvalAddOne :: IO Bool 
    30 testEvalAddOne = return $ [1::Int] == (eval $ testAddOne `app` nil) 
     29testD2Cons :: Exp e => e [[Int]] 
     30testD2Cons = cons (cons (lit 1) nil) nil 
    3131 
    32 testEvalTail :: IO Bool 
    33 testEvalTail = return $ [2..6::Int] == eval testTail [1..6] 
     32checkAST :: S a -> String -> IO Bool 
     33checkAST exp repr = ast exp >>= (\t -> return $ t "" == repr ) 
    3434 
    35 testEvalConcat :: IO Bool 
    36 testEvalConcat = return $ [1..6::Int] == eval testConcat [1,2,3] [4,5,6]  
     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    ] 
    3748 
    38 tests :: [IO Bool] 
    39  
    40 tests = [ testEvalNil 
    41         , testEvalAddOne 
    42         , testEvalTail 
    43         , testEvalConcat 
    44         ] 
    4549 
    4650runTests :: IO Bool 
Note: See TracChangeset for help on using the changeset viewer.