Line | |
---|
1 | {-# LANGUAGE NoMonomorphismRestriction #-} |
---|
2 | |
---|
3 | module Tests.OpsTest where |
---|
4 | |
---|
5 | import Ops |
---|
6 | import Lambda |
---|
7 | import Prelude ( ($), Int, (==), return, sequence, (>>=), and, (.), IO, Bool ) |
---|
8 | import qualified Control.Monad |
---|
9 | |
---|
10 | test1 :: (LOps l) => l Int |
---|
11 | test1 = app (lam $ \x -> const 3 + x) (const 2) |
---|
12 | |
---|
13 | test2 :: (LOps l) => l Int |
---|
14 | test2 = app (lam $ \x -> const 3 * x) (const 2) |
---|
15 | |
---|
16 | test3 :: (LOps l) => l Int |
---|
17 | test3 = app (lam $ \x -> const 2 * x + const 1) (const 5 - const 2) |
---|
18 | |
---|
19 | |
---|
20 | test1ast :: IO Bool |
---|
21 | test1ast = do |
---|
22 | t <- ast test1 |
---|
23 | return $ t "" == "(λa.3+a) 2" |
---|
24 | |
---|
25 | test1eval :: IO Bool |
---|
26 | test1eval = return $ eval test1 == 5 |
---|
27 | |
---|
28 | test2ast :: IO Bool |
---|
29 | test2ast = do |
---|
30 | t <- ast test2 |
---|
31 | return $ t "" == "(λa.3*a) 2" |
---|
32 | |
---|
33 | test2eval :: IO Bool |
---|
34 | test2eval = return $ eval test2 == 6 |
---|
35 | |
---|
36 | test3ast :: IO Bool |
---|
37 | test3ast = do |
---|
38 | t <- ast test3 |
---|
39 | return $ t "" == "(λa.2*a+1) (5-2)" |
---|
40 | |
---|
41 | test3eval :: IO Bool |
---|
42 | test3eval = return $ eval test3 == 7 |
---|
43 | |
---|
44 | tests :: [IO Bool] |
---|
45 | tests = [ |
---|
46 | test1ast |
---|
47 | , test1eval |
---|
48 | ] |
---|
49 | |
---|
50 | runTests :: IO Bool |
---|
51 | runTests = Control.Monad.liftM and $ sequence tests |
---|
Note: See
TracBrowser
for help on using the repository browser.