Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Durieux Pol committed Nov 21, 2023
1 parent a9d4a9e commit 18a123a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
24 changes: 19 additions & 5 deletions src/MuTalk-Model/RandomMutantSelection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ 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 [

Expand Down Expand Up @@ -91,7 +104,7 @@ RandomMutantSelection >> nullLogger [
{ #category : #generating }
RandomMutantSelection >> selectMutantsFrom: aCollection [

| size index newColl random |
| size newColl random |
size := aCollection size.
newColl := aCollection copyEmpty.
random := Random new.
Expand All @@ -100,10 +113,11 @@ RandomMutantSelection >> selectMutantsFrom: aCollection [
(self highLimitCondition: aCollection size) ifTrue: [ ^ aCollection ].

1 to: (self totalNumberOfMutants: aCollection size) do: [ :i |
index := random nextIntegerBetween: 1 and: size.
[ newColl includes: (aCollection at: index) ] whileTrue: [
index := random nextIntegerBetween: 1 and: size ].
newColl add: (aCollection at: index) ].
self
addMutantIn: newColl
from: aCollection
using: random
and: size ].
^ newColl
]

Expand Down
17 changes: 12 additions & 5 deletions src/MuTalk-Model/RandomOperatorMutantSelection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ RandomOperatorMutantSelection class >> percent: aPercentage [
(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 [

Expand Down Expand Up @@ -108,7 +114,7 @@ RandomOperatorMutantSelection >> randomMutantSelection: anObject [
{ #category : #generating }
RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [

| size index newColl random dict operators operator |
| size newColl random dict operators operator |
newColl := aCollection copyEmpty.
random := Random new.

Expand All @@ -128,10 +134,11 @@ RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [
(random nextIntegerBetween: 1 and: operators size) ].

size := (dict at: operator) size.
index := random nextIntegerBetween: 1 and: size.
[ newColl includes: ((dict at: operator) at: index) ] whileTrue: [
index := random nextIntegerBetween: 1 and: size ].
newColl add: ((dict at: operator) at: index) ].
self
addMutantIn: newColl
from: (dict at: operator)
using: random
and: size ].
^ newColl
]

Expand Down

0 comments on commit 18a123a

Please sign in to comment.