Skip to content

Commit

Permalink
refactor random mutant selection to only shuffle mutants & rename oth…
Browse files Browse the repository at this point in the history
…er mutant selection strategies to mutant generation strategies
  • Loading branch information
Durieux Pol committed Apr 5, 2024
1 parent daecc3e commit 3f5e340
Show file tree
Hide file tree
Showing 22 changed files with 255 additions and 264 deletions.
6 changes: 3 additions & 3 deletions src/MuTalk-CI/MTCI.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ MTCI >> mutateAll [
runMutalkTargets: targets
tests: tests
generationStrategy:
MTSelectingFromCoverageMutantSelectionStrategy new
MTSelectingFromCoverageMutantGenerationStrategy new
]

{ #category : 'as yet unclassified' }
Expand All @@ -162,7 +162,7 @@ MTCI >> mutateDiff [
self
runMutalkTargets: targets
tests: tests
generationStrategy: MTSelectingFromAlivesMutantSelectionStrategy new
generationStrategy: MTSelectingFromAlivesMutantGenerationStrategy new
]

{ #category : 'as yet unclassified' }
Expand Down Expand Up @@ -202,7 +202,7 @@ MTCI >> runMutalkTargets: targets tests: tests generationStrategy: generationStr
classesToMutate: targets;
testSelectionStrategy:
MTSelectingFromCoverageTestSelectionStrategy new;
mutantSelectionStrategy: generationStrategy.
mutantGenerationStrategy: generationStrategy.
analysis run.
coverageInfo := self prepareCoverageInfo: analysis.
self exportResultJson: analysis coverageInfo: coverageInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : 'MTSelectingFromAlivesMutantSelectionStrategy',
#superclass : 'MTMutantSelectionStrategy',
#name : 'MTSelectingFromAlivesMutantGenerationStrategy',
#superclass : 'MTMutantGenerationStrategy',
#instVars : [
'analysis'
],
Expand All @@ -9,13 +9,13 @@ Class {
}

{ #category : 'accessing' }
MTSelectingFromAlivesMutantSelectionStrategy >> analysis: anObject [
MTSelectingFromAlivesMutantGenerationStrategy >> analysis: anObject [

analysis := anObject
]

{ #category : 'generating' }
MTSelectingFromAlivesMutantSelectionStrategy >> methodsToMutateFrom: aMutationTestingAnalysis [
MTSelectingFromAlivesMutantGenerationStrategy >> methodsToMutateFrom: aMutationTestingAnalysis [

^ (analysis generalResult aliveMutants collect: [ :alive |
alive mutant originalMethod ]) asSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Class {
#name : 'MTAllMutantSelectionStrategy',
#superclass : 'MTMutantSelectionStrategy',
#category : 'MuTalk-Model-Mutant selection strategies',
#name : 'MTAllMutantGenerationStrategy',
#superclass : 'MTMutantGenerationStrategy',
#category : 'MuTalk-Model-Mutant generation strategies',
#package : 'MuTalk-Model',
#tag : 'Mutant selection strategies'
#tag : 'Mutant generation strategies'
}

{ #category : 'generating' }
MTAllMutantSelectionStrategy >> classesAndMetaclassesFrom: modelClasses [
MTAllMutantGenerationStrategy >> classesAndMetaclassesFrom: modelClasses [
^ modelClasses
inject: OrderedCollection new
into: [:classes :aClass |
Expand All @@ -17,7 +17,7 @@ MTAllMutantSelectionStrategy >> classesAndMetaclassesFrom: modelClasses [
]

{ #category : 'generating' }
MTAllMutantSelectionStrategy >> methodsToMutateFrom: aMutationTestingAnalysis [
MTAllMutantGenerationStrategy >> methodsToMutateFrom: aMutationTestingAnalysis [
^ (self classesAndMetaclassesFrom: aMutationTestingAnalysis modelClasses)
inject: OrderedCollection new
into: [:methods :aClass |
Expand Down
28 changes: 14 additions & 14 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Class {
'mutantResults',
'stopOnErrorOrFail',
'testSelectionStrategy',
'mutantSelectionStrategy',
'testFilter'
'testFilter',
'mutantGenerationStrategy'
],
#category : 'MuTalk-Model-Core',
#package : 'MuTalk-Model',
Expand Down Expand Up @@ -64,9 +64,9 @@ MTAnalysis >> defaultLogger [
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultMutantSelectionStrategy [
MTAnalysis >> defaultMutantGenerationStrategy [

^ MTAllMutantSelectionStrategy new
^ MTAllMutantGenerationStrategy new
]

{ #category : 'accessing - defaults' }
Expand Down Expand Up @@ -118,7 +118,7 @@ MTAnalysis >> generateMutations [

logger logStartMutationGeneration.
^ mutations ifNil: [
mutations := mutantSelectionStrategy
mutations := mutantGenerationStrategy
mutationsFor: self
loggingIn: logger.
logger logTotalNumberOfMutations: mutations.
Expand Down Expand Up @@ -160,7 +160,7 @@ MTAnalysis >> initialize [

super initialize.
operators := self defaultOperators.
mutantSelectionStrategy := self defaultMutantSelectionStrategy.
mutantGenerationStrategy := self defaultMutantGenerationStrategy.
testSelectionStrategy := self defaultTestSelectionStrategy.
mutantResults := OrderedCollection new.
elapsedTime := 0.
Expand Down Expand Up @@ -193,22 +193,22 @@ MTAnalysis >> modelClasses [
class includesBehavior: classToFilter ] ]
]

{ #category : 'results' }
MTAnalysis >> mutantResults [
{ #category : 'accessing' }
MTAnalysis >> mutantGenerationStrategy [

^ mutantResults
^ mutantGenerationStrategy
]

{ #category : 'accessing' }
MTAnalysis >> mutantSelectionStrategy [
MTAnalysis >> mutantGenerationStrategy: anObject [

^ mutantSelectionStrategy
mutantGenerationStrategy := anObject
]

{ #category : 'accessing' }
MTAnalysis >> mutantSelectionStrategy: anObject [
{ #category : 'results' }
MTAnalysis >> mutantResults [

mutantSelectionStrategy := anObject
^ mutantResults
]

{ #category : 'accessing' }
Expand Down
22 changes: 22 additions & 0 deletions src/MuTalk-Model/MTManualMutatedMethodGenerationStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class {
#name : 'MTManualMutatedMethodGenerationStrategy',
#superclass : 'MTMutantGenerationStrategy',
#instVars : [
'targetMethods'
],
#category : 'MuTalk-Model-Mutant generation strategies',
#package : 'MuTalk-Model',
#tag : 'Mutant generation strategies'
}

{ #category : 'generating' }
MTManualMutatedMethodGenerationStrategy >> methodsToMutateFrom: aMutationTestingAnalysis [

^ targetMethods
]

{ #category : 'accessing' }
MTManualMutatedMethodGenerationStrategy >> targetMethods: anObject [

targetMethods := anObject
]
22 changes: 0 additions & 22 deletions src/MuTalk-Model/MTManualMutatedMethodSelectionStrategy.class.st

This file was deleted.

33 changes: 33 additions & 0 deletions src/MuTalk-Model/MTManualMutationGenerationStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"
This strategy uses a fixed list of mutations pre-computed by the user
"
Class {
#name : 'MTManualMutationGenerationStrategy',
#superclass : 'MTMutantGenerationStrategy',
#instVars : [
'mutations'
],
#category : 'MuTalk-Model-Mutant generation strategies',
#package : 'MuTalk-Model',
#tag : 'Mutant generation strategies'
}

{ #category : 'instance creation' }
MTManualMutationGenerationStrategy class >> with: aCollection [

^ self new
mutations: aCollection;
yourself
]

{ #category : 'accessing' }
MTManualMutationGenerationStrategy >> mutations: anInfiniteReadStream [
mutations := anInfiniteReadStream
]

{ #category : 'generating' }
MTManualMutationGenerationStrategy >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [

"Do not compute a list of mutations, just use the explicit one"
^ mutations
]
33 changes: 0 additions & 33 deletions src/MuTalk-Model/MTManualMutationSelectionStrategy.class.st

This file was deleted.

120 changes: 120 additions & 0 deletions src/MuTalk-Model/MTMutantGenerationStrategy.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
Class {
#name : 'MTMutantGenerationStrategy',
#superclass : 'Object',
#instVars : [
'mutantSelectionStrategy'
],
#category : 'MuTalk-Model-Mutant generation strategies',
#package : 'MuTalk-Model',
#tag : 'Mutant generation strategies'
}

{ #category : 'instance creation' }
MTMutantGenerationStrategy class >> withRandomClassMutantSelection [

^ self new
mutantSelectionStrategy: MTRandomClassMutantSelectionStrategy new;
yourself
]

{ #category : 'instance creation' }
MTMutantGenerationStrategy class >> withRandomMethodMutantSelection [

^ self new
mutantSelectionStrategy: MTRandomMethodMutantSelectionStrategy new;
yourself
]

{ #category : 'instance creation' }
MTMutantGenerationStrategy class >> withRandomMutantSelection [

^ self new
mutantSelectionStrategy: MTRandomMutantSelectionStrategy new;
yourself
]

{ #category : 'instance creation' }
MTMutantGenerationStrategy class >> withRandomOperatorMutantSelection [

^ self new
mutantSelectionStrategy: MTRandomOperatorMutantSelectionStrategy new;
yourself
]

{ #category : 'accessing - defaults' }
MTMutantGenerationStrategy >> defaultMutantSelectionStrategy [

^ MTMutantSelectionStrategy new
]

{ #category : 'initialization' }
MTMutantGenerationStrategy >> initialize [

super initialize.
mutantSelectionStrategy := self defaultMutantSelectionStrategy
]

{ #category : 'generating' }
MTMutantGenerationStrategy >> methodsToMutateFrom:aMutationTestingAnalysis [
self subclassResponsibility.
]

{ #category : 'accessing' }
MTMutantGenerationStrategy >> mutantSelectionStrategy [

^ mutantSelectionStrategy
]

{ #category : 'accessing' }
MTMutantGenerationStrategy >> mutantSelectionStrategy: anObject [

mutantSelectionStrategy := anObject
]

{ #category : 'generating' }
MTMutantGenerationStrategy >> mutationsFor: aMutationTestingAnalysis [
^ self
mutationsFor: aMutationTestingAnalysis
loggingIn: self nullLogger
]

{ #category : 'generating' }
MTMutantGenerationStrategy >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [

| mutations |
mutations := OrderedCollection new.
(self methodsToMutateFrom: aMutationTestingAnalysis)
do: [ :aMethod |
mutations addAll: (self
mutationsFor: aMethod
usingAll: aMutationTestingAnalysis operators
logginIn: aLogger) ]
displayingProgress: 'Building Mutants'.
^ mutantSelectionStrategy shuffleMutants: mutations
]

{ #category : 'generating' }
MTMutantGenerationStrategy >> mutationsFor: aMethod usingAll: aCollectionOfMutantOperators logginIn: aLogger [

| parseTree |
parseTree := aMethod parseTree.
^ aCollectionOfMutantOperators
inject: OrderedCollection new
into: [ :mutations :anOperator |
aLogger logStartBuildingMutantionsFor: aMethod using: anOperator.
(aMethod ignoredMutationOperators includes: anOperator class)
ifFalse: [
| newMutations |
newMutations := anOperator
mutationsFor: aMethod
with: parseTree.
aLogger logNumberOfGeneratedMutations: newMutations size.
mutations addAll: newMutations ].
mutations ]
]

{ #category : 'logging' }
MTMutantGenerationStrategy >> nullLogger [

^ MTNullLogger new.
]
Loading

0 comments on commit 3f5e340

Please sign in to comment.