1
1
import * as test from "tape" ;
2
- import { evaluate , verify , dedent , testSingleExpressionByList } from "./shared_functions" ;
2
+ import { evaluate , verify , dedent , testSingleExpressionByList , valueTest } from "./shared_functions" ;
3
3
4
4
// Test Constants
5
- // Would this fail on different architectures than mine? Not according to dcmumentation Maybe we Should
5
+ // Would this fail on different architectures than mine? Not according to documentation Maybe we Should
6
6
// flush out that implicit assumption.
7
7
8
- let constants_list : any = [
9
- { "Expression" :"pi[]" , "Value" :"3.141592653589793" } ,
10
- { "Expression" :"e[]" , "Value" :"2.718281828459045" } ,
11
- { "Expression" :"ln2[]" , "Value" :"0.6931471805599453" } ,
12
- { "Expression" :"log2e[]" , "Value" :"1.4426950408889634" } ,
13
- { "Expression" :"log10e[]" , "Value" :"0.4342944819032518" } ,
14
- { "Expression" :"sqrt1/2[]" , "Value" :"0.7071067811865476" } ,
15
- { "Expression" :"sqrt2[]" , "Value" :"1.4142135623730951" }
8
+ let delta = 0.00000000001 ;
9
+
10
+ let constants_list : valueTest [ ] = [
11
+ { expression : "pi[]" , expectedValue : 3.141592653589793 } ,
12
+ { expression : "e[]" , expectedValue : 2.718281828459045 } ,
13
+ { expression : "ln2[]" , expectedValue : 0.6931471805599453 } ,
14
+ { expression : "log2e[]" , expectedValue : 1.4426950408889634 } ,
15
+ { expression : "log10e[]" , expectedValue : 0.4342944819032518 } ,
16
+ { expression : "sqrt1/2[]" , expectedValue : 0.7071067811865476 } ,
17
+ { expression : "sqrt2[]" , expectedValue : 1.4142135623730951 }
16
18
]
17
19
testSingleExpressionByList ( constants_list ) ;
18
20
19
21
// Test Power Function
20
- let pow_list : any = [
21
- { "Expression" : "pow[ value:2 by:3 ]" , "Value" : "8" } ,
22
- { "Expression" : "pow[ value:9 by:1 / 2 ]" , "Value" : "3" } ]
22
+ let pow_list : valueTest [ ] = [
23
+ { expression : "pow[ value:2 by:3 ]" , expectedValue : 8 } ,
24
+ { expression : "pow[ value:9 by:1 / 2 ]" , expectedValue : 3 } ]
23
25
testSingleExpressionByList ( pow_list ) ;
24
26
25
27
// Test Log Function
26
- let log_list : any = [
27
- { "Expression" : "log[ value: e[] ]" , "Value" : "1" } ,
28
- { "Expression" : "log[ value: 10 base: 10 ]" , "Value" : "1" } ]
28
+ let log_list : valueTest [ ] = [
29
+ { expression : "log[ value: e[] ]" , expectedValue : 1 } ,
30
+ { expression : "log[ value: 10 base: 10 ]" , expectedValue : 1 } ]
29
31
testSingleExpressionByList ( log_list ) ;
30
32
31
33
// Test Exp Function
32
- let exp_list : any = [
33
- { "Expression" : "exp[ value: 1 ]" , "Value" : " 2.718281828459045" } ]
34
+ let exp_list : valueTest [ ] = [
35
+ { expression : "exp[ value: 1 ]" , expectedValue : 2.718281828459045 } ]
34
36
testSingleExpressionByList ( exp_list ) ;
35
37
36
38
// Test Trig Functions
37
- let trig_list : any = [
38
- { "Expression" : "sin[ radians: 1 ]" , "Value" : " 0.8414709848078965" } ,
39
- { "Expression" : "cos[ radians: 1 ]" , "Value" : " 0.5403023058681398" } ,
40
- { "Expression" : "tan[ radians: 1 ]" , "Value" : " 1.5574077246549023" }
39
+ let trig_list : valueTest [ ] = [
40
+ { expression : "sin[ radians: 1 ]" , expectedValue : 0.8414709848078965 } ,
41
+ { expression : "cos[ radians: 1 ]" , expectedValue : 0.5403023058681398 } ,
42
+ { expression : "tan[ radians: 1 ]" , expectedValue : 1.5574077246549023 }
41
43
]
42
44
testSingleExpressionByList ( trig_list ) ;
43
45
44
46
45
47
test ( "Should be able to use the sin function with degrees and radians" , ( assert ) => {
46
48
let expected = {
47
49
insert : [
48
- [ "a" , "tag" , "div" ] ,
49
- [ "a" , "text" , "1" ] ,
50
- [ "b" , "tag" , "div" ] ,
51
- [ "b" , "text" , "0.9999996829318346" ] ,
50
+ [ "a" , "floatTest" , "1" ] ,
51
+ [ "b" , "floatTest" , "0.9999996829318346" ] ,
52
52
] ,
53
53
remove : [ ] ,
54
54
} ;
55
55
56
56
evaluate ( assert , expected , `
57
- Now consider this:
58
-
59
57
~~~
60
58
search
61
59
y = sin[degrees: 90]
62
60
x = sin[radians: 3.14 / 2]
63
61
64
- bind @browser
65
- [#div text : y]
66
- [#div text : x]
62
+ bind
63
+ [floatTest : y]
64
+ [floatTest : x]
67
65
~~~
68
66
` ) ;
69
67
assert . end ( ) ;
@@ -72,25 +70,21 @@ test("Should be able to use the sin function with degrees and radians", (assert)
72
70
test ( "Should be able to use the cos function with degrees and radians" , ( assert ) => {
73
71
let expected = {
74
72
insert : [
75
- [ "a" , "tag" , "div" ] ,
76
- [ "a" , "text" , "1" ] ,
77
- [ "b" , "tag" , "div" ] ,
78
- [ "b" , "text" , "-0.9999987317275395" ] ,
73
+ [ "a" , "floatTest" , "1" ] ,
74
+ [ "b" , "floatTest" , "-0.9999987317275395" ] ,
79
75
] ,
80
76
remove : [ ] ,
81
77
} ;
82
78
83
79
evaluate ( assert , expected , `
84
- Now consider this:
85
-
86
80
~~~
87
81
search
88
82
y = cos[degrees: 0]
89
83
x = cos[radians: 3.14]
90
84
91
- bind @browser
92
- [#div text : y]
93
- [#div text : x]
85
+ bind
86
+ [floatTest : y]
87
+ [floatTest : x]
94
88
~~~
95
89
` ) ;
96
90
assert . end ( ) ;
@@ -99,122 +93,129 @@ test("Should be able to use the cos function with degrees and radians", (assert)
99
93
test ( "Should be able to use the tan function with degrees and radians" , ( assert ) => {
100
94
let expected = {
101
95
insert : [
102
- [ "a" , "tag" , "div" ] ,
103
- [ "a" , "text" , "0.5773502691896257" ] ,
104
- [ "b" , "tag" , "div" ] ,
105
- [ "b" , "text" , "0.5463024898437905" ] ,
96
+ [ "a" , "floatTest" , "0.5773502691896257" ] ,
97
+ [ "b" , "floatTest" , "0.5463024898437905" ] ,
106
98
] ,
107
99
remove : [ ] ,
108
100
} ;
109
101
110
102
evaluate ( assert , expected , `
111
- Now consider this:
112
-
113
103
~~~
114
104
search
115
105
y = tan[degrees: 30]
116
106
x = tan[radians: 0.5]
117
107
118
- bind @browser
119
- [#div text : y]
120
- [#div text : x]
108
+ bind
109
+ [floatTest : y]
110
+ [floatTest : x]
121
111
~~~
122
112
` ) ;
123
113
assert . end ( ) ;
124
114
} )
125
115
126
116
// Test inverse Trig
127
- let atrig_list : any = [
128
- { "Expression" :"asin[ value: 0.8414709848078965 ]" , "Value" :"1" } ,
129
- // Does Eve need an implicit round under the hood? The below should be 1
130
- { "Expression" :"acos[ value: 0.5403023058681398 ]" , "Value" :"0.9999999999999999" } ,
131
- { "Expression" :"atan[ value: 1.5574077246549023 ]" , "Value" :"1" } ,
117
+ let atrig_list : valueTest [ ] = [
118
+ { expression : "asin[ value: 0.8414709848078965 ]" , expectedValue : 1 } ,
119
+ { expression : "acos[ value: 0.5403023058681398 ]" , expectedValue : 0.9999999999999999 } ,
120
+ { expression : "atan[ value: 1.5574077246549023 ]" , expectedValue : 1 } ,
132
121
]
133
122
testSingleExpressionByList ( atrig_list ) ;
134
123
135
124
// Test Hyperbolic Functions
136
- let hyp_list : any = [
137
- { "Expression" : "sinh[ value: 1 ]" , "Value" : " 1.1752011936438014" } ,
138
- { "Expression" : "cosh[ value: 1 ]" , "Value" : " 1.5430806348152437" } ,
139
- { "Expression" : "tanh[ value: 1 ]" , "Value" : " 0.7615941559557649" } ,
125
+ let hyp_list : valueTest [ ] = [
126
+ { expression : "sinh[ value: 1 ]" , expectedValue : 1.1752011936438014 } ,
127
+ { expression : "cosh[ value: 1 ]" , expectedValue : 1.5430806348152437 } ,
128
+ { expression : "tanh[ value: 1 ]" , expectedValue : 0.7615941559557649 } ,
140
129
]
141
130
testSingleExpressionByList ( hyp_list ) ;
142
131
143
132
// Test Inverse Hyperbolic Functions
144
- let ahyp_list : any = [
145
- { "Expression" : "asinh[ value: 1.1752011936438014 ]" , "Value" : "1" } ,
146
- { "Expression" : "acosh[ value: 1.5430806348152437 ]" , "Value" : "1" } ,
147
- { "Expression" : "atanh[ value: 0.7615941559557649 ]" , "Value" : " 0.9999999999999999" } ,
133
+ let ahyp_list : valueTest [ ] = [
134
+ { expression : "asinh[ value: 1.1752011936438014 ]" , expectedValue : 1 } ,
135
+ { expression : "acosh[ value: 1.5430806348152437 ]" , expectedValue : 1 } ,
136
+ { expression : "atanh[ value: 0.7615941559557649 ]" , expectedValue : 0.9999999999999999 } ,
148
137
]
149
138
testSingleExpressionByList ( ahyp_list ) ;
150
139
151
- test ( "Range and function within function " , ( assert ) => {
140
+ test ( "Test range " , ( assert ) => {
152
141
let expected = {
153
142
insert : [
154
- [ "a" , "tag" , "div" ] ,
155
- [ "a" , "text" , "1" ] ,
156
- [ "b" , "tag" , "div" ] ,
157
- [ "b" , "text" , "2" ] ,
158
- [ "c" , "tag" , "div" ] ,
159
- [ "c" , "text" , "3" ] ,
143
+ [ "a" , "result" , "1" ] ,
144
+ [ "b" , "result" , "2" ] ,
145
+ [ "c" , "result" , "3" ] ,
160
146
] ,
161
147
remove : [ ] ,
162
148
} ;
163
149
164
150
evaluate ( assert , expected , `
165
- Now consider this:
151
+ ~~~
152
+ search
153
+ x = range[from:1 to: 3 increment: 1 ]
166
154
155
+ bind
156
+ [result: x]
157
+ ~~~
158
+ ` ) ;
159
+ assert . end ( ) ;
160
+ } )
161
+
162
+ test ( "Test nested functions" , ( assert ) => {
163
+ let expected = {
164
+ insert : [
165
+ [ "a" , "floatTest" , "1" ] ,
166
+ ] ,
167
+ remove : [ ] ,
168
+ } ;
169
+
170
+ evaluate ( assert , expected , `
167
171
~~~
168
172
search
169
- x = range[from:1 to: pi[] increment: 1 ]
173
+ x = sin[radians: pi[] / 2 ]
170
174
171
- bind @browser
172
- [#div text: x]
175
+ bind
176
+ [floatTest: x]
173
177
~~~
174
178
` ) ;
175
179
assert . end ( ) ;
176
180
} )
177
181
178
182
// Test Floor Function
179
- let floor_list : any = [
180
- { "Expression" : "floor[ value: 1.0000000000000001 ]" , "Value" : "1" } ,
181
- { "Expression" : "floor[ value: 1.999999999999999 ]" , "Value" : "1" } ,
183
+ let floor_list : valueTest [ ] = [
184
+ { expression : "floor[ value: 1.0000000000000001 ]" , expectedValue : 1 } ,
185
+ { expression : "floor[ value: 1.999999999999999 ]" , expectedValue : 1 } ,
182
186
]
183
187
testSingleExpressionByList ( floor_list ) ;
184
188
185
189
// Test Ceiling Function
186
- let ceiling_list : any = [
187
- { "Expression" : "ceiling[ value: 1.000000000000001 ]" , "Value" : "2" } ,
188
- { "Expression" : "ceiling[ value: 1.999999999999999 ]" , "Value" : "2" } ,
190
+ let ceiling_list : valueTest [ ] = [
191
+ { expression : "ceiling[ value: 1.000000000000001 ]" , expectedValue : 2 } ,
192
+ { expression : "ceiling[ value: 1.999999999999999 ]" , expectedValue : 2 } ,
189
193
]
190
194
testSingleExpressionByList ( ceiling_list ) ;
191
195
192
-
193
196
// Test ABS Function
194
- let abs_list : any = [
195
- { "Expression" : "abs[ value: -1 ]" , "Value" : "1" } ,
196
- { "Expression" : "abs[ value: 1 ]" , "Value" : "1" } ,
197
+ let abs_list : valueTest [ ] = [
198
+ { expression : "abs[ value: -1 ]" , expectedValue : 1 } ,
199
+ { expression : "abs[ value: 1 ]" , expectedValue : 1 } ,
197
200
]
198
201
testSingleExpressionByList ( abs_list ) ;
199
202
200
-
201
203
// Test Mod Function
202
- let mod_list : any = [
203
- { "Expression" : "mod[ value: 7 by: 3]" , "Value" : "1" } ,
204
- { "Expression" : "mod[ value: 6 by: 3]" , "Value" : "0" } ,
204
+ let mod_list : valueTest [ ] = [
205
+ { expression : "mod[ value: 7 by: 3]" , expectedValue : 1 } ,
206
+ { expression : "mod[ value: 6 by: 3]" , expectedValue : 0 } ,
205
207
]
206
208
testSingleExpressionByList ( mod_list ) ;
207
209
208
-
209
210
// Test Round Function
210
- let round_list : any = [
211
- { "Expression" : "round[ value: 1.49999999999999 ]" , "Value" : "1" } ,
212
- { "Expression" : "round[ value: 1.5 ]" , "Value" : "2" }
211
+ let round_list : valueTest [ ] = [
212
+ { expression : "round[ value: 1.49999999999999 ]" , expectedValue : 1 } ,
213
+ { expression : "round[ value: 1.5 ]" , expectedValue : 2 }
213
214
]
214
215
testSingleExpressionByList ( round_list ) ;
215
216
216
217
// Test Round Function
217
- let toFixed_list : any = [
218
- { "Expression" : "to-fixed[ value: 1.499 places:2 ]" , "Value" : " 1.50" } ,
218
+ let toFixed_list : valueTest [ ] = [
219
+ { expression : "to-fixed[ value: 1.499 places: 2 ]" , expectedValue : 1.50 } ,
219
220
]
220
- testSingleExpressionByList ( toFixed_list ) ;
221
+ testSingleExpressionByList ( toFixed_list ) ;
0 commit comments