Skip to content

Commit 2d48607

Browse files
Issue 154 Refactoring - Make The Test More Specific By Breaking It Up (#171)
* [issue-154] Extracted the actual object being asserted on to a better named local variable. * [issue-154] Broke the tests up so that they#re more specific. * [issue-154] Extracted the 'act' part to a role-revealing local variable. * [issue-154] Extracted a method where the key is passed in explicitly, thereby avoiding magic. * [issue-154] Improved the name of the variable.
1 parent e044905 commit 2d48607

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/Math-Tests-Accuracy/PMAccuracyTest.class.st

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@ PMAccuracyTest >> testDecimalPlaces [
8383
]
8484

8585
{ #category : #tests }
86-
PMAccuracyTest >> testExtractFromResultsWhichOnlyOne [
87-
self
88-
assert: (a extractFromResults: #('bla' 'blah') which: 2 onlyOne: false)
89-
equals: 'blah'.
90-
self assert: a testGetterAaa second equals: #(true).
91-
self
92-
assert: (a extractFromResults: #('bla' 'blah') which: 1 onlyOne: true)
93-
equals: #('bla' 'blah').
94-
self assert: a testGetterAaa second equals: #(#(false) #(true))
86+
PMAccuracyTest >> testExtractFromResultsReturnsAllElementsWhenOnlyOneIsTrue [
87+
| argument results |
88+
results := a
89+
extractFromResults: #('bla' 'blah')
90+
which: 1
91+
onlyOne: true.
92+
93+
self assert: results equals: #('bla' 'blah').
94+
argument := a testGetterAaa second.
95+
self assert: argument equals: #(#(false) #(true))
96+
]
97+
98+
{ #category : #tests }
99+
PMAccuracyTest >> testExtractFromResultsReturnsTheCorrectIndexedElementWhenOnlyOneIsFalse [
100+
| argument results |
101+
results := a
102+
extractFromResults: #('bla' 'blah')
103+
which: 2
104+
onlyOne: false.
105+
106+
self assert: results equals: 'blah'.
107+
argument := a testGetterAaa second.
108+
self assert: argument equals: #(true)
95109
]
96110

97111
{ #category : #tests }

src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ Class {
1313
#category : #'Math-Tests-Accuracy'
1414
}
1515

16+
{ #category : #private }
17+
PMAccuracyTestExample >> argumentWith: key [
18+
| theArgument |
19+
theArgument := self argumentAt: key.
20+
numberOfResults ifNotNil: [ :rn | theArgument := theArgument at: rn ].
21+
^ theArgument
22+
]
23+
1624
{ #category : #tests }
1725
PMAccuracyTestExample >> checkAaa [
1826
self argument first
@@ -146,7 +154,7 @@ PMAccuracyTestExample >> tearDown [
146154
PMAccuracyTestExample >> testGetterAaa [
147155
^Array
148156
with: self parameter
149-
with: self argument
157+
with: (self argumentWith: 'Aaa')
150158
with: (self resultsAt: 'Aaa')
151159
with: (self numberOfDifferentParametersAt: 'Aaa')
152160
with: (self numberOfDifferentResultsAt: 'Aaa')
@@ -156,7 +164,7 @@ PMAccuracyTestExample >> testGetterAaa [
156164
PMAccuracyTestExample >> testGetterBbb [
157165
^Array
158166
with: self parameter
159-
with: self argument
167+
with: (self argumentWith: 'Bbb')
160168
with: (self resultsAt: 'Bbb')
161169
with: (self numberOfDifferentParametersAt: 'Bbb')
162170
with: (self numberOfDifferentResultsAt: 'Bbb')

0 commit comments

Comments
 (0)