-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.hs
executable file
·147 lines (122 loc) · 4.72 KB
/
Tests.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{-# LANGUAGE NoMonomorphismRestriction #-}
module Tests where
import Test.QuickCheck
import Analyser
import Evaluator
import LambdaCalculus
import Data.List
--import AlgorithmW
--import TypeChecker
-- deepCheck :: (Testable a) => a -> IO ()
-- deepCheck = check (defaultConfig { configMaxTest = 1000})
-- splitConcat :: (Ord a) => [a] -> Maybe Bool
-- splitConcat x = do
-- (b, v, a) <- split x
-- return $ (b ++ [v] ++ a) == x
-- defaultMaybe :: t -> Maybe t -> t
-- defaultMaybe _ (Just x) = x
-- defaultMaybe x Nothing = x
-- prop_SplitConcat :: (Ord a) => [a] -> Property
-- prop_SplitConcat x = (x /= []) ==> defaultMaybe False . splitConcat $ x
-- commonOperators =
-- ["let closed ( x ) = x",
-- "let infixr 1 a + b = add a b",
-- "let infixr 2 a * b = times a b",
-- "let infixr 1 a - b = sub a b",
-- "let infixr 2 a == b = equals a b"]
-- --main :: IO ()
-- --main = deepCheck (prop_SplitConcat:: [Int] -> Property)
-- factorialN = executeProgram
-- "let closed ( x ) = x \
-- \let rec suffix n ! = \
-- \ if (equals 0 n) \
-- \ 1 \
-- \ (times n ((sub n 1)!)) \
-- \main = 5!"
-- factorial :: Bool
-- factorial = executeProgram
-- "let closed ( x ) = x \
-- \let rec suffix n ! = \
-- \ if (equals 0 n) \
-- \ 1 \
-- \ (times n ((sub n 1)!)) \
-- \main = 5!" == Right (Const $ IData 120)
-- powProgram = commonOperators ++
-- ["let rec infixl x ^ n = ",
-- "if (0 == n)",
-- "1",
-- "(x * (x ^ (n - 1)))",
-- "main = 5^2"
-- ]
-- -- Simple example describing infix operator syntax
-- pow :: Bool
-- pow = executeList powProgram == Right (Const $ IData 25)
-- int :: Integer -> Analyser.ExprTree
-- int = Value . IPrim
-- -- Parameters are evaluated as needed in whnf. Passing _|_
-- -- Doesn't cause non termination.
-- lazinessN =
-- commonOperators
-- ++ ["let rec x = x ",
-- "main = if (1 == 1) 2 x"]
-- laziness :: Bool
-- laziness = executeList lazinessN == Right (Const $ IData 2)
-- ambiguousOpN = commonOperators
-- ++ ["let ++ x = x + 1",
-- "main = 1 +++++++ 3"]
-- -- Test for resolving ambiguous operators.
-- -- "+++++++" can be interpreted in a number of ways. Given the current environment
-- -- the only one that has some sense is (1 + (++(++(++ 3)))) nano is able of discovering this.
-- ambiguousOp :: Bool
-- ambiguousOp = executeList ambiguousOpN == Right (Const $ IData 7)
-- -- Other examples.
-- closedOps :: Either [Char] LambdaCalculus.Expr
-- closedOps = executeList
-- ["let incr = 1",
-- "let suffix x ! = incr + x",
-- "let closed < x > = x!!!!",
-- "main = <1+2*3>!"]
-- prefixOp :: Either [Char] LambdaCalculus.Expr
-- prefixOp = executeList
-- ["let add x y = x + y",
-- "main = add 5 6"]
-- precedence :: Either [Char] LambdaCalculus.Expr
-- precedence = executeList
-- ["main = (1+3)+(3*2)+( 7 + 5 )",
-- " + ( 8 + 9 ) + ( 6 * 7 )",
-- "+ ( 3 + 3 ) + ( 2 + 3 * ",
-- "(1+3)+(3*2)+( 7 + 5 ) + ( 8 + 9 )",
-- "+ ( 6 * 7 ) + ( 3 + 3 ) + ( 2 + 3 ) )"]
-- tests :: [([Char], Bool)]
-- tests = [("factorial", factorial),
-- ("pow", pow),
-- ("laziness",laziness),
-- ("ambiguousOp",ambiguousOp),
-- ("pairTest", pairTest == Right (Const (IData 7))),
-- ("listTest", listTest == Right (Const (IData 1))),
-- ("listLength", listLength == Right (Const (IData 4)))
-- ]
-- failed :: [[Char]]
-- failed = map fst $ filter (not . snd) tests
-- executeList :: [[Char]] -> Either [Char] LambdaCalculus.Expr
-- executeList = executeProgram . intercalate "\n"
-- typeTest :: Either [Char] LambdaCalculus.Expr
-- typeTest = executeList
-- ["main = 5 + (6 == 3)"]
-- pairTest :: Either [Char] LambdaCalculus.Expr
-- pairTest = executeList $
-- commonOperators ++ ["let pair = buildPair 5 (6 == 3)",
-- "main = if (snd pair) (fst pair + 3) (fst pair + 2)"
-- ]
-- -- Yep... infinite list + obfuscation via concatenation of operators
-- listTest :: Either [Char] LambdaCalculus.Expr
-- listTest = executeList
-- ["let rec l = cons 1 l",
-- "main = hdrestrestrest l"
-- ]
-- listLength :: Either [Char] LambdaCalculus.Expr
-- listLength = executeList $
-- commonOperators ++
-- ["let rec closed [| l |] = if (isNull l) 0 (1 + [|rest l|] )",
-- "main = [|cons 5 cons 6 empty|] + [|cons 3 cons 2 empty|]"
-- ]