From cf051148d8b99c252725f5d766e622cadef5246a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 16:24:10 +0000 Subject: [PATCH 01/42] refactor: Extract a method which encapsulates how to calculate the root of a function. --- src/Math-Numerical/PMNewtonZeroFinder.class.st | 7 +++++++ src/Math-Polynomials/PMPolynomial.class.st | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Math-Numerical/PMNewtonZeroFinder.class.st b/src/Math-Numerical/PMNewtonZeroFinder.class.st index 9f5f2303..7e15ce50 100644 --- a/src/Math-Numerical/PMNewtonZeroFinder.class.st +++ b/src/Math-Numerical/PMNewtonZeroFinder.class.st @@ -114,6 +114,13 @@ PMNewtonZeroFinder >> initialize [ ^ self ] +{ #category : #operation } +PMNewtonZeroFinder >> rootOf: function [ +self setFunction: function; + setDerivative: function derivative. + ^ self evaluate. +] + { #category : #initialization } PMNewtonZeroFinder >> setDerivative: aBlock [ "Defines the derivative of the function for which zeroes will be found. diff --git a/src/Math-Polynomials/PMPolynomial.class.st b/src/Math-Polynomials/PMPolynomial.class.st index d941313e..8bab0caa 100644 --- a/src/Math-Polynomials/PMPolynomial.class.st +++ b/src/Math-Polynomials/PMPolynomial.class.st @@ -245,10 +245,7 @@ PMPolynomial >> roots: aNumber [ (coefficients reverse collect: [ :each | each asFloat ]). roots := OrderedCollection new: self degree. [ - rootFinder - setFunction: pol; - setDerivative: pol derivative. - root := rootFinder evaluate. + root := rootFinder rootOf: pol. rootFinder hasConverged ] whileTrue: [ roots add: root. pol := pol deflatedAt: root. From 8ebadd3048a57117920a19483dbe088e8cc63868 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 16:26:11 +0000 Subject: [PATCH 02/42] refactor: Rename Variable, where we clarified the name by using the full form. --- src/Math-Polynomials/PMPolynomial.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math-Polynomials/PMPolynomial.class.st b/src/Math-Polynomials/PMPolynomial.class.st index 8bab0caa..efbe9342 100644 --- a/src/Math-Polynomials/PMPolynomial.class.st +++ b/src/Math-Polynomials/PMPolynomial.class.st @@ -239,17 +239,17 @@ PMPolynomial >> roots [ { #category : #information } PMPolynomial >> roots: aNumber [ - | pol roots root rootFinder | + | polynomial roots root rootFinder | rootFinder := PMNewtonZeroFinder with: aNumber. - pol := self class coefficients: + polynomial := self class coefficients: (coefficients reverse collect: [ :each | each asFloat ]). roots := OrderedCollection new: self degree. [ - root := rootFinder rootOf: pol. + root := rootFinder rootOf: polynomial. rootFinder hasConverged ] whileTrue: [ roots add: root. - pol := pol deflatedAt: root. - pol degree > 0 ifFalse: [ ^ roots ] ]. + polynomial := polynomial deflatedAt: root. + polynomial degree > 0 ifFalse: [ ^ roots ] ]. ^ roots ] From 5146d5921716270b59bd1e8085580270ce08a57d Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 18:51:15 +0000 Subject: [PATCH 03/42] refactor: use strictlyPositive to hide the type of Number being referred to. --- src/Math-Polynomials/PMPolynomial.class.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Math-Polynomials/PMPolynomial.class.st b/src/Math-Polynomials/PMPolynomial.class.st index efbe9342..157670a0 100644 --- a/src/Math-Polynomials/PMPolynomial.class.st +++ b/src/Math-Polynomials/PMPolynomial.class.st @@ -242,14 +242,14 @@ PMPolynomial >> roots: aNumber [ | polynomial roots root rootFinder | rootFinder := PMNewtonZeroFinder with: aNumber. polynomial := self class coefficients: - (coefficients reverse collect: [ :each | each asFloat ]). + (coefficients reverse collect: [ :each | each asFloat ]). roots := OrderedCollection new: self degree. [ root := rootFinder rootOf: polynomial. rootFinder hasConverged ] whileTrue: [ roots add: root. polynomial := polynomial deflatedAt: root. - polynomial degree > 0 ifFalse: [ ^ roots ] ]. + polynomial degree strictlyPositive ifFalse: [ ^ roots ] ]. ^ roots ] From c1146070a689acbd4dbab6a10b4ae59d1c7e218c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 20:06:36 +0000 Subject: [PATCH 04/42] refactor: clarified the name of a category. --- .../PMPolynomialTest.class.st | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index aa20322a..ae98c16f 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -13,7 +13,7 @@ PMPolynomialTest >> testIsZero [ self shouldnt: [ p2 isZero ] ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialAddition [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) @@ -25,7 +25,7 @@ PMPolynomialTest >> testPolynomialAddition [ self assert: (polynomial at: 4) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" @@ -38,7 +38,7 @@ PMPolynomialTest >> testPolynomialDerivative [ self assert: (polynomial at: 4) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialDivision [ | pol1 pol2 polynomial | pol1 := PMPolynomial coefficients: #(2 -3 1). @@ -53,7 +53,7 @@ PMPolynomialTest >> testPolynomialDivision [ self assert: (polynomial at: 6) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialDivisionBug [ "identify an error when trying to create a zero dividend" @@ -80,7 +80,7 @@ PMPolynomialTest >> testPolynomialDoubleDispatch [ self assert: n - p equals: (p - n) negated ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialEvaluation [ "Code example 2.2" @@ -105,7 +105,7 @@ PMPolynomialTest >> testPolynomialHash [ self assert: p3 hash equals: p2 hash ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialIntegral [ "Code example 2.3" @@ -119,7 +119,7 @@ PMPolynomialTest >> testPolynomialIntegral [ self assert: (polynomial at: 5) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialIntegralWithConstant [ "Code example 2.3" @@ -133,7 +133,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ self assert: (polynomial at: 5) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialMultiplication [ "Code example 2.3" @@ -150,7 +150,7 @@ PMPolynomialTest >> testPolynomialMultiplication [ self assert: (polynomial at: 6) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberAddition [ | polynomial | polynomial := 2 + (PMPolynomial coefficients: #(2 -3 1)). @@ -160,7 +160,7 @@ PMPolynomialTest >> testPolynomialNumberAddition [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberAdditionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) + 2. @@ -170,7 +170,7 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberDivision [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) / 2. @@ -180,7 +180,7 @@ PMPolynomialTest >> testPolynomialNumberDivision [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberMultiplication [ | polynomial | polynomial := 2 * (PMPolynomial coefficients: #(2 -3 1)). @@ -190,7 +190,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) * 2. @@ -200,7 +200,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberSubtraction [ | polynomial | polynomial := 2 - (PMPolynomial coefficients: #(2 -3 1)). @@ -210,7 +210,7 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialNumberSubtractionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) - 2. @@ -265,7 +265,7 @@ PMPolynomialTest >> testPolynomialRootsForLinear [ self assert: (roots at: 1) closeTo: -0.5 ] -{ #category : #'function evaluation' } +{ #category : #algebra } PMPolynomialTest >> testPolynomialSubtraction [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) From 645b5f5c7fe2d86b8ac091b5629f5e16689fbc13 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 20:09:16 +0000 Subject: [PATCH 05/42] refactor - recategorised the multiplication tests in preparation for more tests. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index ae98c16f..3daceebf 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -133,7 +133,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ self assert: (polynomial at: 5) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialMultiplication [ "Code example 2.3" @@ -180,7 +180,7 @@ PMPolynomialTest >> testPolynomialNumberDivision [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplication [ | polynomial | polynomial := 2 * (PMPolynomial coefficients: #(2 -3 1)). @@ -190,7 +190,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) * 2. From 43d01c71f2008abe53891bdc6b2e712a956a463c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 20:16:03 +0000 Subject: [PATCH 06/42] test: wrote a test to demonstrate that multiplication is commutative. --- .../PMPolynomialTest.class.st | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 3daceebf..c1d8e48e 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -150,6 +150,19 @@ PMPolynomialTest >> testPolynomialMultiplication [ self assert: (polynomial at: 6) equals: 0 ] +{ #category : #'algebra - multiplication' } +PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ + + | expected product commutationProduct p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + product := p * 2. + commutationProduct := 2 * p. + expected := PMPolynomial coefficients: #( 4 -6 2 ). + + self assert: product equals: expected. + self assert: commutationProduct equals: expected +] + { #category : #algebra } PMPolynomialTest >> testPolynomialNumberAddition [ | polynomial | From ca6a896891810c48b93cbb9968a6731e68a9650e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 20:17:49 +0000 Subject: [PATCH 07/42] refactor: made the test a little more generic. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index c1d8e48e..0de79dce 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -153,14 +153,13 @@ PMPolynomialTest >> testPolynomialMultiplication [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ - | expected product commutationProduct p | + | expected p q | p := PMPolynomial coefficients: #( 2 -3 1 ). - product := p * 2. - commutationProduct := 2 * p. + q := PMPolynomial coefficients: #( 2 ). expected := PMPolynomial coefficients: #( 4 -6 2 ). - - self assert: product equals: expected. - self assert: commutationProduct equals: expected + + self assert: p * q equals: expected. + self assert: q * p equals: expected ] { #category : #algebra } From 4ddb4efcc8af789820019aad24afabbdc59269c1 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:24:40 +0000 Subject: [PATCH 08/42] test: made the example a little more complicated (example derived from Wolfram Alpha). --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 0de79dce..4154932c 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -152,11 +152,13 @@ PMPolynomialTest >> testPolynomialMultiplication [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ - | expected p q | - p := PMPolynomial coefficients: #( 2 -3 1 ). - q := PMPolynomial coefficients: #( 2 ). - expected := PMPolynomial coefficients: #( 4 -6 2 ). + "p(x) = (x - 3) (x - 4), q(x) = x^3 + 1 therefore: + + p(x) * q(x) = q(x) * p(x) = x^5 - 7 x^4 + 12 x^3 + x^2 - 7x + 12" + p := PMPolynomial coefficients: #( 12 -7 1 ). + q := PMPolynomial coefficients: #( 1 0 0 1 ). + expected := PMPolynomial coefficients: #( 12 -7 1 12 -7 1 ). self assert: p * q equals: expected. self assert: q * p equals: expected From 8089cc27a64ad95bc276b1fd777efbf0d4cc594f Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:26:04 +0000 Subject: [PATCH 09/42] format: followed arrange, act and assert. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 4154932c..682fdc90 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -152,14 +152,15 @@ PMPolynomialTest >> testPolynomialMultiplication [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ + | expected p q | "p(x) = (x - 3) (x - 4), q(x) = x^3 + 1 therefore: p(x) * q(x) = q(x) * p(x) = x^5 - 7 x^4 + 12 x^3 + x^2 - 7x + 12" p := PMPolynomial coefficients: #( 12 -7 1 ). q := PMPolynomial coefficients: #( 1 0 0 1 ). + expected := PMPolynomial coefficients: #( 12 -7 1 12 -7 1 ). - self assert: p * q equals: expected. self assert: q * p equals: expected ] From 9fd2c1f2a48b292e72bcfddf3729b3ababa5e2f8 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:27:15 +0000 Subject: [PATCH 10/42] refactor: recategorised some tests for addition. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 682fdc90..9332e985 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -13,7 +13,7 @@ PMPolynomialTest >> testIsZero [ self shouldnt: [ p2 isZero ] ] -{ #category : #algebra } +{ #category : #'algebra - addition' } PMPolynomialTest >> testPolynomialAddition [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) @@ -165,7 +165,7 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ self assert: q * p equals: expected ] -{ #category : #algebra } +{ #category : #'algebra - addition' } PMPolynomialTest >> testPolynomialNumberAddition [ | polynomial | polynomial := 2 + (PMPolynomial coefficients: #(2 -3 1)). @@ -175,7 +175,7 @@ PMPolynomialTest >> testPolynomialNumberAddition [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - addition' } PMPolynomialTest >> testPolynomialNumberAdditionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) + 2. From 4d7ce1a60313c693e37d19ce5625ea9f648e60e7 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:29:00 +0000 Subject: [PATCH 11/42] refactor: recategorised more tests for the other binary operations. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 9332e985..717627b2 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -38,7 +38,7 @@ PMPolynomialTest >> testPolynomialDerivative [ self assert: (polynomial at: 4) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - division' } PMPolynomialTest >> testPolynomialDivision [ | pol1 pol2 polynomial | pol1 := PMPolynomial coefficients: #(2 -3 1). @@ -53,7 +53,7 @@ PMPolynomialTest >> testPolynomialDivision [ self assert: (polynomial at: 6) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - division' } PMPolynomialTest >> testPolynomialDivisionBug [ "identify an error when trying to create a zero dividend" @@ -185,7 +185,7 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - division' } PMPolynomialTest >> testPolynomialNumberDivision [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) / 2. @@ -215,7 +215,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtraction [ | polynomial | polynomial := 2 - (PMPolynomial coefficients: #(2 -3 1)). @@ -225,7 +225,7 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #algebra } +{ #category : #'algebra - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtractionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) - 2. @@ -280,7 +280,7 @@ PMPolynomialTest >> testPolynomialRootsForLinear [ self assert: (roots at: 1) closeTo: -0.5 ] -{ #category : #algebra } +{ #category : #'algebra - subtraction' } PMPolynomialTest >> testPolynomialSubtraction [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) From 4a23af2d851f129627225bc5e00ddc813a54f268 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:40:11 +0000 Subject: [PATCH 12/42] refactor: replaced multiple assertions with use of assert: equals: which uses the object's = message. --- .../PMPolynomialTest.class.st | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 717627b2..4ab322b1 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -137,17 +137,12 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ PMPolynomialTest >> testPolynomialMultiplication [ "Code example 2.3" - | pol1 pol2 polynomial | - pol1 := PMPolynomial coefficients: #(2 -3 1). - pol2 := PMPolynomial coefficients: #(-3 7 2 1). + | pol1 pol2 polynomial expected | + pol1 := PMPolynomial coefficients: #( 2 -3 1 ). + pol2 := PMPolynomial coefficients: #( -3 7 2 1 ). polynomial := pol1 * pol2. - self assert: (polynomial at: 0) equals: -6. - self assert: (polynomial at: 1) equals: 23. - self assert: (polynomial at: 2) equals: -20. - self assert: (polynomial at: 3) equals: 3. - self assert: (polynomial at: 4) equals: -1. - self assert: (polynomial at: 5) equals: 1. - self assert: (polynomial at: 6) equals: 0 + expected := PMPolynomial coefficients: #( -6 23 -20 3 -1 1 ). + self assert: polynomial equals: expected. ] { #category : #'algebra - multiplication' } From f8183357f8adb1b1cf60d3a4ed79382311409a0d Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:41:33 +0000 Subject: [PATCH 13/42] refactor: Rename Variable, where we give objects names similar to those used in mathematics. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 4ab322b1..49abf095 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -137,12 +137,12 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ PMPolynomialTest >> testPolynomialMultiplication [ "Code example 2.3" - | pol1 pol2 polynomial expected | - pol1 := PMPolynomial coefficients: #( 2 -3 1 ). - pol2 := PMPolynomial coefficients: #( -3 7 2 1 ). - polynomial := pol1 * pol2. + | p q product expected | + p := PMPolynomial coefficients: #( 2 -3 1 ). + q := PMPolynomial coefficients: #( -3 7 2 1 ). + product := p * q. expected := PMPolynomial coefficients: #( -6 23 -20 3 -1 1 ). - self assert: polynomial equals: expected. + self assert: product equals: expected. ] { #category : #'algebra - multiplication' } From 2bfcd0ea5033b936e133e27e9fefbd79e6883a0e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:44:29 +0000 Subject: [PATCH 14/42] refactor: we equate a product with its expected result directly. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 49abf095..48d41393 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -192,12 +192,12 @@ PMPolynomialTest >> testPolynomialNumberDivision [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplication [ - | polynomial | - polynomial := 2 * (PMPolynomial coefficients: #(2 -3 1)). - self assert: (polynomial at: 0) equals: 4. - self assert: (polynomial at: 1) equals: -6. - self assert: (polynomial at: 2) equals: 2. - self assert: (polynomial at: 3) equals: 0 + + | polynomial expected | + polynomial := 2 * (PMPolynomial coefficients: #( 2 -3 1 )). + + expected := PMPolynomial coefficients: #( 4 -6 2 ). + self assert: polynomial equals: expected ] { #category : #'algebra - multiplication' } From e0c2919da93a036f4f70eed9e1365af8244c13d7 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:46:45 +0000 Subject: [PATCH 15/42] refactor: Rename Variable with domain language. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 48d41393..83be566e 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -193,11 +193,11 @@ PMPolynomialTest >> testPolynomialNumberDivision [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplication [ - | polynomial expected | - polynomial := 2 * (PMPolynomial coefficients: #( 2 -3 1 )). + | product expected | + product := 2 * (PMPolynomial coefficients: #( 2 -3 1 )). expected := PMPolynomial coefficients: #( 4 -6 2 ). - self assert: polynomial equals: expected + self assert: product equals: expected ] { #category : #'algebra - multiplication' } From 05ba156b2113da74c22fcdd78b9c029bf5d473ce Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Mon, 25 Dec 2023 23:50:18 +0000 Subject: [PATCH 16/42] refactor: used the assert: equals message rather than check each coefficient. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 83be566e..188f8f44 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -202,12 +202,12 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) * 2. - self assert: (polynomial at: 0) equals: 4. - self assert: (polynomial at: 1) equals: -6. - self assert: (polynomial at: 2) equals: 2. - self assert: (polynomial at: 3) equals: 0 + + | polynomial expected | + polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) * 2. + + expected := PMPolynomial coefficients: #( 4 -6 2 ). + self assert: polynomial equals: expected ] { #category : #'algebra - subtraction' } From 4b7f888bccd5791493b35b2b51e7ce710a7452ce Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 09:10:54 +0000 Subject: [PATCH 17/42] refactor: Rename Variable so it reflects the role played by the object. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 188f8f44..23a38026 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -203,11 +203,11 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ { #category : #'algebra - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ - | polynomial expected | - polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) * 2. + | product expected | + product := (PMPolynomial coefficients: #( 2 -3 1 )) * 2. expected := PMPolynomial coefficients: #( 4 -6 2 ). - self assert: polynomial equals: expected + self assert: product equals: expected ] { #category : #'algebra - subtraction' } From fa9b49daaf99f680506d7af8ac838ac1b604b32a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 09:17:26 +0000 Subject: [PATCH 18/42] refactor: renamed protocols to make similar code even more similar. --- .../PMPolynomialTest.class.st | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 23a38026..5aa8b235 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -13,7 +13,7 @@ PMPolynomialTest >> testIsZero [ self shouldnt: [ p2 isZero ] ] -{ #category : #'algebra - addition' } +{ #category : #'testing - addition' } PMPolynomialTest >> testPolynomialAddition [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) @@ -38,7 +38,7 @@ PMPolynomialTest >> testPolynomialDerivative [ self assert: (polynomial at: 4) equals: 0 ] -{ #category : #'algebra - division' } +{ #category : #'testing - division' } PMPolynomialTest >> testPolynomialDivision [ | pol1 pol2 polynomial | pol1 := PMPolynomial coefficients: #(2 -3 1). @@ -53,7 +53,7 @@ PMPolynomialTest >> testPolynomialDivision [ self assert: (polynomial at: 6) equals: 0 ] -{ #category : #'algebra - division' } +{ #category : #'testing - division' } PMPolynomialTest >> testPolynomialDivisionBug [ "identify an error when trying to create a zero dividend" @@ -133,7 +133,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ self assert: (polynomial at: 5) equals: 0 ] -{ #category : #'algebra - multiplication' } +{ #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialMultiplication [ "Code example 2.3" @@ -145,7 +145,7 @@ PMPolynomialTest >> testPolynomialMultiplication [ self assert: product equals: expected. ] -{ #category : #'algebra - multiplication' } +{ #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ | expected p q | @@ -160,7 +160,7 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ self assert: q * p equals: expected ] -{ #category : #'algebra - addition' } +{ #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAddition [ | polynomial | polynomial := 2 + (PMPolynomial coefficients: #(2 -3 1)). @@ -170,7 +170,7 @@ PMPolynomialTest >> testPolynomialNumberAddition [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'algebra - addition' } +{ #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAdditionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) + 2. @@ -180,7 +180,7 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'algebra - division' } +{ #category : #'testing - division' } PMPolynomialTest >> testPolynomialNumberDivision [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) / 2. @@ -190,7 +190,7 @@ PMPolynomialTest >> testPolynomialNumberDivision [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'algebra - multiplication' } +{ #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplication [ | product expected | @@ -200,7 +200,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ self assert: product equals: expected ] -{ #category : #'algebra - multiplication' } +{ #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ | product expected | @@ -210,7 +210,7 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ self assert: product equals: expected ] -{ #category : #'algebra - subtraction' } +{ #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtraction [ | polynomial | polynomial := 2 - (PMPolynomial coefficients: #(2 -3 1)). @@ -220,7 +220,7 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [ self assert: (polynomial at: 3) equals: 0 ] -{ #category : #'algebra - subtraction' } +{ #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtractionInverse [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) - 2. @@ -275,7 +275,7 @@ PMPolynomialTest >> testPolynomialRootsForLinear [ self assert: (roots at: 1) closeTo: -0.5 ] -{ #category : #'algebra - subtraction' } +{ #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialSubtraction [ | polynomial | polynomial := (PMPolynomial coefficients: #(2 -3 1)) From 7e46a25290051ac0c88bb4be8631bb1a695d0b5a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 09:19:59 +0000 Subject: [PATCH 19/42] refactor: renamed Protocols to make similar code even more similar. --- .../PMPolynomialTest.class.st | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 5aa8b235..ac815685 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -4,7 +4,7 @@ Class { #category : #'Math-Tests-Polynomials' } -{ #category : #comparing } +{ #category : #'testing - comparing' } PMPolynomialTest >> testIsZero [ | p1 p2 | p1 := PMPolynomial coefficients: #(0 0 0 0 0). @@ -25,7 +25,7 @@ PMPolynomialTest >> testPolynomialAddition [ self assert: (polynomial at: 4) equals: 0 ] -{ #category : #algebra } +{ #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" @@ -63,7 +63,7 @@ PMPolynomialTest >> testPolynomialDivisionBug [ self shouldnt: [ pol1 / pol2 ] raise: Error ] -{ #category : #arithmetic } +{ #category : #'testing - arithmetic' } PMPolynomialTest >> testPolynomialDoubleDispatch [ | n p | n := 3.2. @@ -80,7 +80,7 @@ PMPolynomialTest >> testPolynomialDoubleDispatch [ self assert: n - p equals: (p - n) negated ] -{ #category : #algebra } +{ #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialEvaluation [ "Code example 2.2" @@ -89,7 +89,7 @@ PMPolynomialTest >> testPolynomialEvaluation [ self assert: 0 equals: (polynomial value: 1) ] -{ #category : #comparing } +{ #category : #'testing - comparing' } PMPolynomialTest >> testPolynomialHash [ "polynomial hash is hash of coefficient array" @@ -105,7 +105,7 @@ PMPolynomialTest >> testPolynomialHash [ self assert: p3 hash equals: p2 hash ] -{ #category : #algebra } +{ #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialIntegral [ "Code example 2.3" @@ -119,7 +119,7 @@ PMPolynomialTest >> testPolynomialIntegral [ self assert: (polynomial at: 5) equals: 0 ] -{ #category : #algebra } +{ #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialIntegralWithConstant [ "Code example 2.3" From 4b0e6ce6a87fe1fd283875aaf107f61c0d136eed Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 09:23:04 +0000 Subject: [PATCH 20/42] refactor: we can use Polynomial's = message to reduce number of assertions. --- .../PMPolynomialTest.class.st | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index ac815685..c74a080d 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -15,13 +15,12 @@ PMPolynomialTest >> testIsZero [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialAddition [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) - + (PMPolynomial coefficients: #(-3 7 2 1)). - self assert: (polynomial at: 0) equals: -1. - self assert: (polynomial at: 1) equals: 4. - self assert: (polynomial at: 2) equals: 3. - self assert: (polynomial at: 3) equals: 1. + + | polynomial expected | + polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) + + (PMPolynomial coefficients: #( -3 7 2 1 )). + expected := PMPolynomial coefficients: #( -1 4 3 1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 4) equals: 0 ] From c56bdc1269b739df882fa1e6c6cda9cfb5ff955a Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 09:25:13 +0000 Subject: [PATCH 21/42] refactor: we can use the Polynomial's = method to reduce the number of assertions and make the tests more DSL like. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index c74a080d..c66a9db6 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -161,11 +161,11 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAddition [ - | polynomial | - polynomial := 2 + (PMPolynomial coefficients: #(2 -3 1)). - self assert: (polynomial at: 0) equals: 4. - self assert: (polynomial at: 1) equals: -3. - self assert: (polynomial at: 2) equals: 1. + + | polynomial expected | + polynomial := 2 + (PMPolynomial coefficients: #( 2 -3 1 )). + expected := PMPolynomial coefficients: #( 4 -3 1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 ] From 03ae30d37688a2a9adeb5f00fee2a72a81080e46 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:02:37 +0000 Subject: [PATCH 22/42] test: added a missing test to demonstrate that polynomial addition is commutative. --- .../PMPolynomialTest.class.st | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index c66a9db6..19d40d4d 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -24,6 +24,18 @@ PMPolynomialTest >> testPolynomialAddition [ self assert: (polynomial at: 4) equals: 0 ] +{ #category : #'testing - addition' } +PMPolynomialTest >> testPolynomialAdditionIsCommutative [ + + | p q expected | + p := PMPolynomial coefficients: #(1 2 4 8). + q := PMPolynomial coefficients: #(-1 3 7 -4). + + expected := PMPolynomial coefficients: #(0 5 11 4). + self assert: p + q equals: expected. + self assert: q + p equals: expected +] + { #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" @@ -171,11 +183,11 @@ PMPolynomialTest >> testPolynomialNumberAddition [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAdditionInverse [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) + 2. - self assert: (polynomial at: 0) equals: 4. - self assert: (polynomial at: 1) equals: -3. - self assert: (polynomial at: 2) equals: 1. + + | polynomial expected | + polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) + 2. + expected := PMPolynomial coefficients: #( 4 -3 1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 ] From 31baea44a3ca2c06ce7e5353f222dbca80a8a081 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:06:27 +0000 Subject: [PATCH 23/42] refactor: used the assert: equals: message to take advantage of Polynomial's = message. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 19d40d4d..90043214 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -40,11 +40,10 @@ PMPolynomialTest >> testPolynomialAdditionIsCommutative [ PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" - | polynomial | - polynomial := (PMPolynomial coefficients: #(-3 7 2 1)) derivative. - self assert: (polynomial at: 0) equals: 7. - self assert: (polynomial at: 1) equals: 4. - self assert: (polynomial at: 2) equals: 3. + | polynomial expectedDerivative | + polynomial := (PMPolynomial coefficients: #( -3 7 2 1 )) derivative. + expectedDerivative := PMPolynomial coefficients: #( 7 4 3 ). + self assert: polynomial equals: expectedDerivative. self assert: (polynomial at: 3) equals: 0. self assert: (polynomial at: 4) equals: 0 ] From c76f8f920dffcf9de7af83ec57ef51215b12bdaa Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:08:22 +0000 Subject: [PATCH 24/42] refactor: extracted temp, renamed a temp to tell a better story. --- .../PMPolynomialTest.class.st | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 90043214..cc3e8383 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -40,12 +40,15 @@ PMPolynomialTest >> testPolynomialAdditionIsCommutative [ PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" - | polynomial expectedDerivative | - polynomial := (PMPolynomial coefficients: #( -3 7 2 1 )) derivative. + | p derivative expectedDerivative | + p := PMPolynomial coefficients: #( -3 7 2 1 ). + + derivative := p derivative. + expectedDerivative := PMPolynomial coefficients: #( 7 4 3 ). - self assert: polynomial equals: expectedDerivative. - self assert: (polynomial at: 3) equals: 0. - self assert: (polynomial at: 4) equals: 0 + self assert: derivative equals: expectedDerivative. + self assert: (derivative at: 3) equals: 0. + self assert: (derivative at: 4) equals: 0 ] { #category : #'testing - division' } From 6f02880e105555d7eed90dba7f9e2b027f5b9a3e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:10:03 +0000 Subject: [PATCH 25/42] test: added a comment describing the example the way a mathematician would understand it. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index cc3e8383..6148fbce 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -39,6 +39,10 @@ PMPolynomialTest >> testPolynomialAdditionIsCommutative [ { #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialDerivative [ "Code example 2.3" + " + p(x) = x^3 + 2x^2 + 7x - 3, therefore: + p'(x) = 3x^2 + 4x + 7 + " | p derivative expectedDerivative | p := PMPolynomial coefficients: #( -3 7 2 1 ). From 26f762cd1e918f2ee29bcdac39ed3d0ff357a861 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:26:22 +0000 Subject: [PATCH 26/42] refactor: replaced equating constants with equating polynomials. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 6148fbce..71482c7c 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -229,11 +229,11 @@ PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ { #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtraction [ - | polynomial | - polynomial := 2 - (PMPolynomial coefficients: #(2 -3 1)). - self assert: (polynomial at: 0) equals: 0. - self assert: (polynomial at: 1) equals: 3. - self assert: (polynomial at: 2) equals: -1. + + | polynomial expected | + polynomial := 2 - (PMPolynomial coefficients: #( 2 -3 1 )). + expected := PMPolynomial coefficients: #( 0 3 -1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 ] From 1d0897046a4a26a737ebf56ae6c66dc97b7b047e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:28:35 +0000 Subject: [PATCH 27/42] refactor: replaced equating coefficients with equating the polynomial. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 71482c7c..0f5ed3ea 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -239,11 +239,11 @@ PMPolynomialTest >> testPolynomialNumberSubtraction [ { #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialNumberSubtractionInverse [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) - 2. - self assert: (polynomial at: 0) equals: 0. - self assert: (polynomial at: 1) equals: -3. - self assert: (polynomial at: 2) equals: 1. + + | polynomial expected | + polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) - 2. + expected := PMPolynomial coefficients: #( 0 -3 1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 ] From 84b6af90e72922e6666a675616f19855fd0fc203 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:29:53 +0000 Subject: [PATCH 28/42] refactor: extract temp so we can show the computation being tested clearly. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 0f5ed3ea..89a0fcbb 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -294,9 +294,11 @@ PMPolynomialTest >> testPolynomialRootsForLinear [ { #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialSubtraction [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) - - (PMPolynomial coefficients: #(-3 7 2 1)). + + | polynomial p q | + p := PMPolynomial coefficients: #( 2 -3 1 ). + q := PMPolynomial coefficients: #( -3 7 2 1 ). + polynomial := p - q. self assert: (polynomial at: 0) equals: 5. self assert: (polynomial at: 1) equals: -10. self assert: (polynomial at: 2) equals: -1. From aaefdcfca1668903e2418dc1ed957a33977b3063 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:33:44 +0000 Subject: [PATCH 29/42] refactor: replaced equating coefficients with equating Polynomials. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 89a0fcbb..923c3fb4 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -295,14 +295,12 @@ PMPolynomialTest >> testPolynomialRootsForLinear [ { #category : #'testing - subtraction' } PMPolynomialTest >> testPolynomialSubtraction [ - | polynomial p q | + | polynomial p q expected | p := PMPolynomial coefficients: #( 2 -3 1 ). q := PMPolynomial coefficients: #( -3 7 2 1 ). polynomial := p - q. - self assert: (polynomial at: 0) equals: 5. - self assert: (polynomial at: 1) equals: -10. - self assert: (polynomial at: 2) equals: -1. - self assert: (polynomial at: 3) equals: -1. + expected := PMPolynomial coefficients: #( 5 -10 -1 -1 ). + self assert: polynomial equals: expected. self assert: (polynomial at: 4) equals: 0 ] From 4ddc12b3319299d8d72a722a0c43f5f522896dcb Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:37:18 +0000 Subject: [PATCH 30/42] test: Extract Variable, so that the operation being tested clear. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 923c3fb4..fea49c4d 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -16,9 +16,10 @@ PMPolynomialTest >> testIsZero [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialAddition [ - | polynomial expected | - polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) - + (PMPolynomial coefficients: #( -3 7 2 1 )). + | polynomial expected p q | + p := PMPolynomial coefficients: #( 2 -3 1 ). + q := PMPolynomial coefficients: #( -3 7 2 1 ). + polynomial := p + q. expected := PMPolynomial coefficients: #( -1 4 3 1 ). self assert: polynomial equals: expected. self assert: (polynomial at: 4) equals: 0 From 75c2fd8e752870b0f4db625fc22a36e9cf13801e Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:38:38 +0000 Subject: [PATCH 31/42] refactor: Extract Variable so we can show the operation being tested clearly. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index fea49c4d..7000186c 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -181,8 +181,9 @@ PMPolynomialTest >> testPolynomialMultiplicationIsCommutative [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAddition [ - | polynomial expected | - polynomial := 2 + (PMPolynomial coefficients: #( 2 -3 1 )). + | polynomial expected p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + polynomial := 2 + p. expected := PMPolynomial coefficients: #( 4 -3 1 ). self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 @@ -191,8 +192,9 @@ PMPolynomialTest >> testPolynomialNumberAddition [ { #category : #'testing - addition' } PMPolynomialTest >> testPolynomialNumberAdditionInverse [ - | polynomial expected | - polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) + 2. + | polynomial expected p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + polynomial := p + 2. expected := PMPolynomial coefficients: #( 4 -3 1 ). self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 From d4fed030aca4c6a34b2313cd2e298c8a1f832dc3 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 19:52:24 +0000 Subject: [PATCH 32/42] refactor: Extract Variable so we can demonstrate the operation being tested clearly. --- .../PMPolynomialTest.class.st | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 7000186c..ad2fbdc9 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -213,9 +213,10 @@ PMPolynomialTest >> testPolynomialNumberDivision [ { #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplication [ - | product expected | - product := 2 * (PMPolynomial coefficients: #( 2 -3 1 )). - + | product expected p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + product := 2 * p. + expected := PMPolynomial coefficients: #( 4 -6 2 ). self assert: product equals: expected ] @@ -223,9 +224,10 @@ PMPolynomialTest >> testPolynomialNumberMultiplication [ { #category : #'testing - multiplication' } PMPolynomialTest >> testPolynomialNumberMultiplicationInverse [ - | product expected | - product := (PMPolynomial coefficients: #( 2 -3 1 )) * 2. - + | product expected p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + product := p * 2. + expected := PMPolynomial coefficients: #( 4 -6 2 ). self assert: product equals: expected ] From 2ba7c68cdeeea5e68d53fba433f697ded805d418 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 21:21:02 +0000 Subject: [PATCH 33/42] refactor: replaced assertions on coefficients with a Polynomial. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index ad2fbdc9..3f7ab126 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -202,11 +202,12 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [ { #category : #'testing - division' } PMPolynomialTest >> testPolynomialNumberDivision [ - | polynomial | - polynomial := (PMPolynomial coefficients: #(2 -3 1)) / 2. - self assert: (polynomial at: 0) equals: 1. - self assert: (polynomial at: 1) equals: -3 / 2. - self assert: (polynomial at: 2) equals: 1 / 2. + + | polynomial expected expectedCoefficients | + polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) / 2. + expectedCoefficients := Array with: 1 with: -3 / 2 with: 1 / 2. + expected := PMPolynomial coefficients: expectedCoefficients. + self assert: polynomial equals: expected. self assert: (polynomial at: 3) equals: 0 ] From 8320ec0d933a0b1c192876071484ae51cea53894 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 21:22:21 +0000 Subject: [PATCH 34/42] refactor: Extract variable so we can make the operation being tested clearer. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 3f7ab126..e3d4f2da 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -203,8 +203,9 @@ PMPolynomialTest >> testPolynomialNumberAdditionInverse [ { #category : #'testing - division' } PMPolynomialTest >> testPolynomialNumberDivision [ - | polynomial expected expectedCoefficients | - polynomial := (PMPolynomial coefficients: #( 2 -3 1 )) / 2. + | polynomial expected expectedCoefficients p | + p := PMPolynomial coefficients: #( 2 -3 1 ). + polynomial := p / 2. expectedCoefficients := Array with: 1 with: -3 / 2 with: 1 / 2. expected := PMPolynomial coefficients: expectedCoefficients. self assert: polynomial equals: expected. From 4b898584119b3c9b499b4d37249e845f2646f44c Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Wed, 27 Dec 2023 21:25:21 +0000 Subject: [PATCH 35/42] refactor: extracted the expected coefficients to a local variable to make equating Polynomials simpler. --- .../PMPolynomialTest.class.st | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index e3d4f2da..9e0978b9 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -127,13 +127,15 @@ PMPolynomialTest >> testPolynomialHash [ PMPolynomialTest >> testPolynomialIntegral [ "Code example 2.3" - | polynomial | - polynomial := (PMPolynomial coefficients: #(-3 7 2 1)) integral. - self assert: (polynomial at: 0) equals: 0. - self assert: (polynomial at: 1) equals: -3. - self assert: (polynomial at: 2) equals: 7 / 2. - self assert: (polynomial at: 3) equals: 2 / 3. - self assert: (polynomial at: 4) equals: 1 / 4. + | polynomial expectedCoefficients expected | + polynomial := (PMPolynomial coefficients: #( -3 7 2 1 )) integral. + expectedCoefficients := Array + with: 0 + with: -3 + with: 7 / 2 + with: 2 / 3 + with: 1 / 4. + expected := PMPolynomial coefficients: expectedCoefficients. self assert: (polynomial at: 5) equals: 0 ] From 63b37795593466255b0e736664b02f4eb67f2598 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 28 Dec 2023 09:39:24 +0000 Subject: [PATCH 36/42] refactor: extracted magic number and integrand to local variables. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 9e0978b9..b631408b 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -143,8 +143,10 @@ PMPolynomialTest >> testPolynomialIntegral [ PMPolynomialTest >> testPolynomialIntegralWithConstant [ "Code example 2.3" - | polynomial | - polynomial := (PMPolynomial coefficients: #(-3 7 2 1)) integral: 5. + | polynomial arbitraryConstant p | + arbitraryConstant := 5. + p := PMPolynomial coefficients: #( -3 7 2 1 ). + polynomial := p integral: arbitraryConstant. self assert: (polynomial at: 0) equals: 5. self assert: (polynomial at: 1) equals: -3. self assert: (polynomial at: 2) equals: 7 / 2. From a3e7f96d6dbeeaa992ff8976aab0a19841973945 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 28 Dec 2023 09:40:04 +0000 Subject: [PATCH 37/42] refactor: Rename Variable: the polynomial is the integrand. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index b631408b..f1e9b999 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -143,10 +143,10 @@ PMPolynomialTest >> testPolynomialIntegral [ PMPolynomialTest >> testPolynomialIntegralWithConstant [ "Code example 2.3" - | polynomial arbitraryConstant p | + | polynomial arbitraryConstant integrand | arbitraryConstant := 5. - p := PMPolynomial coefficients: #( -3 7 2 1 ). - polynomial := p integral: arbitraryConstant. + integrand := PMPolynomial coefficients: #( -3 7 2 1 ). + polynomial := integrand integral: arbitraryConstant. self assert: (polynomial at: 0) equals: 5. self assert: (polynomial at: 1) equals: -3. self assert: (polynomial at: 2) equals: 7 / 2. From ecb00fc3ede61c5af7cc58a5ddf511fef6e389c0 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Thu, 28 Dec 2023 09:42:23 +0000 Subject: [PATCH 38/42] refactor: reduce the number of assertions by equating polynomials rather than coefficients. --- .../PMPolynomialTest.class.st | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index f1e9b999..133d594a 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -143,15 +143,18 @@ PMPolynomialTest >> testPolynomialIntegral [ PMPolynomialTest >> testPolynomialIntegralWithConstant [ "Code example 2.3" - | polynomial arbitraryConstant integrand | + | polynomial arbitraryConstant integrand expectedCoefficients expected | arbitraryConstant := 5. integrand := PMPolynomial coefficients: #( -3 7 2 1 ). polynomial := integrand integral: arbitraryConstant. - self assert: (polynomial at: 0) equals: 5. - self assert: (polynomial at: 1) equals: -3. - self assert: (polynomial at: 2) equals: 7 / 2. - self assert: (polynomial at: 3) equals: 2 / 3. - self assert: (polynomial at: 4) equals: 1 / 4. + expectedCoefficients := Array + with: 5 + with: -3 + with: 7 / 2 + with: 2 / 3 + with: 1 / 4. + expected := PMPolynomial coefficients: expectedCoefficients. + self assert: polynomial equals: expected. self assert: (polynomial at: 5) equals: 0 ] From a286790f399d734fdecc80bff7adc0af8df734fb Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Sat, 30 Dec 2023 13:05:31 +0000 Subject: [PATCH 39/42] documentation: added documentation to demonstrate how a mathematician would integrate a polynomial w.r.t. x. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 133d594a..6ea64e8e 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -126,6 +126,11 @@ PMPolynomialTest >> testPolynomialHash [ { #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialIntegral [ "Code example 2.3" + " + Given p(x) = x^3 + 2x^2 + 7x - 3 + then the integral is I(x) = 1/4 x^3 + 2/3 x^3 + 7/2 x^2 - 3x + C, where C is an arbitary + constant. + " | polynomial expectedCoefficients expected | polynomial := (PMPolynomial coefficients: #( -3 7 2 1 )) integral. From efb2a87d2f3da1be71759d41f240b13a90a26aa9 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Sat, 30 Dec 2023 13:06:09 +0000 Subject: [PATCH 40/42] fix: corrected the documentation. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 6ea64e8e..0882397b 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -126,9 +126,10 @@ PMPolynomialTest >> testPolynomialHash [ { #category : #'testing - algebra' } PMPolynomialTest >> testPolynomialIntegral [ "Code example 2.3" + " Given p(x) = x^3 + 2x^2 + 7x - 3 - then the integral is I(x) = 1/4 x^3 + 2/3 x^3 + 7/2 x^2 - 3x + C, where C is an arbitary + then the integral is I(x) = 1/4 x^4 + 2/3 x^3 + 7/2 x^2 - 3x + C, where C is an arbitary constant. " From eb0a97fd3467297c9f340c422f92f5563a53535d Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Sat, 30 Dec 2023 13:07:20 +0000 Subject: [PATCH 41/42] fix: added a missing assertion. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 0882397b..7b1cc867 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -142,6 +142,7 @@ PMPolynomialTest >> testPolynomialIntegral [ with: 2 / 3 with: 1 / 4. expected := PMPolynomial coefficients: expectedCoefficients. + self assert: polynomial equals: expected . self assert: (polynomial at: 5) equals: 0 ] From 85c23987c89616ede6acd2d6953f4d33599d3409 Mon Sep 17 00:00:00 2001 From: hemalvarambhia Date: Sat, 30 Dec 2023 13:08:20 +0000 Subject: [PATCH 42/42] refactor: we can use the arbitrary constant in our expected coefficients of the integrated polynomial. --- src/Math-Tests-Polynomials/PMPolynomialTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st index 7b1cc867..554d95bc 100644 --- a/src/Math-Tests-Polynomials/PMPolynomialTest.class.st +++ b/src/Math-Tests-Polynomials/PMPolynomialTest.class.st @@ -155,7 +155,7 @@ PMPolynomialTest >> testPolynomialIntegralWithConstant [ integrand := PMPolynomial coefficients: #( -3 7 2 1 ). polynomial := integrand integral: arbitraryConstant. expectedCoefficients := Array - with: 5 + with: arbitraryConstant with: -3 with: 7 / 2 with: 2 / 3