From 2ad957b978713af9607bbd4275ec1e5fac116365 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 11:58:06 +0000 Subject: [PATCH 01/13] [issue-154] Moved the test method to its own test case class so that we can break up the long test method and understand the message better. --- .../PMAccuracyTest.class.st | 34 --------- .../PMDataTreeTest.class.st | 70 +++++++++++++++++++ 2 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 src/Math-Tests-Accuracy/PMDataTreeTest.class.st diff --git a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st index d0f5409bb..fa452a403 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st @@ -74,40 +74,6 @@ PMAccuracyTest >> testCalcErrorOfRealResult [ equals: Float infinity negated ] -{ #category : #tests } -PMAccuracyTest >> testDataTree [ - | s | - a run. - self assert: (a dataTree atPath: #('iterations')) equals: 1. - self - assert: (a dataTree atPath: #('names' 'data')) - equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff'). - self - assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) - equals: - (KeyedTree new - at: 'arguments' put: true; - at: 'data' put: #(#(1 1)); - at: 'error' put: #(300.0 300.0); - at: 'expected result' put: #(4 4); - at: 'result' put: #(1 1); - at: 'type' put: 'result'; - yourself). - self - assert: (a dataTree atPath: #('names' 'Aaa' 'data')) - equals: #(#(1 2) #(3 2.8888)). - self - assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) - equals: #(#(2) #(3)). - s := a dataTree atPath: #('names' 'Ccc' #(3)). - self assert: s keys size equals: 5. - s := a dataTree atPath: #('names' 'Fff' 'error'). - self - assert: (s copyFrom: 1 to: 4) - equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). - self assert: (s at: 5) isNaN -] - { #category : #tests } PMAccuracyTest >> testDecimalPlaces [ self assert: a class decimalPlaces equals: 3. diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st new file mode 100644 index 000000000..2d8dd01f7 --- /dev/null +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -0,0 +1,70 @@ +" +Class Name: PMDataTreeTest + +Responsibility: exercising the PMAccuracyTestExample's +dataTree message + +Collaborators: PMAccuracyTestExample +" +Class { + #name : #PMDataTreeTest, + #superclass : #TestCase, + #instVars : [ + 'dp', + 'a' + ], + #category : #'Math-Tests-Accuracy' +} + +{ #category : #initialization } +PMDataTreeTest >> initialize [ + super initialize. + dp := PMAccuracyTestExample decimalPlaces +] + +{ #category : #running } +PMDataTreeTest >> setUp [ + super setUp. + a := PMAccuracyTestExample new. + PMAccuracyTestExample decimalPlaces: 3. +] + +{ #category : #running } +PMDataTreeTest >> tearDown [ + super tearDown. + PMAccuracyTestExample decimalPlaces: dp. +] + +{ #category : #tests } +PMDataTreeTest >> testDataTree [ + | s | + a run. + self assert: (a dataTree atPath: #('iterations')) equals: 1. + self + assert: (a dataTree atPath: #('names' 'data')) + equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff'). + self + assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) + equals: + (KeyedTree new + at: 'arguments' put: true; + at: 'data' put: #(#(1 1)); + at: 'error' put: #(300.0 300.0); + at: 'expected result' put: #(4 4); + at: 'result' put: #(1 1); + at: 'type' put: 'result'; + yourself). + self + assert: (a dataTree atPath: #('names' 'Aaa' 'data')) + equals: #(#(1 2) #(3 2.8888)). + self + assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) + equals: #(#(2) #(3)). + s := a dataTree atPath: #('names' 'Ccc' #(3)). + self assert: s keys size equals: 5. + s := a dataTree atPath: #('names' 'Fff' 'error'). + self + assert: (s copyFrom: 1 to: 4) + equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). + self assert: (s at: 5) isNaN +] From 2f4a6092a5c6caefcfd06cfaee3a67280f99c04c Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 12:02:58 +0000 Subject: [PATCH 02/13] [issue-154] Moved some test code to an intention-revealing test method & identified a possible smell. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 2d8dd01f7..210263ba3 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -39,7 +39,6 @@ PMDataTreeTest >> tearDown [ PMDataTreeTest >> testDataTree [ | s | a run. - self assert: (a dataTree atPath: #('iterations')) equals: 1. self assert: (a dataTree atPath: #('names' 'data')) equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff'). @@ -68,3 +67,10 @@ PMDataTreeTest >> testDataTree [ equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). self assert: (s at: 5) isNaN ] + +{ #category : #tests } +PMDataTreeTest >> testThatRunIncrementsTheNumberOfIterations [ + "SMELL - we're really testing run, it seems." + a run. + self assert: (a dataTree atPath: #('iterations')) equals: 1. +] From 4faff3dc2c2d1d30db4b666391c6f9ca73478ead Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 22:27:19 +0000 Subject: [PATCH 03/13] [issue-154] Moved a block of code to its own intention-revealing test method. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 210263ba3..d67005077 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -39,9 +39,6 @@ PMDataTreeTest >> tearDown [ PMDataTreeTest >> testDataTree [ | s | a run. - self - assert: (a dataTree atPath: #('names' 'data')) - equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff'). self assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) equals: @@ -74,3 +71,11 @@ PMDataTreeTest >> testThatRunIncrementsTheNumberOfIterations [ a run. self assert: (a dataTree atPath: #('iterations')) equals: 1. ] + +{ #category : #tests } +PMDataTreeTest >> testThatTheNamesAreInitialisationKeys [ + a run. + self + assert: (a dataTree atPath: #('names' 'data')) + equals: #('Aaa' 'Bbb' 'Ccc' 'Ddd' 'Eee' 'Fff') +] From a0e214c229d0f728e15a0b5942eb732de1959944 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 22:31:34 +0000 Subject: [PATCH 04/13] [issue-154] Moved some test code to its own intention-revealing method. --- .../PMDataTreeTest.class.st | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index d67005077..93f00978d 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -39,17 +39,6 @@ PMDataTreeTest >> tearDown [ PMDataTreeTest >> testDataTree [ | s | a run. - self - assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) - equals: - (KeyedTree new - at: 'arguments' put: true; - at: 'data' put: #(#(1 1)); - at: 'error' put: #(300.0 300.0); - at: 'expected result' put: #(4 4); - at: 'result' put: #(1 1); - at: 'type' put: 'result'; - yourself). self assert: (a dataTree atPath: #('names' 'Aaa' 'data')) equals: #(#(1 2) #(3 2.8888)). @@ -65,6 +54,22 @@ PMDataTreeTest >> testDataTree [ self assert: (s at: 5) isNaN ] +{ #category : #tests } +PMDataTreeTest >> testThatKeyedTreeContainsArgsDataErrorResultsAndType [ + a run. + self + assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) + equals: + (KeyedTree new + at: 'arguments' put: true; + at: 'data' put: #(#(1 1)); + at: 'error' put: #(300.0 300.0); + at: 'expected result' put: #(4 4); + at: 'result' put: #(1 1); + at: 'type' put: 'result'; + yourself) +] + { #category : #tests } PMDataTreeTest >> testThatRunIncrementsTheNumberOfIterations [ "SMELL - we're really testing run, it seems." From b9d25e73dc87c008e03353b41569e9f3e5ca8a17 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 22:35:36 +0000 Subject: [PATCH 05/13] [issue-154] Added a smell comment to help the next developer. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 93f00978d..f2b21e273 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -56,6 +56,10 @@ PMDataTreeTest >> testDataTree [ { #category : #tests } PMDataTreeTest >> testThatKeyedTreeContainsArgsDataErrorResultsAndType [ + "SMELL - it's not easy to determine the true purpose of the + test and, perhaps with the exception of the 'expected result', + how input leads to the output. + " a run. self assert: (a dataTree atPath: #('names' 'Aaa' #(1 2) #(4 4))) From 3d6b2de7cb4086ed25c4fd6e61ac5a4c555d5316 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 22:37:18 +0000 Subject: [PATCH 06/13] [issue-154] Added more smells to the smell comment. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index f2b21e273..1444f548a 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -58,7 +58,8 @@ PMDataTreeTest >> testDataTree [ PMDataTreeTest >> testThatKeyedTreeContainsArgsDataErrorResultsAndType [ "SMELL - it's not easy to determine the true purpose of the test and, perhaps with the exception of the 'expected result', - how input leads to the output. + how input leads to the output. The test also contains many + 'magic' numbers. " a run. self From 4b7b5e2f43b7866d72b89f329f577bd031237140 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 22:43:14 +0000 Subject: [PATCH 07/13] [issue-154] Moved the test code to an intention-revealing test method, extracted the expected result to a role-revealing local variable. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 1444f548a..fe5de73e6 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -39,9 +39,6 @@ PMDataTreeTest >> tearDown [ PMDataTreeTest >> testDataTree [ | s | a run. - self - assert: (a dataTree atPath: #('names' 'Aaa' 'data')) - equals: #(#(1 2) #(3 2.8888)). self assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) equals: #(#(2) #(3)). @@ -54,6 +51,17 @@ PMDataTreeTest >> testDataTree [ self assert: (s at: 5) isNaN ] +{ #category : #tests } +PMDataTreeTest >> testThatDataForAaaIsTheCorrespondingParameter [ + | parameterForAaa | + a run. + + parameterForAaa := #(#(1 2) #(3 2.8888)). + self + assert: (a dataTree atPath: #('names' 'Aaa' 'data')) + equals: parameterForAaa. +] + { #category : #tests } PMDataTreeTest >> testThatKeyedTreeContainsArgsDataErrorResultsAndType [ "SMELL - it's not easy to determine the true purpose of the From 666afa0bb0f9846d665318e527a82751d5faca4a Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Fri, 27 Dec 2019 23:11:52 +0000 Subject: [PATCH 08/13] [issue-154] Extracted test code to its own intention-revealing test method, with a comment identifying a coincidence between expected outcome and a default I discovered in the initialize method. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index fe5de73e6..0c14e54b3 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -39,9 +39,6 @@ PMDataTreeTest >> tearDown [ PMDataTreeTest >> testDataTree [ | s | a run. - self - assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) - equals: #(#(2) #(3)). s := a dataTree atPath: #('names' 'Ccc' #(3)). self assert: s keys size equals: 5. s := a dataTree atPath: #('names' 'Fff' 'error'). @@ -90,6 +87,20 @@ PMDataTreeTest >> testThatRunIncrementsTheNumberOfIterations [ self assert: (a dataTree atPath: #('iterations')) equals: 1. ] +{ #category : #tests } +PMDataTreeTest >> testThatTheDataForBbbIsTheDefaultResult [ + "SMELL - magic number. This may be coincidental, but the + expected result in this test is that set in + PMAccuracyTestExample's initialize method. + " + | defaultResultAtInitialisation | + a run. + defaultResultAtInitialisation := #(#(2) #(3)). + self + assert: (a dataTree atPath: #('names' 'Bbb' #(3) 'data')) + equals: defaultResultAtInitialisation +] + { #category : #tests } PMDataTreeTest >> testThatTheNamesAreInitialisationKeys [ a run. From 23ab70b4640d8e75fd7bd478923a3decdf43d969 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sat, 28 Dec 2019 14:00:51 +0000 Subject: [PATCH 09/13] [issue-154] Added calls to the super class methods as required. --- src/Math-Tests-Accuracy/PMAccuracyTest.class.st | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st index fa452a403..929834561 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st @@ -19,15 +19,16 @@ PMAccuracyTest >> initialize [ ] { #category : #running } -PMAccuracyTest >> setUp [ +PMAccuracyTest >> setUp [ + super setUp. a := PMAccuracyTestExample new. - PMAccuracyTestExample decimalPlaces: 3. + PMAccuracyTestExample decimalPlaces: 3 ] { #category : #running } -PMAccuracyTest >> tearDown [ +PMAccuracyTest >> tearDown [ PMAccuracyTestExample decimalPlaces: dp. - + super tearDown. ] { #category : #tests } From 767ec745da54e121690672434cbe690c5f637c73 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sat, 28 Dec 2019 14:01:42 +0000 Subject: [PATCH 10/13] [issue-154] Put the call to the super class method in the right place. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 0c14e54b3..26400526e 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -31,8 +31,8 @@ PMDataTreeTest >> setUp [ { #category : #running } PMDataTreeTest >> tearDown [ - super tearDown. PMAccuracyTestExample decimalPlaces: dp. + super tearDown. ] { #category : #tests } From 51d5e6c540d4cf61a18117dfa8913e5a99200c68 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sat, 28 Dec 2019 22:11:17 +0000 Subject: [PATCH 11/13] [issue-154] Improved the name of the local variable. We still don't know the role it plays in the test yet so gave it a structural name. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index 26400526e..bd1243970 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -37,15 +37,15 @@ PMDataTreeTest >> tearDown [ { #category : #tests } PMDataTreeTest >> testDataTree [ - | s | + | keyedTree | a run. - s := a dataTree atPath: #('names' 'Ccc' #(3)). - self assert: s keys size equals: 5. - s := a dataTree atPath: #('names' 'Fff' 'error'). + keyedTree := a dataTree atPath: #('names' 'Ccc' #(3)). + self assert: keyedTree keys size equals: 5. + keyedTree := a dataTree atPath: #('names' 'Fff' 'error'). self - assert: (s copyFrom: 1 to: 4) + assert: (keyedTree copyFrom: 1 to: 4) equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). - self assert: (s at: 5) isNaN + self assert: (keyedTree at: 5) isNaN ] { #category : #tests } From 11b1b5383a2792396a88b71b1681cf93ceb8f76a Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sat, 28 Dec 2019 22:14:21 +0000 Subject: [PATCH 12/13] [issue-154] Improved the name of a local variable. --- src/Math-Tests-Accuracy/PMDataTreeTest.class.st | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index bd1243970..d8954631b 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -37,15 +37,16 @@ PMDataTreeTest >> tearDown [ { #category : #tests } PMDataTreeTest >> testDataTree [ - | keyedTree | + | keyedTree error | a run. keyedTree := a dataTree atPath: #('names' 'Ccc' #(3)). self assert: keyedTree keys size equals: 5. - keyedTree := a dataTree atPath: #('names' 'Fff' 'error'). + + error := a dataTree atPath: #('names' 'Fff' 'error'). self - assert: (keyedTree copyFrom: 1 to: 4) + assert: (error copyFrom: 1 to: 4) equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). - self assert: (keyedTree at: 5) isNaN + self assert: (error at: 5) isNaN. ] { #category : #tests } From a4b6eb597d0f1ab83c7bea3ef2bf8e06f52aed61 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sat, 28 Dec 2019 22:19:09 +0000 Subject: [PATCH 13/13] [issue-154] Moved the test code to its own better named test method. --- .../PMDataTreeTest.class.st | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st index d8954631b..4de3357a0 100644 --- a/src/Math-Tests-Accuracy/PMDataTreeTest.class.st +++ b/src/Math-Tests-Accuracy/PMDataTreeTest.class.st @@ -37,16 +37,10 @@ PMDataTreeTest >> tearDown [ { #category : #tests } PMDataTreeTest >> testDataTree [ - | keyedTree error | + | keyedTree | a run. keyedTree := a dataTree atPath: #('names' 'Ccc' #(3)). self assert: keyedTree keys size equals: 5. - - error := a dataTree atPath: #('names' 'Fff' 'error'). - self - assert: (error copyFrom: 1 to: 4) - equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). - self assert: (error at: 5) isNaN. ] { #category : #tests } @@ -102,6 +96,17 @@ PMDataTreeTest >> testThatTheDataForBbbIsTheDefaultResult [ equals: defaultResultAtInitialisation ] +{ #category : #tests } +PMDataTreeTest >> testThatTheErrorForFffIsCorrect [ + | error | + a run. + error := a dataTree atPath: #('names' 'Fff' 'error'). + self + assert: (error copyFrom: 1 to: 4) + equals: (Array with: 0 with: Float infinity with: -100.0 with: Float infinity negated). + self assert: (error at: 5) isNaN. +] + { #category : #tests } PMDataTreeTest >> testThatTheNamesAreInitialisationKeys [ a run.