diff --git a/src/Math-Accuracy-Core/PMAccuracy.class.st b/src/Math-Accuracy-Core/PMAccuracy.class.st index 01ca179a0..1e74de0a5 100644 --- a/src/Math-Accuracy-Core/PMAccuracy.class.st +++ b/src/Math-Accuracy-Core/PMAccuracy.class.st @@ -209,14 +209,15 @@ PMAccuracy >> extremeCollection: acol max:aBoolean [ { #category : #private } PMAccuracy >> findKey [ - | s m | + | s selector matchingMessage | s := thisContext sender. - m := s sender method selector . - ^(names detect: [:n| m asString endsWith: n] ifNone: [nil]) - ifNil: [ m='initialize' - ifTrue: ['AllTheRest'] - ifFalse: [ m := s method selector asString. - self error: m,' called in wrong context'] ] + selector := s sender method selector. + selector = 'initialize' + ifTrue: [ ^ 'AllTheRest' ]. + matchingMessage := names + detect: [ :name | selector endsWith: name ] + ifNone: [ '' ]. + ^ matchingMessage ] { #category : #printing } @@ -252,31 +253,33 @@ PMAccuracy >> ifSeveralterations: aBlock [ ] { #category : #'initialize-release' } -PMAccuracy >> initNames [ - names := (self class allSelectorsBelow: Object) - select: [ :s | s beginsWith: #check ] - thenCollect: [ :s | s copyFrom: 6 to: s size ]. - names := names asArray sort +PMAccuracy >> initRest: aName [ + | initializationMessage | + initializationMessage := ('initialize' , aName) asSymbol. + (self respondsTo: initializationMessage) + ifFalse: [ ^ self ]. + self perform: initializationMessage ] { #category : #'initialize-release' } -PMAccuracy >> initRest: aName [ - | i | - i := ('initialize' , aName) asSymbol. - (self respondsTo: i) - ifTrue: [ self perform: i ] +PMAccuracy >> initSubclassSelectorNames [ + names := (self class allSelectorsBelow: Object) + select: [ :selectorName | selectorName beginsWith: #check ] + thenCollect: [ :selectorName | selectorName copyFrom: 6 to: selectorName size ]. + names := names asArray sort ] { #category : #'initialize-release' } PMAccuracy >> initialize [ - self initNames. parameters := Dictionary new. arguments := Dictionary new. results := Dictionary new. + self initSubclassSelectorNames. + names do: [ :name | self initRest: name ]. aStream := WriteStream with: ''. iterations := 1. - dataTree := KeyedTree new . - names do: [ :n | self initRest: n ] + dataTree := KeyedTree new. + ] { #category : #accessing } @@ -303,6 +306,11 @@ PMAccuracy >> numberOfDifferentResultsAt: aname [ ^ no first isCollection ifTrue: [ no size ] ifFalse: [ 1 ] ] +{ #category : #accessing } +PMAccuracy >> occurrencesOf: key In: aResults UpTo: anInteger [ + ^ (aResults copyFrom: 1 to: anInteger) occurrencesOf: key +] + { #category : #accessing } PMAccuracy >> parameter [ | r | @@ -394,15 +402,9 @@ PMAccuracy >> resultsKeyFor: aName AtPosition: anInteger [ key := aResults at: anInteger. key isArray ifFalse: [ ^ aResults ]. - repetitions := 0. - aResults - from: 1 - to: anInteger - 1 - do: [ :i | - i = key - ifTrue: [ repetitions := repetitions + 1 ] ]. + repetitions := self occurrencesOf: key In: aResults UpTo: anInteger - 1. result := (Array new: key size + repetitions) - replaceFrom: 1 + replaceFrom: 1 to: key size with: key startingAt: 1. diff --git a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st index d56b08d84..cb68ab31c 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTest.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTest.class.st @@ -38,11 +38,6 @@ PMAccuracyTest >> testArgumentAt [ self assert: (a argumentAt: 'Ccc') equals: #(#(1) #(1.1) #(0.9)) ] -{ #category : #tests } -PMAccuracyTest >> testArgumentError [ - self should: [ a testArgumentError ] raise: Error -] - { #category : #tests } PMAccuracyTest >> testAsArray [ self assert: (a asArray: 'bla') equals: #('bla'). @@ -271,11 +266,6 @@ PMAccuracyTest >> testParameterAt [ self assert: (a parameterAt: 'Fff') isNil ] -{ #category : #tests } -PMAccuracyTest >> testParameterError [ -self should: [a testParameterError ]raise: Error -] - { #category : #tests } PMAccuracyTest >> testPrintOn [ | s | @@ -300,11 +290,6 @@ PMAccuracyTest >> testReport [ self assert: (a report beginsWith: 'Report for: PMAccuracyTestExample') ] -{ #category : #tests } -PMAccuracyTest >> testResultError [ -self should: [a testResultError ]raise: Error -] - { #category : #tests } PMAccuracyTest >> testResultsKeyForAtPosition [ self assert: (a resultsKeyFor: 'Aaa' AtPosition: 2) equals: #(4 4). diff --git a/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st b/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st index f536164d0..70c90e4a5 100644 --- a/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st +++ b/src/Math-Tests-Accuracy/PMAccuracyTestExample.class.st @@ -110,11 +110,6 @@ PMAccuracyTestExample >> tearDown [ count :=count-(1/5). ] -{ #category : #private } -PMAccuracyTestExample >> testArgumentError [ -self argument: #(#(1) #(2)). -] - { #category : #private } PMAccuracyTestExample >> testGetterAaa [ ^{ self parameter .self argument.self resultsAt: 'Aaa'.self numberOfDifferentParametersAt: 'Aaa'.self numberOfDifferentResultsAt:'Aaa'} @@ -124,13 +119,3 @@ PMAccuracyTestExample >> testGetterAaa [ PMAccuracyTestExample >> testGetterBbb [ ^{ self parameter .self argument.self resultsAt: 'Bbb'.self numberOfDifferentParametersAt: 'Bbb'.self numberOfDifferentResultsAt:'Bbb'} ] - -{ #category : #private } -PMAccuracyTestExample >> testParameterError [ -self parameter: #(#(1) #(2)). -] - -{ #category : #private } -PMAccuracyTestExample >> testResultError [ -self result:#(1). -]