1
1
Class {
2
- #name : #PMPolynomialTest ,
3
- #superclass : #TestCase ,
4
- #category : #' Math-Tests-Polynomials'
2
+ #name : ' PMPolynomialTest' ,
3
+ #superclass : ' TestCase' ,
4
+ #category : ' Math-Tests-Polynomials' ,
5
+ #package : ' Math-Tests-Polynomials'
5
6
}
6
7
7
- { #category : # ' testing - comparing' }
8
+ { #category : ' testing - comparing' }
8
9
PMPolynomialTest >> testIsZero [
9
10
| p1 p2 |
10
11
p1 := PMPolynomial coefficients: #(0 0 0 0 0) .
@@ -13,7 +14,7 @@ PMPolynomialTest >> testIsZero [
13
14
self shouldnt: [ p2 isZero ]
14
15
]
15
16
16
- { #category : # ' testing - addition' }
17
+ { #category : ' testing - addition' }
17
18
PMPolynomialTest >> testPolynomialAddition [
18
19
19
20
| polynomial expected p q |
@@ -25,7 +26,7 @@ PMPolynomialTest >> testPolynomialAddition [
25
26
self assert: (polynomial at: 4 ) equals: 0
26
27
]
27
28
28
- { #category : # ' testing - addition' }
29
+ { #category : ' testing - addition' }
29
30
PMPolynomialTest >> testPolynomialAdditionIsCommutative [
30
31
31
32
| p q expected |
@@ -37,7 +38,7 @@ PMPolynomialTest >> testPolynomialAdditionIsCommutative [
37
38
self assert: q + p equals: expected
38
39
]
39
40
40
- { #category : # ' testing - algebra' }
41
+ { #category : ' testing - algebra' }
41
42
PMPolynomialTest >> testPolynomialDerivative [
42
43
" Code example 2.3"
43
44
"
@@ -56,7 +57,7 @@ PMPolynomialTest >> testPolynomialDerivative [
56
57
self assert: (derivative at: 4 ) equals: 0
57
58
]
58
59
59
- { #category : # ' testing - division' }
60
+ { #category : ' testing - division' }
60
61
PMPolynomialTest >> testPolynomialDivision [
61
62
| pol1 pol2 polynomial |
62
63
pol1 := PMPolynomial coefficients: #(2 -3 1) .
@@ -71,17 +72,18 @@ PMPolynomialTest >> testPolynomialDivision [
71
72
self assert: (polynomial at: 6 ) equals: 0
72
73
]
73
74
74
- { #category : # ' testing - division' }
75
+ { #category : ' testing - division' }
75
76
PMPolynomialTest >> testPolynomialDivisionBug [
76
77
" identify an error when trying to create a zero dividend"
77
78
78
- | pol1 pol2 |
79
+ | pol1 pol2 zero |
79
80
pol1 := PMPolynomial coefficients: #( 2 -3 1 ) .
80
81
pol2 := PMPolynomial coefficients: #( -6 23 -20 3 -1 1 ) .
81
- self shouldnt: [ pol1 / pol2 ] raise: Error
82
+ zero := PMPolynomial coefficients: #(0) .
83
+ self assert: pol1 / pol2 equals: zero.
82
84
]
83
85
84
- { #category : # ' testing - arithmetic' }
86
+ { #category : ' testing - arithmetic' }
85
87
PMPolynomialTest >> testPolynomialDoubleDispatch [
86
88
| n p |
87
89
n := 3.2 .
@@ -98,7 +100,7 @@ PMPolynomialTest >> testPolynomialDoubleDispatch [
98
100
self assert: n - p equals: (p - n) negated
99
101
]
100
102
101
- { #category : # ' testing - algebra' }
103
+ { #category : ' testing - algebra' }
102
104
PMPolynomialTest >> testPolynomialEvaluation [
103
105
" Code example 2.2"
104
106
@@ -107,7 +109,7 @@ PMPolynomialTest >> testPolynomialEvaluation [
107
109
self assert: 0 equals: (polynomial value: 1 )
108
110
]
109
111
110
- { #category : # ' testing - comparing' }
112
+ { #category : ' testing - comparing' }
111
113
PMPolynomialTest >> testPolynomialHash [
112
114
" polynomial hash is hash of coefficient array"
113
115
@@ -123,7 +125,7 @@ PMPolynomialTest >> testPolynomialHash [
123
125
self assert: p3 hash equals: p2 hash
124
126
]
125
127
126
- { #category : # ' testing - algebra' }
128
+ { #category : ' testing - algebra' }
127
129
PMPolynomialTest >> testPolynomialIntegral [
128
130
" Code example 2.3"
129
131
@@ -146,7 +148,7 @@ PMPolynomialTest >> testPolynomialIntegral [
146
148
self assert: (polynomial at: 5 ) equals: 0
147
149
]
148
150
149
- { #category : # ' testing - algebra' }
151
+ { #category : ' testing - algebra' }
150
152
PMPolynomialTest >> testPolynomialIntegralWithConstant [
151
153
" Code example 2.3"
152
154
@@ -165,7 +167,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [
165
167
self assert: (polynomial at: 5 ) equals: 0
166
168
]
167
169
168
- { #category : # ' testing - multiplication' }
170
+ { #category : ' testing - multiplication' }
169
171
PMPolynomialTest >> testPolynomialMultiplication [
170
172
" Code example 2.3"
171
173
@@ -177,7 +179,7 @@ PMPolynomialTest >> testPolynomialMultiplication [
177
179
self assert: product equals: expected.
178
180
]
179
181
180
- { #category : # ' testing - multiplication' }
182
+ { #category : ' testing - multiplication' }
181
183
PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [
182
184
183
185
| expected p q |
@@ -192,7 +194,7 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [
192
194
self assert: q * p equals: expected
193
195
]
194
196
195
- { #category : # ' testing - addition' }
197
+ { #category : ' testing - addition' }
196
198
PMPolynomialTest >> testPolynomialNumberAddition [
197
199
198
200
| polynomial expected p |
@@ -203,7 +205,7 @@ PMPolynomialTest >> testPolynomialNumberAddition [
203
205
self assert: (polynomial at: 3 ) equals: 0
204
206
]
205
207
206
- { #category : # ' testing - addition' }
208
+ { #category : ' testing - addition' }
207
209
PMPolynomialTest >> testPolynomialNumberAdditionInverse [
208
210
209
211
| polynomial expected p |
@@ -214,7 +216,7 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [
214
216
self assert: (polynomial at: 3 ) equals: 0
215
217
]
216
218
217
- { #category : # ' testing - division' }
219
+ { #category : ' testing - division' }
218
220
PMPolynomialTest >> testPolynomialNumberDivision [
219
221
220
222
| polynomial expected expectedCoefficients p |
@@ -226,7 +228,7 @@ PMPolynomialTest >> testPolynomialNumberDivision [
226
228
self assert: (polynomial at: 3 ) equals: 0
227
229
]
228
230
229
- { #category : # ' testing - multiplication' }
231
+ { #category : ' testing - multiplication' }
230
232
PMPolynomialTest >> testPolynomialNumberMultiplication [
231
233
232
234
| product expected p |
@@ -237,7 +239,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [
237
239
self assert: product equals: expected
238
240
]
239
241
240
- { #category : # ' testing - multiplication' }
242
+ { #category : ' testing - multiplication' }
241
243
PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [
242
244
243
245
| product expected p |
@@ -248,7 +250,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [
248
250
self assert: product equals: expected
249
251
]
250
252
251
- { #category : # ' testing - subtraction' }
253
+ { #category : ' testing - subtraction' }
252
254
PMPolynomialTest >> testPolynomialNumberSubtraction [
253
255
254
256
| polynomial expected |
@@ -258,7 +260,7 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [
258
260
self assert: (polynomial at: 3 ) equals: 0
259
261
]
260
262
261
- { #category : # ' testing - subtraction' }
263
+ { #category : ' testing - subtraction' }
262
264
PMPolynomialTest >> testPolynomialNumberSubtractionInverse [
263
265
264
266
| polynomial expected |
@@ -268,7 +270,7 @@ PMPolynomialTest >> testPolynomialNumberSubtractionInverse [
268
270
self assert: (polynomial at: 3 ) equals: 0
269
271
]
270
272
271
- { #category : # printing }
273
+ { #category : ' printing' }
272
274
PMPolynomialTest >> testPolynomialPrintOn [
273
275
| poly |
274
276
poly := PMPolynomial coefficients: #(1 0 1) .
@@ -277,7 +279,7 @@ PMPolynomialTest >> testPolynomialPrintOn [
277
279
self assert: poly printString equals: ' 1'
278
280
]
279
281
280
- { #category : # ' iterative algorithms' }
282
+ { #category : ' iterative algorithms' }
281
283
PMPolynomialTest >> testPolynomialRoots [
282
284
" Code Example 5.5"
283
285
@@ -290,7 +292,7 @@ PMPolynomialTest >> testPolynomialRoots [
290
292
self assert: (roots at: 3 ) - 5 closeTo: 0
291
293
]
292
294
293
- { #category : # ' iterative algorithms' }
295
+ { #category : ' iterative algorithms' }
294
296
PMPolynomialTest >> testPolynomialRootsConstantsHaveNoRoots [
295
297
296
298
| constant |
@@ -302,7 +304,7 @@ PMPolynomialTest >> testPolynomialRootsConstantsHaveNoRoots [
302
304
description: ' Function' ' s derivative seems to be zero everywhere'
303
305
]
304
306
305
- { #category : # ' iterative algorithms' }
307
+ { #category : ' iterative algorithms' }
306
308
PMPolynomialTest >> testPolynomialRootsForLinear [
307
309
308
310
| linearPolynomial roots |
@@ -313,7 +315,7 @@ PMPolynomialTest >> testPolynomialRootsForLinear [
313
315
self assert: (roots at: 1 ) closeTo: - 0.5
314
316
]
315
317
316
- { #category : # ' testing - subtraction' }
318
+ { #category : ' testing - subtraction' }
317
319
PMPolynomialTest >> testPolynomialSubtraction [
318
320
319
321
| polynomial p q expected |
@@ -325,7 +327,7 @@ PMPolynomialTest >> testPolynomialSubtraction [
325
327
self assert: (polynomial at: 4 ) equals: 0
326
328
]
327
329
328
- { #category : # ' iterative algorithms' }
330
+ { #category : ' iterative algorithms' }
329
331
PMPolynomialTest >> testPolynomialWithRepeatedRoots [
330
332
| polynomialWithRepeatedRoots roots |
331
333
" Here, compute the roots of the quadratic (2x + 1)^2 = 4 x^2 + 4 x + 1"
0 commit comments