forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptDifferentiationTests.cs
More file actions
291 lines (246 loc) · 6.39 KB
/
Copy pathScriptDifferentiationTests.cs
File metadata and controls
291 lines (246 loc) · 6.39 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using System;
using System.Collections.Generic;
using SkiaSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Waher.Script.Graphs;
namespace Waher.Script.Test
{
[TestClass]
public class ScriptDifferentiationTests
{
private void Test(string Script)
{
Variables v = new Variables();
Expression Exp = new Expression("DrawTangent(x0[],f,min,max):=" +
"(" +
"x:=min..max|((max-min)/100);" +
"plot2dcurve(x,f(x),\"Blue\")+" +
"sum([foreach xi in x0 do plot2dcurve(x,f'(xi)*(x-xi)+f(xi),\"Red\")])+" +
"scatter2d(x0,f(x0),\"Red\",5);" +
");" + Script);
Graph Result = Exp.Evaluate(v) as Graph;
if (Result is null)
Assert.Fail("Expected graph.");
GraphSettings Settings = new GraphSettings();
SKImage Bmp = Result.CreateBitmap(Settings);
}
[TestMethod]
public void Differentiation_Test_01_Sin()
{
this.Test("DrawTangent([-5,-2,2,5],sin,-10,10)");
}
[TestMethod]
public void Differentiation_Test_02_Cos()
{
this.Test("DrawTangent([-5,-2,2,5],cos,-10,10)");
}
[TestMethod]
public void Differentiation_Test_03_Tan()
{
this.Test("DrawTangent([-0.5,0.5],tan,-1,1)");
}
[TestMethod]
public void Differentiation_Test_04_Sec()
{
this.Test("DrawTangent([-0.5,0.5],sec,-1,1)");
}
[TestMethod]
public void Differentiation_Test_05_Csc()
{
this.Test("DrawTangent([1],csc,0.5,2)+DrawTangent([-1],csc,-2,-0.5)");
}
[TestMethod]
public void Differentiation_Test_06_Cot()
{
this.Test("DrawTangent([1],cot,0.5,2)+DrawTangent([-1],cot,-2,-0.5)");
}
[TestMethod]
public void Differentiation_Test_07_SinH()
{
this.Test("DrawTangent([-2,2],sinh,-3,3)");
}
[TestMethod]
public void Differentiation_Test_08_CosH()
{
this.Test("DrawTangent([-2,2],cosh,-3,3)");
}
[TestMethod]
public void Differentiation_Test_09_TanH()
{
this.Test("DrawTangent([-0.5,0.5],tanh,-1,1)");
}
[TestMethod]
public void Differentiation_Test_10_SecH()
{
this.Test("DrawTangent([-0.5,0.5],sech,-1,1)");
}
[TestMethod]
public void Differentiation_Test_11_CscH()
{
this.Test("DrawTangent([1],csch,0.5,2)+DrawTangent([-1],csch,-2,-0.5)");
}
[TestMethod]
public void Differentiation_Test_12_CotH()
{
this.Test("DrawTangent([1],coth,0.5,2)+DrawTangent([-1],coth,-2,-0.5)");
}
[TestMethod]
public void Differentiation_Test_13_ArcSin()
{
this.Test("DrawTangent([-0.5,0.5],arcsin,-1,1)");
}
[TestMethod]
public void Differentiation_Test_14_ArcCos()
{
this.Test("DrawTangent([-0.5,0.5],arccos,-1,1)");
}
[TestMethod]
public void Differentiation_Test_15_ArcTan()
{
this.Test("DrawTangent([-5,5],arctan,-10,10)");
}
[TestMethod]
public void Differentiation_Test_16_ArcSec()
{
this.Test("DrawTangent([2,5],arcsec,1,10)");
this.Test("DrawTangent([-2,-5],arcsec,-10,-1)");
}
[TestMethod]
public void Differentiation_Test_17_ArcCsc()
{
this.Test("DrawTangent([2,5],arccsc,1,10)");
this.Test("DrawTangent([-2,-5],arccsc,-10,-1)");
}
[TestMethod]
public void Differentiation_Test_18_ArcCot()
{
this.Test("DrawTangent([2,5],arccot,1,10)");
this.Test("DrawTangent([-2,-5],arccot,-10,-1)");
}
[TestMethod]
public void Differentiation_Test_19_ArcSinH()
{
this.Test("DrawTangent([-0.5,0.5],arcsinh,-1,1)");
}
[TestMethod]
public void Differentiation_Test_20_ArcCosH()
{
this.Test("DrawTangent([4,8],arccosh,2,10)");
}
[TestMethod]
public void Differentiation_Test_21_ArcTanH()
{
this.Test("DrawTangent([-0.5,0.5],arctanh,-0.9,0.9)");
}
[TestMethod]
public void Differentiation_Test_22_ArcSecH()
{
this.Test("DrawTangent([2,5],arcsech,1,10)");
this.Test("DrawTangent([0.25,0.75],arcsech,0.1,0.9)");
}
[TestMethod]
public void Differentiation_Test_23_ArcCscH()
{
this.Test("DrawTangent([2,5],arccsch,1,10)");
this.Test("DrawTangent([-2,-5],arccsch,-10,-1)");
}
[TestMethod]
public void Differentiation_Test_24_ArcCotH()
{
this.Test("DrawTangent([2],arccoth,1.1,3)");
}
[TestMethod]
public void Differentiation_Test_25_Ln()
{
this.Test("DrawTangent([2,4],ln,1,5);");
}
[TestMethod]
public void Differentiation_Test_26_Lg()
{
this.Test("DrawTangent([2,4],lg,1,5)");
}
[TestMethod]
public void Differentiation_Test_27_Log2()
{
this.Test("DrawTangent([2,4],log2,1,5)");
}
[TestMethod]
public void Differentiation_Test_28_Exp()
{
this.Test("DrawTangent([-2,2],exp,-5,5)");
}
[TestMethod]
public void Differentiation_Test_29_Power()
{
this.Test("DrawTangent([-2,2],x->x^1,-5,5)");
this.Test("DrawTangent([-2,2],x->x^2,-5,5)");
this.Test("DrawTangent([-2,2],x->x^3,-5,5)");
this.Test("DrawTangent([-2,2],x->2^x,-5,5)");
this.Test("DrawTangent([1,4],x->x^x,0.1,5)");
}
[TestMethod]
public void Differentiation_Test_30_Addition()
{
this.Test("DrawTangent([-2,2],x->x^2+x^3,-5,5)");
this.Test("DrawTangent([-2,2],x->x^2.+x^3,-5,5)");
}
[TestMethod]
public void Differentiation_Test_31_Subtraction()
{
this.Test("DrawTangent([-2,2],x->x^2-x^3,-5,5)");
this.Test("DrawTangent([-2,2],x->x^2.-x^3,-5,5)");
}
[TestMethod]
public void Differentiation_Test_32_Multiplication()
{
this.Test("DrawTangent([-2,2],x->x^2*x^3,-5,5)");
this.Test("DrawTangent([-2,2],x->x^2.*x^3,-5,5)");
}
[TestMethod]
public void Differentiation_Test_33_Division()
{
this.Test("DrawTangent([-2,2],x->x^2/(1+x^4),-5,5)");
this.Test("DrawTangent([-2,2],x->x^2./(1+x^4),-5,5)");
}
[TestMethod]
public void Differentiation_Test_34_Cube()
{
this.Test("DrawTangent([-2,2],x->x³,-5,5)");
}
[TestMethod]
public void Differentiation_Test_35_Square()
{
this.Test("DrawTangent([-2,2],x->x²,-5,5)");
}
[TestMethod]
public void Differentiation_Test_36_DegreesToRadians()
{
this.Test("DrawTangent([-2,2],x->x°,-5,5)");
}
[TestMethod]
public void Differentiation_Test_37_Percent()
{
this.Test("DrawTangent([-2,2],x->x%,-5,5)");
}
[TestMethod]
public void Differentiation_Test_38_Permil()
{
this.Test("DrawTangent([-2,2],x->x‰,-5,5)");
}
[TestMethod]
public void Differentiation_Test_39_Perdiezmil()
{
this.Test("DrawTangent([-2,2],x->x‱,-5,5)");
}
[TestMethod]
public void Differentiation_Test_40_Inverse()
{
this.Test("DrawTangent([2,4],ln',1,5)");
}
[TestMethod]
public void Differentiation_Test_41_Negation()
{
this.Test("DrawTangent([-2,2],x->-x^2,-5,5)");
}
}
}