Skip to content

Commit

Permalink
[issue-154] Corrected the behaviour of findKey, making it more testab…
Browse files Browse the repository at this point in the history
…le in the subclass to mitigate risk.
  • Loading branch information
hemalvarambhia committed Sep 8, 2019
1 parent 644e8f9 commit e54af6f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Math-Tests-Accuracy/PMAccuracyFindKeyTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"
This test case exercises the findKey: message with some regression tests.
"
Class {
#name : #PMAccuracyFindKeyTest,
#superclass : #TestCase,
#category : #'Math-Tests-Accuracy'
}

{ #category : #tests }
PMAccuracyFindKeyTest >> testFindKeyReturnsAllTheRestStringWhenSelectorCorrespondsToNonExistentProperty [
| accuracy |
accuracy := PMAccuracyTestExample new.

self assert: (accuracy findKey: 'NonExistent') equals: 'AllTheRest'
]

{ #category : #tests }
PMAccuracyFindKeyTest >> testFindKeyReturnsAllTheRestStringWhenSelectorIsInitialize [
| accuracy selector |
accuracy := PMAccuracyTestExample new.
selector := 'initialize'.

self assert: (accuracy findKey: selector) equals: 'AllTheRest'
]

{ #category : #tests }
PMAccuracyFindKeyTest >> testFindKeyReturnsPropertyWhenSelectorIsSuffixOfInitializePropertyMessage [
| accuracy |
accuracy := PMAccuracyTestExample new.

self assert: (accuracy findKey: 'Aaa') equals: 'Aaa'
]
19 changes: 19 additions & 0 deletions src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ PMAccuracyTestExample >> count [
^ count
]

{ #category : #private }
PMAccuracyTestExample >> findKey [
| s selector |
s := thisContext sender.
selector := s sender method selector.
^ self findKey: selector
]

{ #category : #private }
PMAccuracyTestExample >> findKey: selector [
| matchingMessage |
selector = 'initialize'
ifTrue: [ ^ 'AllTheRest' ].
matchingMessage := names
detect: [ :name | selector endsWith: name ]
ifNone: [ 'AllTheRest' ].
^ matchingMessage
]

{ #category : #'initialize-release' }
PMAccuracyTestExample >> initialize [
"this is always necessarily the first thing:"
Expand Down

0 comments on commit e54af6f

Please sign in to comment.