@@ -235,13 +235,36 @@ PMPolynomialTest >> testPolynomialRoots [
235235
236236 | polynomial roots |
237237 polynomial := PMPolynomial coefficients: #( -10 -13 -2 1 ) .
238- roots := polynomial roots asSortedCollection asArray .
238+ roots := polynomial roots .
239239 self assert: roots size equals: 3 .
240240 self assert: (roots at: 1 ) + 2 closeTo: 0 .
241241 self assert: (roots at: 2 ) + 1 closeTo: 0 .
242242 self assert: (roots at: 3 ) - 5 closeTo: 0
243243]
244244
245+ { #category : #' iterative algorithms' }
246+ PMPolynomialTest >> testPolynomialRootsConstantsHaveNoRoots [
247+
248+ | constant |
249+ " Here, compute the roots of the constant C = 1"
250+ constant := PMPolynomial coefficients: #( 1 ) .
251+ self
252+ should: [ constant roots ]
253+ raise: Error
254+ description: ' Function' ' s derivative seems to be zero everywhere'
255+ ]
256+
257+ { #category : #' iterative algorithms' }
258+ PMPolynomialTest >> testPolynomialRootsForLinear [
259+
260+ | linearPolynomial roots |
261+ " Here, compute the roots of the linear (2x + 1)"
262+ linearPolynomial := PMPolynomial coefficients: #( 1 2 ) .
263+ roots := linearPolynomial roots.
264+ self assert: roots size equals: 1 .
265+ self assert: (roots at: 1 ) closeTo: - 0.5
266+ ]
267+
245268{ #category : #' function evaluation' }
246269PMPolynomialTest >> testPolynomialSubtraction [
247270 | polynomial |
@@ -253,3 +276,14 @@ PMPolynomialTest >> testPolynomialSubtraction [
253276 self assert: (polynomial at: 3 ) equals: - 1 .
254277 self assert: (polynomial at: 4 ) equals: 0
255278]
279+
280+ { #category : #' iterative algorithms' }
281+ PMPolynomialTest >> testPolynomialWithRepeatedRoots [
282+ | polynomialWithRepeatedRoots roots |
283+ " Here, compute the roots of the quadratic (2x + 1)^2 = 4 x^2 + 4 x + 1"
284+ polynomialWithRepeatedRoots := PMPolynomial coefficients: #(1 4 4) .
285+ roots := polynomialWithRepeatedRoots roots .
286+ self assert: roots size equals: 2 .
287+ self assert: (roots at: 1 ) closeTo: - 0.5 .
288+ self assert: (roots at: 2 ) closeTo: - 0.5 .
289+ ]
0 commit comments