source: sizechecking/branches/macs/Tests/SizeTest.hs @ 29

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

new files

File size: 1.4 KB
Line 
1{-# LANGUAGE NoMonomorphismRestriction #-}
2
3module Tests.SizeTest where
4
5import Size
6import Lambda
7import Ops
8import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const )
9import qualified Control.Monad
10
11testEmpty1 :: (Size l) => l [Unsized]
12testEmpty1 = list (lit 0) (lam $ const unsized)
13
14testNil :: (Size l) => l [a]
15testNil = list (lit 0) (lam $ const bottom)
16
17testHead :: (Size l) => l ([a] -> a)
18testHead = slam $ \s f -> f `app` (s - lit 1)
19
20testTail :: (Size l) => l ([a] -> [a])
21testTail = slam $ \s f -> list (s - lit 1) f
22
23testAddOne :: (Size l) => l ([Unsized] -> [Unsized])
24testAddOne = slam $ \s f -> list (s + lit 1) (lam $ const unsized)
25
26testCons :: Size l => l (a -> [a] -> [a])
27testCons = lam $ \x -> slam $ \s f ->
28    list (s + lit 1) $ shift f s (lam $ const x)
29
30testConcat :: Size l => l ([a] -> [a] -> [a])
31testConcat = slam $ \s1 f1 -> slam $ \s2 f2 ->
32    list (s1 + s2) $ shift f1 s1 f2
33
34
35checkAst :: S SData a -> String -> IO Bool
36checkAst exp repr = ast exp >>= (\t -> return $ t "" == repr)
37
38tests :: [IO Bool]
39tests = [
40      checkAst testEmpty1 "List 0 (λa.U)"
41    , checkAst testNil "List 0 (λa.┮)"
42    , checkAst testHead "Λa,b.b (a-1)"
43    , checkAst testTail "Λa,b.List (a-1) b"
44    , checkAst testCons "λa.Λb,c.List (b+1) (Shift c b (λd.a))"
45    ]
46
47runTests :: IO Bool
48runTests = Control.Monad.liftM and $ sequence tests
Note: See TracBrowser for help on using the repository browser.