-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and tests for other utilities #73
Changes from 12 commits
d80dfc6
3a049c7
940ad87
d969f87
d125262
99987bb
46435bb
00242f6
872345c
33959dd
71b3fad
c47c6b0
bbbec1b
150ef0a
5b1bf7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Class { | ||
#name : 'MTAuxiliarClassForMutantOperatorAnalysis', | ||
#superclass : 'Object', | ||
#category : 'MuTalk-Utilities-Tests', | ||
#package : 'MuTalk-Utilities-Tests' | ||
} | ||
|
||
{ #category : 'auxiliar' } | ||
MTAuxiliarClassForMutantOperatorAnalysis >> methodA [ | ||
|
||
| result | | ||
result := 1 + 1. | ||
^ result | ||
] | ||
|
||
{ #category : 'auxiliar' } | ||
MTAuxiliarClassForMutantOperatorAnalysis >> methodB [ | ||
|
||
false ifFalse: [ ^ 1 ] | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Class { | ||
#name : 'MTMutantOperatorAnalysisTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'operatorAnalysis' | ||
], | ||
#category : 'MuTalk-Utilities-Tests', | ||
#package : 'MuTalk-Utilities-Tests' | ||
} | ||
|
||
{ #category : 'running' } | ||
MTMutantOperatorAnalysisTest >> setUp [ | ||
|
||
super setUp. | ||
|
||
operatorAnalysis := MTMutantOperatorAnalysis forClasses: | ||
{ MTAuxiliarClassForMutantOperatorAnalysis } | ||
] | ||
|
||
{ #category : 'tests' } | ||
MTMutantOperatorAnalysisTest >> testGetAllOperators [ | ||
|
||
| actual expected | | ||
actual := (operatorAnalysis operatorsProducingOverXMutants: 0) keys | ||
asSet. | ||
expected := (MTMutantOperator contentsAll collect: #species) asSet. | ||
|
||
self assert: actual equals: expected | ||
] | ||
|
||
{ #category : 'tests' } | ||
MTMutantOperatorAnalysisTest >> testOperatorsProducingOver [ | ||
|
||
| actual expected | | ||
actual := (operatorAnalysis operatorsProducingOverXMutants: 3) keys | ||
asSet. | ||
expected := Set | ||
with: MTLiteralIntegersIncreaseOperator | ||
with: MTLiteralIntegersToZeroOperator | ||
with: MTLiteralIntegersDecreaseOperator. | ||
|
||
self assert: actual equals: expected | ||
] | ||
|
||
{ #category : 'tests' } | ||
MTMutantOperatorAnalysisTest >> testOperatorsProducingUnder [ | ||
|
||
| actual expected | | ||
actual := (operatorAnalysis operatorsProducingUnderXMutants: 2) keys | ||
asSet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it's the same but the other way around.
|
||
expected := (MTMutantOperator contentsAll collect: #species) asSet | ||
reject: [ :operator | | ||
{ | ||
MTLiteralIntegersIncreaseOperator. | ||
MTLiteralIntegersToZeroOperator. | ||
MTLiteralIntegersDecreaseOperator } includes: operator ]. | ||
|
||
self assert: actual equals: expected | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Class { | ||
#name : 'MTNonMutatedMethodsAnalysisTest', | ||
#superclass : 'TestCase', | ||
#category : 'MuTalk-Utilities-Tests', | ||
#package : 'MuTalk-Utilities-Tests' | ||
} | ||
|
||
{ #category : 'tests' } | ||
MTNonMutatedMethodsAnalysisTest >> testNonMutatedMethods [ | ||
|
||
| results | | ||
results := (MTNonMutatedMethodsAnalysis forClasses: { | ||
MTAuxiliarClassForMatrix. | ||
MTAuxiliarClassForMatrixTest }) | ||
findMethodsWithoutMutation asSet. | ||
|
||
self | ||
assert: results | ||
equals: MTAuxiliarClassForMatrixTest methods asSet | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,40 +13,46 @@ Class { | |
} | ||
|
||
{ #category : 'instance creation' } | ||
MTMatrix class >> forAClass: aClass [ | ||
MTMatrix class >> forClasses: aCollectionOfClasses [ | ||
|
||
^ self new | ||
classesToMutate: (Set with: aClass); | ||
testClasses: (Set with: | ||
(aClass name , 'Test' asClassInEnvironment: | ||
self class environment)) | ||
^ self | ||
forClasses: aCollectionOfClasses | ||
andTests: (aCollectionOfClasses collect: [ :class | | ||
class name , 'Test' asClassInEnvironment: | ||
self class environment ]) | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
MTMatrix class >> forAPackage: aPackage [ | ||
MTMatrix class >> forClasses: aCollectionOfClasses andTests: aCollectionOfTests [ | ||
|
||
^ self new | ||
classesToMutate: aPackage asPackage definedClasses; | ||
testClasses: | ||
((aPackage , '-Tests') asPackage definedClasses select: | ||
#isTestCase) | ||
classesToMutate: aCollectionOfClasses; | ||
testClasses: aCollectionOfTests | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
MTMatrix class >> forAPackage: aPackage andTestPackage: aTestPackage [ | ||
MTMatrix class >> forPackages: aCollectionOfPackages [ | ||
|
||
^ self new | ||
classesToMutate: aPackage asPackage definedClasses; | ||
testClasses: | ||
(aTestPackage asPackage definedClasses select: #isTestCase) | ||
^ self | ||
forPackages: aCollectionOfPackages | ||
andTestPackages: | ||
(aCollectionOfPackages collect: [ :package | package , '-Tests' ]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this. This forces a convention!!! |
||
] | ||
|
||
{ #category : 'instance creation' } | ||
MTMatrix class >> forClasses: aCollectionOfClasses andTests: aCollectionOfTests [ | ||
MTMatrix class >> forPackages: aCollectionOfPackages andTestPackages: aCollectionOfTestPackages [ | ||
|
||
^ self new | ||
classesToMutate: aCollectionOfClasses; | ||
testClasses: aCollectionOfTests | ||
classesToMutate: (aCollectionOfPackages | ||
inject: OrderedCollection new | ||
into: [ :coll :package | | ||
coll addAll: package asPackage definedClasses. | ||
coll ]); | ||
testClasses: (aCollectionOfTestPackages | ||
inject: OrderedCollection new | ||
into: [ :testColl :testPackage | | ||
testColl addAll: | ||
(testPackage asPackage definedClasses select: #isTestCase) ]) | ||
] | ||
|
||
{ #category : 'adding' } | ||
|
@@ -102,6 +108,12 @@ MTMatrix >> build [ | |
(self failuresFor: mut) includes: test ]) ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> classesToMutate [ | ||
|
||
^ classesToMutate | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> classesToMutate: aClass [ | ||
|
||
|
@@ -194,6 +206,12 @@ MTMatrix >> mutantOperation: aSymbol with: mutant1 and: mutant2 [ | |
^ self mutant1: mutant1 includesMutant2: mutant2 ] | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> mutations [ | ||
|
||
^ mutations | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> mutations: anObject [ | ||
|
||
|
@@ -212,6 +230,18 @@ MTMatrix >> runAnalysis [ | |
mutations := analysis mutations | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> testCases [ | ||
|
||
^ testCases | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> testClasses [ | ||
|
||
^ testClasses | ||
] | ||
|
||
{ #category : 'accessing' } | ||
MTMatrix >> testClasses: aTestClass [ | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Class { | ||
#name : 'MTMutantOperatorAnalysis', | ||
#superclass : 'Object', | ||
#superclass : 'MTUtilityAnalysis', | ||
#category : 'MuTalk-Utilities', | ||
#package : 'MuTalk-Utilities' | ||
} | ||
|
@@ -22,27 +22,19 @@ MTMutantOperatorAnalysis >> addAllAssociationsFrom: sourceDictionary to: destina | |
] | ||
|
||
{ #category : 'computing' } | ||
MTMutantOperatorAnalysis >> allOperatorsFor: aCollectionOfPackages [ | ||
MTMutantOperatorAnalysis >> allOperators [ | ||
|
||
| allOperatorsDictionary | | ||
allOperatorsDictionary := Dictionary new. | ||
| operatorsDictionary operatorsWithoutMutants | | ||
operatorsDictionary := self getMutantOperatorsDictionary. | ||
operatorsWithoutMutants := self findOperatorsWithoutMutantsFor: | ||
operatorsDictionary. | ||
|
||
aCollectionOfPackages do: [ :name | | ||
| operatorsDictionary operatorsWithoutMutants | | ||
operatorsDictionary := self getMutantOperatorsDictionaryFor: name. | ||
operatorsWithoutMutants := self findOperatorsWithoutMutantsFor: | ||
operatorsDictionary. | ||
operatorsDictionary := self | ||
addAllAssociationsFrom: | ||
operatorsWithoutMutants | ||
to: operatorsDictionary asDictionary. | ||
|
||
operatorsDictionary := self | ||
addAllAssociationsFrom: | ||
operatorsWithoutMutants | ||
to: operatorsDictionary asDictionary. | ||
|
||
self | ||
addAllAssociationsFrom: operatorsDictionary | ||
to: allOperatorsDictionary ]. | ||
|
||
^ allOperatorsDictionary | ||
^ operatorsDictionary | ||
] | ||
|
||
{ #category : 'computing' } | ||
|
@@ -54,18 +46,18 @@ MTMutantOperatorAnalysis >> findOperatorsWithoutMutantsFor: aDictionary [ | |
aDictionary keys includes: ope ]. | ||
|
||
^ Dictionary new | ||
addAll: (operatorsWithoutMutants collect: [ :each | each -> 0 ]) asDictionary; | ||
addAll: | ||
(operatorsWithoutMutants collect: [ :each | each -> 0 ]) | ||
asDictionary; | ||
yourself | ||
] | ||
|
||
{ #category : 'computing' } | ||
MTMutantOperatorAnalysis >> getMutantOperatorsDictionaryFor: aName [ | ||
|
||
| analysis dic classesToMutate | | ||
classesToMutate := aName asPackage definedClasses. | ||
MTMutantOperatorAnalysis >> getMutantOperatorsDictionary [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remember that in Pharo code we don't use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, I will change that. |
||
|
||
| analysis dic | | ||
analysis := MTAnalysis new | ||
classesToMutate: classesToMutate; | ||
classesToMutate: classes; | ||
testClasses: { }; | ||
operators: MTMutantOperator contentsAll. | ||
|
||
|
@@ -76,23 +68,19 @@ MTMutantOperatorAnalysis >> getMutantOperatorsDictionaryFor: aName [ | |
] | ||
|
||
{ #category : 'computing' } | ||
MTMutantOperatorAnalysis >> operatorsProducingOver: aNumber mutantsFor: aCollectionOfPackages [ | ||
MTMutantOperatorAnalysis >> operatorsProducingOverXMutants: aNumber [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this extra parameter all over the code is indeed an improvement :) |
||
|
||
^ self | ||
operatorsSelectedWith: [ :value | value >= aNumber ] | ||
for: aCollectionOfPackages | ||
^ self operatorsSelectedWith: [ :value | value >= aNumber ] | ||
] | ||
|
||
{ #category : 'computing' } | ||
MTMutantOperatorAnalysis >> operatorsProducingUnder: aNumber mutantsFor: aCollectionOfPackages [ | ||
MTMutantOperatorAnalysis >> operatorsProducingUnderXMutants: aNumber [ | ||
|
||
^ self | ||
operatorsSelectedWith: [ :value | value <= aNumber ] | ||
for: aCollectionOfPackages | ||
^ self operatorsSelectedWith: [ :value | value <= aNumber ] | ||
] | ||
|
||
{ #category : 'computing' } | ||
MTMutantOperatorAnalysis >> operatorsSelectedWith: aBlock for: aCollectionOfPackages [ | ||
MTMutantOperatorAnalysis >> operatorsSelectedWith: aBlock [ | ||
|
||
^ (self allOperatorsFor: aCollectionOfPackages) select: aBlock | ||
^ self allOperators select: aBlock | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name of this method is strange :)
operatorsProducingOverXMutants:
Does it mean they produce more than 0 mutants?
Alsy, why is it answering a dictionary? I see all your tests do
keys asSet
,keys asSet
,keys asSet
. This means that probably we want a method returning the set of keys directly and hide the fact that internally it's a dictionary right? :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually,
Over 0
means> 0
or>= 0
? Maybe a little rename could clarify "At least" vs "More than"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be useful to return a dictionary, to actually see how many mutants are produced by each operator.
But yes I think I could add a bit more methods, like the whole dictionary, the set of mutants producing at least a certain number of mutants, the 10 most producing operators, things like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there is already a method returning the whole dictionary, forgot about it ahah