-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from DurieuxPol/randomMutantSelection
Introducing random mutant-selection
- Loading branch information
Showing
8 changed files
with
638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Class { | ||
#name : #FixedRandomMutantSelection, | ||
#superclass : #RandomMutantSelection, | ||
#instVars : [ | ||
'numberOfMutants' | ||
], | ||
#category : #'MuTalk-Model-Mutations generation strategies' | ||
} | ||
|
||
{ #category : #accessing } | ||
FixedRandomMutantSelection >> highLimitCondition: aSize [ | ||
|
||
^ aSize <= self numberOfMutants | ||
] | ||
|
||
{ #category : #accessing } | ||
FixedRandomMutantSelection >> lowLimitCondition [ | ||
|
||
^ self numberOfMutants = 0 | ||
] | ||
|
||
{ #category : #accessing } | ||
FixedRandomMutantSelection >> numberOfMutants [ | ||
|
||
^ numberOfMutants | ||
] | ||
|
||
{ #category : #accessing } | ||
FixedRandomMutantSelection >> numberOfMutants: aNumber [ | ||
|
||
numberOfMutants := aNumber | ||
] | ||
|
||
{ #category : #accessing } | ||
FixedRandomMutantSelection >> totalNumberOfMutants: aSize [ | ||
|
||
^ self numberOfMutants | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Class { | ||
#name : #PercentRandomMutantSelection, | ||
#superclass : #RandomMutantSelection, | ||
#instVars : [ | ||
'percentageOfMutants' | ||
], | ||
#category : #'MuTalk-Model-Mutations generation strategies' | ||
} | ||
|
||
{ #category : #accessing } | ||
PercentRandomMutantSelection >> highLimitCondition: size [ | ||
|
||
^ percentageOfMutants = 100 | ||
] | ||
|
||
{ #category : #accessing } | ||
PercentRandomMutantSelection >> lowLimitCondition [ | ||
|
||
^ percentageOfMutants = 0 | ||
] | ||
|
||
{ #category : #accessing } | ||
PercentRandomMutantSelection >> percentageOfMutants [ | ||
|
||
^ percentageOfMutants | ||
] | ||
|
||
{ #category : #accessing } | ||
PercentRandomMutantSelection >> percentageOfMutants: aPercentage [ | ||
|
||
(aPercentage < 0 or: [ aPercentage > 100 ]) ifTrue: [ | ||
Error signal: 'Percantage should be between 0 and 100' ]. | ||
percentageOfMutants := aPercentage | ||
] | ||
|
||
{ #category : #accessing } | ||
PercentRandomMutantSelection >> totalNumberOfMutants: aSize [ | ||
|
||
^ percentageOfMutants * aSize / 100 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
Class { | ||
#name : #RandomMutantSelection, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'mutationsGenerationStrategy' | ||
], | ||
#category : #'MuTalk-Model-Mutations generation strategies' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
RandomMutantSelection class >> using: aMutationsGenerationStrategy [ | ||
|
||
^ self new mutationsGenerationStrategy: aMutationsGenerationStrategy | ||
] | ||
|
||
{ #category : #adding } | ||
RandomMutantSelection >> addMutantIn: newColl from: oldColl using: random and: aNumber [ | ||
|
||
| index | | ||
index := random nextIntegerBetween: 1 and: aNumber. | ||
|
||
"If the selected mutant has already been added, another one is chosen" | ||
[ newColl includes: (oldColl at: index) ] whileTrue: [ | ||
index := random nextIntegerBetween: 1 and: aNumber ]. | ||
|
||
newColl add: (oldColl at: index) | ||
] | ||
|
||
{ #category : #'accessing-defaults' } | ||
RandomMutantSelection >> defaultMutationGenerationStrategy [ | ||
|
||
^ AllMutationsGenerationStrategy new | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomMutantSelection >> highLimitCondition: aSize [ | ||
|
||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : #initialization } | ||
RandomMutantSelection >> initialize [ | ||
|
||
super initialize. | ||
mutationsGenerationStrategy := self defaultMutationGenerationStrategy | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomMutantSelection >> lowLimitCondition [ | ||
|
||
^ self subclassResponsibility | ||
] | ||
|
||
{ #category : #generating } | ||
RandomMutantSelection >> methodsToMutateFrom: aMutationTestingAnalysis [ | ||
|
||
^ mutationsGenerationStrategy methodsToMutateFrom: aMutationTestingAnalysis | ||
] | ||
|
||
{ #category : #generating } | ||
RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis [ | ||
|
||
^ self | ||
mutationsFor: aMutationTestingAnalysis | ||
loggingIn: self nullLogger | ||
] | ||
|
||
{ #category : #generating } | ||
RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ | ||
|
||
| mutations | | ||
mutations := mutationsGenerationStrategy mutationsFor: | ||
aMutationTestingAnalysis loggingIn: aLogger. | ||
^ self selectMutantsFrom: mutations | ||
] | ||
|
||
{ #category : #generating } | ||
RandomMutantSelection >> mutationsFor: aMethod usingAll: aCollectionOfMutantOperators logginIn: aLogger [ | ||
|
||
^ mutationsGenerationStrategy | ||
mutationsFor: aMethod | ||
usingAll: aCollectionOfMutantOperators | ||
logginIn: aLogger | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomMutantSelection >> mutationsGenerationStrategy [ | ||
|
||
^ mutationsGenerationStrategy | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomMutantSelection >> mutationsGenerationStrategy: aMutationsGenerationStrategy [ | ||
|
||
mutationsGenerationStrategy := aMutationsGenerationStrategy | ||
] | ||
|
||
{ #category : #logging } | ||
RandomMutantSelection >> nullLogger [ | ||
|
||
^ mutationsGenerationStrategy nullLogger | ||
] | ||
|
||
{ #category : #generating } | ||
RandomMutantSelection >> selectMutantsFrom: aCollection [ | ||
|
||
| size newColl random | | ||
size := aCollection size. | ||
newColl := aCollection copyEmpty. | ||
random := Random new. | ||
|
||
self lowLimitCondition ifTrue: [ ^ newColl ]. | ||
(self highLimitCondition: aCollection size) ifTrue: [ ^ aCollection ]. | ||
|
||
1 to: (self totalNumberOfMutants: aCollection size) do: [ :i | | ||
self | ||
addMutantIn: newColl | ||
from: aCollection | ||
using: random | ||
and: size ]. | ||
^ newColl | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomMutantSelection >> totalNumberOfMutants: aSize [ | ||
|
||
^ self subclassResponsibility | ||
] |
149 changes: 149 additions & 0 deletions
149
src/MuTalk-Model/RandomOperatorMutantSelection.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
Class { | ||
#name : #RandomOperatorMutantSelection, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'randomMutantSelection' | ||
], | ||
#category : #'MuTalk-Model-Mutations generation strategies' | ||
} | ||
|
||
{ #category : #intialization } | ||
RandomOperatorMutantSelection class >> fixed: aNumber [ | ||
|
||
^ self new randomMutantSelection: | ||
(FixedRandomMutantSelection new numberOfMutants: aNumber) | ||
] | ||
|
||
{ #category : #intialization } | ||
RandomOperatorMutantSelection class >> percent: aPercentage [ | ||
|
||
^ self new randomMutantSelection: | ||
(PercentRandomMutantSelection new percentageOfMutants: aPercentage) | ||
] | ||
|
||
{ #category : #adding } | ||
RandomOperatorMutantSelection >> addMutantIn: newColl from: oldColl using: random and: aNumber [ | ||
|
||
randomMutantSelection addMutantIn: newColl from: oldColl using: random and: aNumber | ||
] | ||
|
||
{ #category : #'accessing-defaults' } | ||
RandomOperatorMutantSelection >> defaultMutationGenerationStrategy [ | ||
|
||
^ randomMutantSelection defaultMutationGenerationStrategy | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> highLimitCondition: aSize [ | ||
|
||
^ randomMutantSelection highLimitCondition: aSize | ||
] | ||
|
||
{ #category : #initialization } | ||
RandomOperatorMutantSelection >> initialize [ | ||
|
||
randomMutantSelection initialize | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> lowLimitCondition [ | ||
|
||
^ randomMutantSelection lowLimitCondition | ||
] | ||
|
||
{ #category : #generating } | ||
RandomOperatorMutantSelection >> methodsToMutateFrom: aMutationTestingAnalysis [ | ||
|
||
^ randomMutantSelection methodsToMutateFrom: aMutationTestingAnalysis | ||
] | ||
|
||
{ #category : #generating } | ||
RandomOperatorMutantSelection >> mutationsFor: aMutationTestingAnalysis [ | ||
|
||
^ randomMutantSelection mutationsFor: aMutationTestingAnalysis | ||
] | ||
|
||
{ #category : #generating } | ||
RandomOperatorMutantSelection >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ | ||
|
||
^ randomMutantSelection | ||
mutationsFor: aMutationTestingAnalysis | ||
loggingIn: aLogger | ||
] | ||
|
||
{ #category : #generating } | ||
RandomOperatorMutantSelection >> mutationsFor: aMethod usingAll: aCollectionOfMutantOperators logginIn: aLogger [ | ||
|
||
^ randomMutantSelection | ||
mutationsFor: aMethod | ||
usingAll: aCollectionOfMutantOperators | ||
logginIn: aLogger | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> mutationsGenerationStrategy [ | ||
|
||
^ randomMutantSelection mutationGenerationStrategy | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> mutationsGenerationStrategy: aMutationsGenerationStrategy [ | ||
|
||
^ randomMutantSelection mutationsGenerationStrategy: | ||
aMutationsGenerationStrategy | ||
] | ||
|
||
{ #category : #logging } | ||
RandomOperatorMutantSelection >> nullLogger [ | ||
|
||
^ randomMutantSelection nullLogger | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> randomMutantSelection [ | ||
|
||
^ randomMutantSelection | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> randomMutantSelection: anObject [ | ||
|
||
randomMutantSelection := anObject | ||
] | ||
|
||
{ #category : #generating } | ||
RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ | ||
|
||
| size newColl random dict operators operator | | ||
newColl := aCollection copyEmpty. | ||
random := Random new. | ||
|
||
self lowLimitCondition ifTrue: [ ^ newColl ]. | ||
(self highLimitCondition: aCollection size) ifTrue: [ ^ aCollection ]. | ||
|
||
dict := aCollection groupedBy: [ :e | e operator ]. | ||
operators := dict keys. | ||
1 to: (self totalNumberOfMutants: aCollection size) do: [ :i | | ||
operator := operators at: | ||
(random nextIntegerBetween: 1 and: operators size). | ||
|
||
"if all the mutants generated with a given operator have already been selected, another operator is chosen" | ||
[ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ] | ||
whileTrue: [ | ||
operator := operators at: | ||
(random nextIntegerBetween: 1 and: operators size) ]. | ||
|
||
size := (dict at: operator) size. | ||
self | ||
addMutantIn: newColl | ||
from: (dict at: operator) | ||
using: random | ||
and: size ]. | ||
^ newColl | ||
] | ||
|
||
{ #category : #accessing } | ||
RandomOperatorMutantSelection >> totalNumberOfMutants: aSize [ | ||
|
||
^ randomMutantSelection totalNumberOfMutants: aSize | ||
] |
Oops, something went wrong.