1 | {-# LANGUAGE NoMonomorphismRestriction #-} |
---|
2 | |
---|
3 | module Tests.SizeTest where |
---|
4 | |
---|
5 | import Size |
---|
6 | import Lambda |
---|
7 | import Ops |
---|
8 | import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool, String, const ) |
---|
9 | import qualified Control.Monad |
---|
10 | |
---|
11 | testEmpty1 :: (Size l) => l [Unsized] |
---|
12 | testEmpty1 = list (lit 0) (lam $ const unsized) |
---|
13 | |
---|
14 | testNil :: (Size l) => l [a] |
---|
15 | testNil = list (lit 0) (lam $ const bottom) |
---|
16 | |
---|
17 | testHead :: (Size l) => l ([a] -> a) |
---|
18 | testHead = slam $ \s f -> f `app` (s - lit 1) |
---|
19 | |
---|
20 | testTail :: (Size l) => l ([a] -> [a]) |
---|
21 | testTail = slam $ \s f -> list (s - lit 1) f |
---|
22 | |
---|
23 | testCons :: Size l => l (a -> [a] -> [a]) |
---|
24 | testCons = lam $ \x -> slam $ \s f -> |
---|
25 | list (s + lit 1) $ shift f s (lam $ const x) |
---|
26 | |
---|
27 | checkAst :: S a -> String -> IO Bool |
---|
28 | checkAst exp repr = ast exp >>= (\t -> return $ t "" == repr) |
---|
29 | |
---|
30 | tests :: [IO Bool] |
---|
31 | tests = [ |
---|
32 | checkAst testEmpty1 "List 0 (λa.U)" |
---|
33 | , checkAst testNil "List 0 (λa.âŽ)" |
---|
34 | , checkAst testHead "Îa,b.b (a-1)" |
---|
35 | , checkAst testTail "Îa,b.List (a-1) b" |
---|
36 | , checkAst testCons "λa.Îb,c.List (b+1) (Shift c b (λd.a))" |
---|
37 | ] |
---|
38 | |
---|
39 | runTests :: IO Bool |
---|
40 | runTests = Control.Monad.liftM and $ sequence tests |
---|