Skip to content
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

Merged
merged 15 commits into from
Feb 5, 2024
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 ]
]
2 changes: 1 addition & 1 deletion src/MuTalk-Utilities-Tests/MTMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Class {
MTMatrixTest >> setUp [

super setUp.
matrix := MTMatrix forAClass: MTAuxiliarClassForMatrix.
matrix := MTMatrix forClasses: { MTAuxiliarClassForMatrix }.
matrix build.
self setUpVariablesForTest
]
Expand Down
59 changes: 59 additions & 0 deletions src/MuTalk-Utilities-Tests/MTMutantOperatorAnalysisTest.class.st
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
Copy link
Contributor

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? :D

Copy link
Contributor

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"

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's the same but the other way around.

  • the keys asSet looks like the same smell (but duplicated code?)
  • under is < x or <= x ? :D

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
]
68 changes: 49 additions & 19 deletions src/MuTalk-Utilities/MTMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' ])
Copy link
Contributor

Choose a reason for hiding this comment

The 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' }
Expand Down Expand Up @@ -102,6 +108,12 @@ MTMatrix >> build [
(self failuresFor: mut) includes: test ]) ]
]

{ #category : 'accessing' }
MTMatrix >> classesToMutate [

^ classesToMutate
]

{ #category : 'accessing' }
MTMatrix >> classesToMutate: aClass [

Expand Down Expand Up @@ -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 [

Expand All @@ -212,6 +230,18 @@ MTMatrix >> runAnalysis [
mutations := analysis mutations
]

{ #category : 'accessing' }
MTMatrix >> testCases [

^ testCases
]

{ #category : 'accessing' }
MTMatrix >> testClasses [

^ testClasses
]

{ #category : 'accessing' }
MTMatrix >> testClasses: aTestClass [

Expand Down
43 changes: 0 additions & 43 deletions src/MuTalk-Utilities/MTMissingMutantOperatorAnalysis.class.st

This file was deleted.

58 changes: 23 additions & 35 deletions src/MuTalk-Utilities/MTMutantOperatorAnalysis.class.st
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'
}
Expand All @@ -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' }
Expand All @@ -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 [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember that in Pharo code we don't use the get/set prefixes in methods as a convention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Expand All @@ -76,23 +68,19 @@ MTMutantOperatorAnalysis >> getMutantOperatorsDictionaryFor: aName [
]

{ #category : 'computing' }
MTMutantOperatorAnalysis >> operatorsProducingOver: aNumber mutantsFor: aCollectionOfPackages [
MTMutantOperatorAnalysis >> operatorsProducingOverXMutants: aNumber [
Copy link
Contributor

Choose a reason for hiding this comment

The 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
]
Loading
Loading