Skip to content

Commit

Permalink
refactor: corrected an assertion that Pharo complained about from a s…
Browse files Browse the repository at this point in the history
…tyle perspective.
  • Loading branch information
hemalvarambhia committed Jun 9, 2024
1 parent d8d6fc0 commit 8da7c67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
64 changes: 33 additions & 31 deletions src/Math-Tests-Polynomials/PMPolynomialTest.class.st
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Class {
#name : #PMPolynomialTest,
#superclass : #TestCase,
#category : #'Math-Tests-Polynomials'
#name : 'PMPolynomialTest',
#superclass : 'TestCase',
#category : 'Math-Tests-Polynomials',
#package : 'Math-Tests-Polynomials'
}

{ #category : #'testing - comparing' }
{ #category : 'testing - comparing' }
PMPolynomialTest >> testIsZero [
| p1 p2 |
p1 := PMPolynomial coefficients: #(0 0 0 0 0).
Expand All @@ -13,7 +14,7 @@ PMPolynomialTest >> testIsZero [
self shouldnt: [ p2 isZero ]
]

{ #category : #'testing - addition' }
{ #category : 'testing - addition' }
PMPolynomialTest >> testPolynomialAddition [

| polynomial expected p q |
Expand All @@ -25,7 +26,7 @@ PMPolynomialTest >> testPolynomialAddition [
self assert: (polynomial at: 4) equals: 0
]

{ #category : #'testing - addition' }
{ #category : 'testing - addition' }
PMPolynomialTest >> testPolynomialAdditionIsCommutative [

| p q expected |
Expand All @@ -37,7 +38,7 @@ PMPolynomialTest >> testPolynomialAdditionIsCommutative [
self assert: q + p equals: expected
]

{ #category : #'testing - algebra' }
{ #category : 'testing - algebra' }
PMPolynomialTest >> testPolynomialDerivative [
"Code example 2.3"
"
Expand All @@ -56,7 +57,7 @@ PMPolynomialTest >> testPolynomialDerivative [
self assert: (derivative at: 4) equals: 0
]

{ #category : #'testing - division' }
{ #category : 'testing - division' }
PMPolynomialTest >> testPolynomialDivision [
| pol1 pol2 polynomial |
pol1 := PMPolynomial coefficients: #(2 -3 1).
Expand All @@ -71,17 +72,18 @@ PMPolynomialTest >> testPolynomialDivision [
self assert: (polynomial at: 6) equals: 0
]

{ #category : #'testing - division' }
{ #category : 'testing - division' }
PMPolynomialTest >> testPolynomialDivisionBug [
"identify an error when trying to create a zero dividend"

| pol1 pol2 |
| pol1 pol2 zero|
pol1 := PMPolynomial coefficients: #( 2 -3 1 ).
pol2 := PMPolynomial coefficients: #( -6 23 -20 3 -1 1 ).
self shouldnt: [ pol1 / pol2 ] raise: Error
zero := PMPolynomial coefficients: #(0).
self assert: pol1 / pol2 equals: zero.
]

{ #category : #'testing - arithmetic' }
{ #category : 'testing - arithmetic' }
PMPolynomialTest >> testPolynomialDoubleDispatch [
| n p |
n := 3.2.
Expand All @@ -98,7 +100,7 @@ PMPolynomialTest >> testPolynomialDoubleDispatch [
self assert: n - p equals: (p - n) negated
]

{ #category : #'testing - algebra' }
{ #category : 'testing - algebra' }
PMPolynomialTest >> testPolynomialEvaluation [
"Code example 2.2"

Expand All @@ -107,7 +109,7 @@ PMPolynomialTest >> testPolynomialEvaluation [
self assert: 0 equals: (polynomial value: 1)
]

{ #category : #'testing - comparing' }
{ #category : 'testing - comparing' }
PMPolynomialTest >> testPolynomialHash [
"polynomial hash is hash of coefficient array"

Expand All @@ -123,7 +125,7 @@ PMPolynomialTest >> testPolynomialHash [
self assert: p3 hash equals: p2 hash
]

{ #category : #'testing - algebra' }
{ #category : 'testing - algebra' }
PMPolynomialTest >> testPolynomialIntegral [
"Code example 2.3"

Expand All @@ -146,7 +148,7 @@ PMPolynomialTest >> testPolynomialIntegral [
self assert: (polynomial at: 5) equals: 0
]

{ #category : #'testing - algebra' }
{ #category : 'testing - algebra' }
PMPolynomialTest >> testPolynomialIntegralWithConstant [
"Code example 2.3"

Expand All @@ -165,7 +167,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [
self assert: (polynomial at: 5) equals: 0
]

{ #category : #'testing - multiplication' }
{ #category : 'testing - multiplication' }
PMPolynomialTest >> testPolynomialMultiplication [
"Code example 2.3"

Expand All @@ -177,7 +179,7 @@ PMPolynomialTest >> testPolynomialMultiplication [
self assert: product equals: expected.
]

{ #category : #'testing - multiplication' }
{ #category : 'testing - multiplication' }
PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [

| expected p q |
Expand All @@ -192,7 +194,7 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [
self assert: q * p equals: expected
]

{ #category : #'testing - addition' }
{ #category : 'testing - addition' }
PMPolynomialTest >> testPolynomialNumberAddition [

| polynomial expected p |
Expand All @@ -203,7 +205,7 @@ PMPolynomialTest >> testPolynomialNumberAddition [
self assert: (polynomial at: 3) equals: 0
]

{ #category : #'testing - addition' }
{ #category : 'testing - addition' }
PMPolynomialTest >> testPolynomialNumberAdditionInverse [

| polynomial expected p |
Expand All @@ -214,7 +216,7 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [
self assert: (polynomial at: 3) equals: 0
]

{ #category : #'testing - division' }
{ #category : 'testing - division' }
PMPolynomialTest >> testPolynomialNumberDivision [

| polynomial expected expectedCoefficients p |
Expand All @@ -226,7 +228,7 @@ PMPolynomialTest >> testPolynomialNumberDivision [
self assert: (polynomial at: 3) equals: 0
]

{ #category : #'testing - multiplication' }
{ #category : 'testing - multiplication' }
PMPolynomialTest >> testPolynomialNumberMultiplication [

| product expected p |
Expand All @@ -237,7 +239,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [
self assert: product equals: expected
]

{ #category : #'testing - multiplication' }
{ #category : 'testing - multiplication' }
PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [

| product expected p |
Expand All @@ -248,7 +250,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [
self assert: product equals: expected
]

{ #category : #'testing - subtraction' }
{ #category : 'testing - subtraction' }
PMPolynomialTest >> testPolynomialNumberSubtraction [

| polynomial expected |
Expand All @@ -258,7 +260,7 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [
self assert: (polynomial at: 3) equals: 0
]

{ #category : #'testing - subtraction' }
{ #category : 'testing - subtraction' }
PMPolynomialTest >> testPolynomialNumberSubtractionInverse [

| polynomial expected |
Expand All @@ -268,7 +270,7 @@ PMPolynomialTest >> testPolynomialNumberSubtractionInverse [
self assert: (polynomial at: 3) equals: 0
]

{ #category : #printing }
{ #category : 'printing' }
PMPolynomialTest >> testPolynomialPrintOn [
| poly |
poly := PMPolynomial coefficients: #(1 0 1).
Expand All @@ -277,7 +279,7 @@ PMPolynomialTest >> testPolynomialPrintOn [
self assert: poly printString equals: '1'
]

{ #category : #'iterative algorithms' }
{ #category : 'iterative algorithms' }
PMPolynomialTest >> testPolynomialRoots [
"Code Example 5.5"

Expand All @@ -290,7 +292,7 @@ PMPolynomialTest >> testPolynomialRoots [
self assert: (roots at: 3) - 5 closeTo: 0
]

{ #category : #'iterative algorithms' }
{ #category : 'iterative algorithms' }
PMPolynomialTest >> testPolynomialRootsConstantsHaveNoRoots [

| constant |
Expand All @@ -302,7 +304,7 @@ PMPolynomialTest >> testPolynomialRootsConstantsHaveNoRoots [
description: 'Function''s derivative seems to be zero everywhere'
]

{ #category : #'iterative algorithms' }
{ #category : 'iterative algorithms' }
PMPolynomialTest >> testPolynomialRootsForLinear [

| linearPolynomial roots |
Expand All @@ -313,7 +315,7 @@ PMPolynomialTest >> testPolynomialRootsForLinear [
self assert: (roots at: 1) closeTo: -0.5
]

{ #category : #'testing - subtraction' }
{ #category : 'testing - subtraction' }
PMPolynomialTest >> testPolynomialSubtraction [

| polynomial p q expected |
Expand All @@ -325,7 +327,7 @@ PMPolynomialTest >> testPolynomialSubtraction [
self assert: (polynomial at: 4) equals: 0
]

{ #category : #'iterative algorithms' }
{ #category : 'iterative algorithms' }
PMPolynomialTest >> testPolynomialWithRepeatedRoots [
| polynomialWithRepeatedRoots roots |
"Here, compute the roots of the quadratic (2x + 1)^2 = 4 x^2 + 4 x + 1"
Expand Down
2 changes: 1 addition & 1 deletion src/Math-Tests-Polynomials/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Math-Tests-Polynomials' }
Package { #name : 'Math-Tests-Polynomials' }

0 comments on commit 8da7c67

Please sign in to comment.