Skip to content

Commit 03ae30d

Browse files
test: added a missing test to demonstrate that polynomial addition is commutative.
1 parent c56bdc1 commit 03ae30d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/Math-Tests-Polynomials/PMPolynomialTest.class.st

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ PMPolynomialTest >> testPolynomialAddition [
2424
self assert: (polynomial at: 4) equals: 0
2525
]
2626

27+
{ #category : #'testing - addition' }
28+
PMPolynomialTest >> testPolynomialAdditionIsCommutative [
29+
30+
| p q expected |
31+
p := PMPolynomial coefficients: #(1 2 4 8).
32+
q := PMPolynomial coefficients: #(-1 3 7 -4).
33+
34+
expected := PMPolynomial coefficients: #(0 5 11 4).
35+
self assert: p + q equals: expected.
36+
self assert: q + p equals: expected
37+
]
38+
2739
{ #category : #'testing - algebra' }
2840
PMPolynomialTest >> testPolynomialDerivative [
2941
"Code example 2.3"
@@ -171,11 +183,11 @@ PMPolynomialTest >> testPolynomialNumberAddition [
171183

172184
{ #category : #'testing - addition' }
173185
PMPolynomialTest >> testPolynomialNumberAdditionInverse [
174-
| polynomial |
175-
polynomial := (PMPolynomial coefficients: #(2 -3 1)) + 2.
176-
self assert: (polynomial at: 0) equals: 4.
177-
self assert: (polynomial at: 1) equals: -3.
178-
self assert: (polynomial at: 2) equals: 1.
186+
187+
| polynomial expected |
188+
polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) + 2.
189+
expected := PMPolynomial coefficients: #( 4 -3 1 ).
190+
self assert: polynomial equals: expected.
179191
self assert: (polynomial at: 3) equals: 0
180192
]
181193

0 commit comments

Comments
 (0)