-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.hs
142 lines (113 loc) · 4.45 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
module Tests where
import IC.TestSuite hiding (Id)
import qualified IC.TestSuite as TS
import Calculus
evalTests
= [((Val 7), [("x",380)])
==> 7.0
, ((Id "a"), [("x",380), ("a",42), ("t",10)])
==> 42.0
, ( (BinApp Add (Val (-5)) (Id "t'")), [("t",10), ("t'",18)])
==> 13.0
, ((UnApp Neg (BinApp Add (Val (-5)) (Id "t'"))), [("t",10), ("t'",19)])
==> (-14.0)
, ((BinApp Mul (Id "x") (Id "x")), [("t",10), ("t'",18.6), ("x",-55)])
==> 3025.0
, ((BinApp Div (Val 3) (Id "z")), [("z",7)])
==> 0.42857142857142855
, ((UnApp Neg (Id "x")), [("x",0.37)])
==> (-0.37)
, ((Id "x"), [("x", 1)])
==> (1.0)
, ((UnApp Sin (Val 2.4)), [])
==> 0.675463180551151
, ((UnApp Cos (Val 2.4)), [])
==> (-0.7373937155412454)
, ( e1, [("x",0.37)])
==> (1.85)
, ( e2, [("x",0.37), ("y", 8.2)])
==> 1.3369
, ( e3, [("x",0.37), ("y", 2.0)])
==> 4.216153846153846
, ( e4, [("x",0.37)])
==> (-0.9323273456060345)
, ( e5, [("x",0.37)])
==> 0.6433720724587564
, ( e6, [("x",0.37)])
==> 0.8799171617597958
]
diffTests
= [ (e1, "x") ==>
BinApp Add (BinApp Mul (Val 5.0) (Val 1.0)) (BinApp Mul (Val 0.0)
(Id "x"))
, (e2, "x") ==>
BinApp Add (BinApp Add (BinApp Add (BinApp Mul (Id "x") (Val 1.0))
(BinApp Mul (Val 1.0) (Id "x"))) (Val 0.0))
(UnApp Neg (Val 0.0))
, (e2, "y") ==>
BinApp Add (BinApp Add (BinApp Add (BinApp Mul (Id "x") (Val 0.0))
(BinApp Mul (Val 0.0) (Id "x"))) (Val 1.0))
(UnApp Neg (Val 0.0))
, (e4, "x") ==>
UnApp Neg (UnApp Neg (BinApp Mul (UnApp Sin (Id "x")) (Val 1.0)))
, (e5, "x") ==>
BinApp Mul (UnApp Cos (BinApp Add (Val 1.0)
(UnApp Log (BinApp Mul (Val 2.0)
(Id "x")))))
(BinApp Add (Val 0.0)
(BinApp Div (BinApp Add (BinApp Mul (Val 2.0)
(Val 1.0))
(BinApp Mul (Val 0.0) (Id "x")))
(BinApp Mul (Val 2.0) (Id "x"))))
, (e6, "x") ==>
BinApp Div (BinApp Add (BinApp Add (BinApp Mul (Val 3.0)
(BinApp Add (BinApp Mul (Id "x")
(Val 1.0))
(BinApp Mul (Val 1.0)
(Id "x"))))
(BinApp Mul (Val 0.0)
(BinApp Mul (Id "x")
(Id "x"))))
(Val 0.0))
(BinApp Add (BinApp Mul (Val 3.0) (BinApp Mul (Id "x")
(Id "x")))
(Val 2.0))
, (log(x), "x") ==>
BinApp Div (Val 1.0) (Id "x")
]
maclaurinTests
= [ (UnApp Sin (Id "x"), 2, 2)
==> 2.0
, (UnApp Sin (Id "x"), 2, 3)
==> 2.0
, (UnApp Sin (Id "x"), 2, 5)
==> 0.6666666666666667
, (UnApp Sin (Id "x"), 2, 7)
==> 0.9333333333333333
, (UnApp Sin (Id "x"), 2, 9)
==> 0.9079365079365079
, (UnApp Cos (Id "x"), 4, 9)
==> (-0.39682539682539764)
, ((log(x+5)), 4, 5)
==> (2.157704579100767)
, (((log(sin(x+1)))*cos(sin(-x*x*sin(log(3))))), 2, 3)
==> (-1.7129843692752142)
]
showExpTests
= [ Val 42 ==> "42.0"
, Id "u''" ==> "u''"
, e1 ==> "(5.0*x)"
, e2 ==> "(((x*x)+y)+-(7.0))"
, e3 ==> "(x+-(((y*y)/(((4.0*x)*y)+-((y*y))))))"
, e4 ==> "-(cos(x))"
, e5 ==> "sin((1.0+log((2.0*x))))"
, e6 ==> "log(((3.0*(x*x))+2.0))"
]
allTestCases
= [ floatTestCase "eval" (uncurry eval) evalTests
, testCase "diff" (uncurry diff) diffTests
, floatTestCase "maclaurin" (uncurry3 maclaurin) maclaurinTests
, testCase "showExp" (showExp . unId) (map mkId showExpTests)
]
runTests = mapM_ goTest allTestCases
main = runTests