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

Introducing random mutant-selection #31

Merged
merged 10 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/MuTalk-Model/FixedRandomMutantSelection.class.st
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
]
40 changes: 40 additions & 0 deletions src/MuTalk-Model/PercentRandomMutantSelection.class.st
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
]
128 changes: 128 additions & 0 deletions src/MuTalk-Model/RandomMutantSelection.class.st
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 src/MuTalk-Model/RandomOperatorMutantSelection.class.st
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
]
Loading