forked from PolyMathOrg/PolyMath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMAccuracyTest.class.st
More file actions
340 lines (309 loc) · 8.95 KB
/
PMAccuracyTest.class.st
File metadata and controls
340 lines (309 loc) · 8.95 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
"
AccuracyTest uses AccuracyTestExample
"
Class {
#name : 'PMAccuracyTest',
#superclass : 'TestCase',
#instVars : [
'a',
'dp'
],
#category : 'Math-Tests-Accuracy',
#package : 'Math-Tests-Accuracy'
}
{ #category : 'initialization' }
PMAccuracyTest >> initialize [
super initialize.
dp := PMAccuracyTestExample decimalPlaces
]
{ #category : 'running' }
PMAccuracyTest >> setUp [
super setUp.
a := PMAccuracyTestExample new.
PMAccuracyTestExample decimalPlaces: 3
]
{ #category : 'running' }
PMAccuracyTest >> tearDown [
PMAccuracyTestExample decimalPlaces: dp.
super tearDown
]
{ #category : 'tests' }
PMAccuracyTest >> testArgumentAt [
self assert: (a argumentAt: 'Aaa') equals: #(#(false) #(true)).
self assert: (a argumentAt: 'Bbb') equals: #(#('a') #('AG')).
self assert: (a argumentAt: 'Ddd') isNil.
self assert: (a argumentAt: 'Ccc') equals: #(#(1) #(1.1) #(0.9))
]
{ #category : 'tests' }
PMAccuracyTest >> testAsArray [
self assert: (a asArray: 'bla') equals: #('bla').
self assert: (a asArray: #('bla')) equals: #('bla').
self
assert: (a asArray: #('bla') asOrderedCollection)
equals: #('bla')
]
{ #category : 'tests' }
PMAccuracyTest >> testCalcDeviationsInMax [
| r c |
c := #(#(1 2 3) #(2 3 6)).
r := Array with: (3 / 2) with: (9 / 4) with: 4.
self
assert: (a calcDeviations: r in: c max: false)
equals: (Array with: (-100 / 3) asFloat with: (-100 / 9) asFloat with: -25).
self
assert: (a calcDeviations: r in: c max: true)
equals: (Array with: (100 / 3) asFloat with: (100 / 3) asFloat with: 50)
]
{ #category : 'tests' }
PMAccuracyTest >> testCalcErrorOfRealResult [
self assert: (a calcErrorOf: 0.7 realResult: 0.7) equals: 0.
self assert: (a calcErrorOf: 0.7 realResult: 0.0) equals: -100.
self assert: (a calcErrorOf: 1 / 4 realResult: 1 / 2) equals: 100.
self
assert: (a calcErrorOf: 0.0 realResult: 7)
equals: Float infinity.
self assert: (a calcErrorOf: 0.0 realResult: 0) equals: 0.
self
assert: (a calcErrorOf: 0.0 realResult: -1 / 7)
equals: Float infinity negated
]
{ #category : 'tests' }
PMAccuracyTest >> testDecimalPlaces [
self assert: a class decimalPlaces equals: 3.
a class decimalPlaces: 2.
self assert: a class decimalPlaces equals: 2
]
{ #category : 'tests' }
PMAccuracyTest >> testExtractFromResultsReturnsAllElementsWhenOnlyOneIsTrue [
| argument results |
results := a
extractFromResults: #('bla' 'blah')
which: 1
onlyOne: true.
self assert: results equals: #('bla' 'blah').
argument := a testGetterAaa second.
self assert: argument equals: #(#(false) #(true))
]
{ #category : 'tests' }
PMAccuracyTest >> testExtractFromResultsReturnsTheCorrectIndexedElementWhenOnlyOneIsFalse [
| argument results |
results := a
extractFromResults: #('bla' 'blah')
which: 2
onlyOne: false.
self assert: results equals: 'blah'.
argument := a testGetterAaa second.
self assert: argument equals: #(true)
]
{ #category : 'tests' }
PMAccuracyTest >> testExtremeCollectionmax [
| c |
c := #(4 4 2).
self
assert: (a extremeCollection: c max: true)
equals: (Array with: Float infinity negated).
self
assert: (a extremeCollection: c max: false)
equals: (Array with: Float infinity).
self
assert: (a extremeCollection: (Array with: c) max: false)
equals: (Array with: Float infinity with: Float infinity with: Float infinity)
]
{ #category : 'tests' }
PMAccuracyTest >> testFormat [
self
assert: (a format: #(1 'rez' 1.8899))
equals: #('1.0' 'rez' '1.89').
self
assert: (a format: #(10 100 0.18899 0.018899))
equals: #('10.0' '1.0e2' '0.189' '1.89e-2').
self assert: (a format: Float infinity) equals: #('Infinity').
self assert: (a format: 0 - Float infinity) equals: #('-Infinity')
]
{ #category : 'tests' }
PMAccuracyTest >> testFormatTypePostfix [
| r |
r := a format: #(1 'rez' 1.8899) type: 'x' postfix: '%%'.
self assert: r contents equals: 'x: 1.0%% , rez%% , 1.89%% '.
r := a format: #(1.8899 true) type: '' postfix: nil.
self
assert: r contents
equals: 'x: 1.0%% , rez%% , 1.89%% : 1.89 , true '
]
{ #category : 'tests' }
PMAccuracyTest >> testFormatTypePostfixTree [
| t |
t := KeyedTree new.
self
assert:
(a
format: #(100.0 'rez' 0.18899)
type: 'x'
postfix: '%%'
tree: t) contents
equals: 'x: 1.0e2%% , rez%% , 0.189%% '.
self
assert: t
equals:
(KeyedTree new
at: 'x' put: #(100.0 'rez' 0.18899);
yourself)
]
{ #category : 'tests' }
PMAccuracyTest >> testGetters [
| r |
r := a testGetterAaa.
self assert: r equals: #( #( #( 1 2 ) #( 3 2.8888 ) ) #( #( false ) #( true ) ) #( #( 5 3 ) #( 4 4 ) ) 2 2 ).
r := a testGetterBbb.
self assert: r equals: #( #( #( 1 ) #( 3 ) ) #( #( 'a' ) #( 'AG' ) ) #( #( 2 ) #( 3 ) ) 2 2 )
]
{ #category : 'tests' }
PMAccuracyTest >> testIfSeveralterations [
a iterations: 2.
self assert: (a ifSeveralterations: [ 1 ]) equals: 1.
a iterations: 1.
self assert: (a ifSeveralterations: [ 1 ]) equals: a
]
{ #category : 'tests' }
PMAccuracyTest >> testIterations [
| s d |
a
iterations: 2;
run.
d := a dataTree at: 'names'.
s := (d atPath: #( 'Aaa' #( 1 2 ) #( 5 3 ) '+dev' )) first negated.
self assert: (d atPath: #( 'Aaa' #( 1 2 ) #( 5 3 ) '-dev' )) first closeTo: s.
s := d atPath: #( 'Aaa' #( 3 2.8888 ) #( 5 3 ) 'standard deviation' ).
self assert: s first > 0.
self assert: s second equals: 0.
self assert: (d atPath: #( 'Ddd' 'data' )) equals: #( #( 2 3 ) #( 2 3 ) ).
s := d atPath: #( 'Ddd' 'error' ).
self assert: s first closeTo: -45.
self assert: s second closeTo: -26.6666667 precision: 0.00001
]
{ #category : 'tests' }
PMAccuracyTest >> testNumberOfDifferentParametersAt [
self assert: (a numberOfDifferentParametersAt: 'Aaa') equals: 2.
self assert: (a numberOfDifferentParametersAt: 'Ccc') equals: 2.
self assert: (a numberOfDifferentParametersAt: 'Ddd') equals: 1.
self assert: (a numberOfDifferentParametersAt: 'Fff') equals: 1
]
{ #category : 'tests' }
PMAccuracyTest >> testNumberOfDifferentResultsAt [
self assert: (a numberOfDifferentResultsAt: 'Aaa') equals: 2.
self assert: (a numberOfDifferentResultsAt: 'Bbb') equals: 2.
self assert: (a numberOfDifferentResultsAt: 'Ccc') equals: 3.
self assert: (a numberOfDifferentResultsAt: 'Ddd') equals: 1.
self assert: (a numberOfDifferentResultsAt: 'Eee') equals: 2
]
{ #category : 'tests' }
PMAccuracyTest >> testParameterAt [
self assert: (a parameterAt: 'Aaa') equals: #(#(1 2) #(3 2.8888)).
self assert: (a parameterAt: 'Bbb') equals: #(#(1) #(3)).
self assert: (a parameterAt: 'Ddd') isNil.
self assert: (a parameterAt: 'Fff') isNil
]
{ #category : 'tests' }
PMAccuracyTest >> testPrintOn [
| s |
s := WriteStream on: String new.
a printOn: s.
self assert: s contents equals: 'a PMAccuracyTestExample ()'.
s reset.
a run.
a printOn: s.
self
assert:
(s contents
beginsWith:
'a PMAccuracyTestExample (
Report for: PMAccuracyTestExample')
]
{ #category : 'tests' }
PMAccuracyTest >> testReport [
self assert: a report equals: ''.
a run.
self assert: (a report beginsWith: 'Report for: PMAccuracyTestExample')
]
{ #category : 'tests' }
PMAccuracyTest >> testResultsKeyForAtPosition [
self assert: (a resultsKeyFor: 'Aaa' AtPosition: 2) equals: #(4 4).
self assert: (a resultsKeyFor: 'Bbb' AtPosition: 1) equals: #(2).
a run.
self
assert:
(a dataTree
atPath: (
Array
with: 'names'
with: 'Ccc'
with: #(1)
with: (a resultsKeyFor: 'Ccc' AtPosition: 1)
with: 'arguments'))
equals: 1.
self
assert:
(a dataTree
atPath: (
Array
with: 'names'
with: 'Ccc'
with: #(1)
with: (a resultsKeyFor: 'Ccc' AtPosition: 3)
with: 'arguments'))
equals: 0.9.
self assert: (a resultsKeyFor: 'Eee' AtPosition: 2) equals: #(1 3).
self
assert: (a resultsKeyFor: 'Fff' AtPosition: 1)
equals: #(0 1 0 -2 3)
]
{ #category : 'tests' }
PMAccuracyTest >> testRun [
a run.
a run: 'Bbb'.
self assert: (a dataTree atPath: #('names' 'data')) equals: #('Bbb').
self
assert:
(a report
beginsWith:
'Report for: PMAccuracyTestExample
test Bbb').
a run: #('Ccc' 'Eee').
self
assert: (a dataTree atPath: #('names' 'data'))
equals: #('Ccc' 'Eee')
]
{ #category : 'tests' }
PMAccuracyTest >> testSetUp [
self assert: a count equals: 0.
a performCheck: 'Fff'.
self assert: a count equals: 4 / 5.
a iterations: 3.
a performCheck: 'Ccc'.
self assert: a count equals: 16 / 5
]
{ #category : 'tests' }
PMAccuracyTest >> testTreeTypeData [
| aTree |
aTree := KeyedTree new.
self assert: (a tree: aTree type: 'aa' data: 'bb') equals: aTree.
self
assert: aTree
equals:
(KeyedTree new
at: 'data' put: 'bb';
at: 'type' put: 'aa';
yourself)
]
{ #category : 'tests' }
PMAccuracyTest >> testperformCheck [
| b |
a extractFromResults: 'bla' which: 2 onlyOne: false. "for setting numberOfResults"
self assert: (a performCheck: 'Aaa') equals: #(#(1 1)).
a extractFromResults: 'bla' which: 1 onlyOne: true. "for setting numberOfResults"
a iterations: 3.
b := a performCheck: 'Fff'.
self assert: b first first equals: 0.
self assert: b second third equals: 1.
self assert: (b third at: 5) isNaN
]