From 0abf119e32fc52694e397b04a408bd77858026be Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 13 Nov 2023 17:30:47 +0100 Subject: [PATCH 01/10] Added a random mutant-selection decorator, as well as two types of selection: selecting a fixed number of mutants, and selecting a percentage of all the mutants. All of this with some tests --- .../FixedRandomMutantsSelection.class.st | 37 ++++++++++ .../MutationTestingAnalysis.class.st | 4 +- .../PercentRandomMutantsSelection.class.st | 40 +++++++++++ .../RandomMutantsEvaluationStrategy.class.st | 68 +++++++++++++++++++ .../FixedRandomMutantsSelectionTest.class.st | 43 ++++++++++++ ...PercentRandomMutantsSelectionTest.class.st | 52 ++++++++++++++ ...ndomMutantsEvaluationStrategyTest.class.st | 13 ++++ 7 files changed, 255 insertions(+), 2 deletions(-) create mode 100644 src/MuTalk-Model/FixedRandomMutantsSelection.class.st create mode 100644 src/MuTalk-Model/PercentRandomMutantsSelection.class.st create mode 100644 src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st create mode 100644 src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st create mode 100644 src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st create mode 100644 src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st diff --git a/src/MuTalk-Model/FixedRandomMutantsSelection.class.st b/src/MuTalk-Model/FixedRandomMutantsSelection.class.st new file mode 100644 index 00000000..dfb89f82 --- /dev/null +++ b/src/MuTalk-Model/FixedRandomMutantsSelection.class.st @@ -0,0 +1,37 @@ +Class { + #name : #FixedRandomMutantsSelection, + #superclass : #RandomMutantsEvaluationStrategy, + #instVars : [ + 'numberOfMutants' + ], + #category : #'MuTalk-Model-Mutations generation strategies' +} + +{ #category : #accessing } +FixedRandomMutantsSelection >> numberOfMutants [ + + ^ numberOfMutants +] + +{ #category : #accessing } +FixedRandomMutantsSelection >> numberOfMutants: aNumber [ + + numberOfMutants := aNumber +] + +{ #category : #accessing } +FixedRandomMutantsSelection >> selectMutantsFrom: aCollection [ + + | size index newColl random | + size := aCollection size. + newColl := aCollection copyEmpty. + random := Random new. + + numberOfMutants = 0 ifTrue: [ ^ newColl ]. + aCollection size <= numberOfMutants ifTrue: [ ^ aCollection ]. + + 1 to: numberOfMutants do: [ :i | + index := random nextIntegerBetween: 1 and: size. + newColl add: (aCollection at: index) ]. + ^ newColl +] diff --git a/src/MuTalk-Model/MutationTestingAnalysis.class.st b/src/MuTalk-Model/MutationTestingAnalysis.class.st index 926f55ec..fd0b0aef 100644 --- a/src/MuTalk-Model/MutationTestingAnalysis.class.st +++ b/src/MuTalk-Model/MutationTestingAnalysis.class.st @@ -278,13 +278,13 @@ MutationTestingAnalysis >> mutations: anObject [ ] { #category : #accessing } -MutationTestingAnalysis >> mutationsGenerationStrategy [ +MutationTestingAnalysis >> mutationsEvaluationStrategy [ ^ mutationsGenerationStrategy ] { #category : #accessing } -MutationTestingAnalysis >> mutationsGenerationStrategy: anObject [ +MutationTestingAnalysis >> mutationsEvaluationStrategy: anObject [ mutationsGenerationStrategy := anObject ] diff --git a/src/MuTalk-Model/PercentRandomMutantsSelection.class.st b/src/MuTalk-Model/PercentRandomMutantsSelection.class.st new file mode 100644 index 00000000..acc03b37 --- /dev/null +++ b/src/MuTalk-Model/PercentRandomMutantsSelection.class.st @@ -0,0 +1,40 @@ +Class { + #name : #PercentRandomMutantsSelection, + #superclass : #RandomMutantsEvaluationStrategy, + #instVars : [ + 'percentageOfMutants' + ], + #category : #'MuTalk-Model-Mutations generation strategies' +} + +{ #category : #accessing } +PercentRandomMutantsSelection >> percentageOfMutants [ + + ^ percentageOfMutants +] + +{ #category : #accessing } +PercentRandomMutantsSelection >> percentageOfMutants: aPercentage [ + + (aPercentage < 0 or: [ aPercentage > 100 ]) ifTrue: [ + Error signal: 'Percantage should be between 0 and 100' ]. + percentageOfMutants := aPercentage +] + +{ #category : #accessing } +PercentRandomMutantsSelection >> selectMutantsFrom: aCollection [ + + | size index newColl random numberOfMutants | + size := aCollection size. + newColl := aCollection copyEmpty. + random := Random new. + numberOfMutants := size * percentageOfMutants / 100. + + percentageOfMutants = 0 ifTrue: [ ^ newColl ]. + percentageOfMutants = 100 ifTrue: [ ^ aCollection ]. + + 1 to: numberOfMutants do: [ :i | + index := random nextIntegerBetween: 1 and: size. + newColl add: (aCollection at: index) ]. + ^ newColl +] diff --git a/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st b/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st new file mode 100644 index 00000000..5d8678bc --- /dev/null +++ b/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st @@ -0,0 +1,68 @@ +Class { + #name : #RandomMutantsEvaluationStrategy, + #superclass : #Object, + #instVars : [ + 'mutationsEvaluationStrategy' + ], + #category : #'MuTalk-Model-Mutations generation strategies' +} + +{ #category : #'instance creation' } +RandomMutantsEvaluationStrategy class >> using: aMutationsGenerationStrategy [ + + ^ self new mutationsEvaluationStrategy: aMutationsGenerationStrategy +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> defaultMutationGenerationStrategy [ + + ^ AllMutationsGenerationStrategy new +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> initialize [ + + super initialize. + mutationsEvaluationStrategy := self defaultMutationGenerationStrategy +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> mutationsEvaluationStrategy [ + + ^ mutationsEvaluationStrategy +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> mutationsEvaluationStrategy: aMutationsEvaluationStrategy [ + + mutationsEvaluationStrategy := aMutationsEvaluationStrategy +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> mutationsFor: aMutationTestingAnalysis [ + + ^ self + mutationsFor: aMutationTestingAnalysis + loggingIn: self nullLogger +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ + + | mutations | + mutations := mutationsEvaluationStrategy mutationsFor: + aMutationTestingAnalysis loggingIn: aLogger. + ^ self selectMutantsFrom: mutations +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> nullLogger [ + + ^ mutationsEvaluationStrategy nullLogger +] + +{ #category : #accessing } +RandomMutantsEvaluationStrategy >> selectMutantsFrom: aCollection [ + + ^ self subclassResponsibility +] diff --git a/src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st b/src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st new file mode 100644 index 00000000..15585088 --- /dev/null +++ b/src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st @@ -0,0 +1,43 @@ +Class { + #name : #FixedRandomMutantsSelectionTest, + #superclass : #RandomMutantsEvaluationStrategyTest, + #category : #'MuTalk-Tests' +} + +{ #category : #tests } +FixedRandomMutantsSelectionTest >> testSelectMutantsFrom [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := FixedRandomMutantsSelection new numberOfMutants: 5. + self assert: (select selectMutantsFrom: coll) size equals: 5 +] + +{ #category : #tests } +FixedRandomMutantsSelectionTest >> testSelectMutantsFrom2 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := FixedRandomMutantsSelection new numberOfMutants: 0. + self + assert: (select selectMutantsFrom: coll) + equals: { } asOrderedCollection +] + +{ #category : #tests } +FixedRandomMutantsSelectionTest >> testSelectMutantsFrom3 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := FixedRandomMutantsSelection new numberOfMutants: 10. + self assert: (select selectMutantsFrom: coll) equals: coll +] + +{ #category : #tests } +FixedRandomMutantsSelectionTest >> testSelectMutantsFrom4 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := FixedRandomMutantsSelection new numberOfMutants: 20. + self assert: (select selectMutantsFrom: coll) equals: coll +] diff --git a/src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st b/src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st new file mode 100644 index 00000000..c9bb650b --- /dev/null +++ b/src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st @@ -0,0 +1,52 @@ +Class { + #name : #PercentRandomMutantsSelectionTest, + #superclass : #RandomMutantsEvaluationStrategyTest, + #category : #'MuTalk-Tests' +} + +{ #category : #tests } +PercentRandomMutantsSelectionTest >> testSelectMutantsFrom [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantsSelection new percentageOfMutants: 50. + self assert: (select selectMutantsFrom: coll) size equals: 5 +] + +{ #category : #tests } +PercentRandomMutantsSelectionTest >> testSelectMutantsFrom2 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantsSelection new percentageOfMutants: 0. + self + assert: (select selectMutantsFrom: coll) + equals: { } asOrderedCollection +] + +{ #category : #tests } +PercentRandomMutantsSelectionTest >> testSelectMutantsFrom3 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantsSelection new percentageOfMutants: 100. + self assert: (select selectMutantsFrom: coll) equals: coll +] + +{ #category : #tests } +PercentRandomMutantsSelectionTest >> testSelectMutantsFrom4 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantsSelection new. + self should: [ select percentageOfMutants: -50 ] raise: Error +] + +{ #category : #tests } +PercentRandomMutantsSelectionTest >> testSelectMutantsFrom5 [ + + | select coll | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantsSelection new. + self should: [ select percentageOfMutants: 150 ] raise: Error +] diff --git a/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st b/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st new file mode 100644 index 00000000..da79d855 --- /dev/null +++ b/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st @@ -0,0 +1,13 @@ +Class { + #name : #RandomMutantsEvaluationStrategyTest, + #superclass : #TestCase, + #category : #'MuTalk-Tests' +} + +{ #category : #tests } +RandomMutantsEvaluationStrategyTest >> testDefaultMutationsGenerationStrategy [ + + self + assert: RandomMutantsEvaluationStrategy new mutationsEvaluationStrategy species + equals: AllMutationsGenerationStrategy new species +] From 0997dc1aff870f1808e4fa28d72b6e1bafcb2921 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 14 Nov 2023 10:08:58 +0100 Subject: [PATCH 02/10] Renamed classes and attribute --- ...st => FixedRandomMutantSelection.class.st} | 10 +-- .../MutationTestingAnalysis.class.st | 4 +- ... => PercentRandomMutantSelection.class.st} | 10 +-- .../RandomMutantSelection.class.st | 68 +++++++++++++++++++ .../RandomMutantsEvaluationStrategy.class.st | 68 ------------------- ...> FixedRandomMutantSelectionTest.class.st} | 20 +++--- ...PercentRandomMutantSelectionTest.class.st} | 24 +++---- .../RandomMutantSelectionTest.class.st | 13 ++++ ...ndomMutantsEvaluationStrategyTest.class.st | 13 ---- 9 files changed, 115 insertions(+), 115 deletions(-) rename src/MuTalk-Model/{FixedRandomMutantsSelection.class.st => FixedRandomMutantSelection.class.st} (70%) rename src/MuTalk-Model/{PercentRandomMutantsSelection.class.st => PercentRandomMutantSelection.class.st} (74%) create mode 100644 src/MuTalk-Model/RandomMutantSelection.class.st delete mode 100644 src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st rename src/MuTalk-Tests/{FixedRandomMutantsSelectionTest.class.st => FixedRandomMutantSelectionTest.class.st} (52%) rename src/MuTalk-Tests/{PercentRandomMutantsSelectionTest.class.st => PercentRandomMutantSelectionTest.class.st} (52%) create mode 100644 src/MuTalk-Tests/RandomMutantSelectionTest.class.st delete mode 100644 src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st diff --git a/src/MuTalk-Model/FixedRandomMutantsSelection.class.st b/src/MuTalk-Model/FixedRandomMutantSelection.class.st similarity index 70% rename from src/MuTalk-Model/FixedRandomMutantsSelection.class.st rename to src/MuTalk-Model/FixedRandomMutantSelection.class.st index dfb89f82..c174aa67 100644 --- a/src/MuTalk-Model/FixedRandomMutantsSelection.class.st +++ b/src/MuTalk-Model/FixedRandomMutantSelection.class.st @@ -1,6 +1,6 @@ Class { - #name : #FixedRandomMutantsSelection, - #superclass : #RandomMutantsEvaluationStrategy, + #name : #FixedRandomMutantSelection, + #superclass : #RandomMutantSelection, #instVars : [ 'numberOfMutants' ], @@ -8,19 +8,19 @@ Class { } { #category : #accessing } -FixedRandomMutantsSelection >> numberOfMutants [ +FixedRandomMutantSelection >> numberOfMutants [ ^ numberOfMutants ] { #category : #accessing } -FixedRandomMutantsSelection >> numberOfMutants: aNumber [ +FixedRandomMutantSelection >> numberOfMutants: aNumber [ numberOfMutants := aNumber ] { #category : #accessing } -FixedRandomMutantsSelection >> selectMutantsFrom: aCollection [ +FixedRandomMutantSelection >> selectMutantsFrom: aCollection [ | size index newColl random | size := aCollection size. diff --git a/src/MuTalk-Model/MutationTestingAnalysis.class.st b/src/MuTalk-Model/MutationTestingAnalysis.class.st index fd0b0aef..926f55ec 100644 --- a/src/MuTalk-Model/MutationTestingAnalysis.class.st +++ b/src/MuTalk-Model/MutationTestingAnalysis.class.st @@ -278,13 +278,13 @@ MutationTestingAnalysis >> mutations: anObject [ ] { #category : #accessing } -MutationTestingAnalysis >> mutationsEvaluationStrategy [ +MutationTestingAnalysis >> mutationsGenerationStrategy [ ^ mutationsGenerationStrategy ] { #category : #accessing } -MutationTestingAnalysis >> mutationsEvaluationStrategy: anObject [ +MutationTestingAnalysis >> mutationsGenerationStrategy: anObject [ mutationsGenerationStrategy := anObject ] diff --git a/src/MuTalk-Model/PercentRandomMutantsSelection.class.st b/src/MuTalk-Model/PercentRandomMutantSelection.class.st similarity index 74% rename from src/MuTalk-Model/PercentRandomMutantsSelection.class.st rename to src/MuTalk-Model/PercentRandomMutantSelection.class.st index acc03b37..b9a2d80a 100644 --- a/src/MuTalk-Model/PercentRandomMutantsSelection.class.st +++ b/src/MuTalk-Model/PercentRandomMutantSelection.class.st @@ -1,6 +1,6 @@ Class { - #name : #PercentRandomMutantsSelection, - #superclass : #RandomMutantsEvaluationStrategy, + #name : #PercentRandomMutantSelection, + #superclass : #RandomMutantSelection, #instVars : [ 'percentageOfMutants' ], @@ -8,13 +8,13 @@ Class { } { #category : #accessing } -PercentRandomMutantsSelection >> percentageOfMutants [ +PercentRandomMutantSelection >> percentageOfMutants [ ^ percentageOfMutants ] { #category : #accessing } -PercentRandomMutantsSelection >> percentageOfMutants: aPercentage [ +PercentRandomMutantSelection >> percentageOfMutants: aPercentage [ (aPercentage < 0 or: [ aPercentage > 100 ]) ifTrue: [ Error signal: 'Percantage should be between 0 and 100' ]. @@ -22,7 +22,7 @@ PercentRandomMutantsSelection >> percentageOfMutants: aPercentage [ ] { #category : #accessing } -PercentRandomMutantsSelection >> selectMutantsFrom: aCollection [ +PercentRandomMutantSelection >> selectMutantsFrom: aCollection [ | size index newColl random numberOfMutants | size := aCollection size. diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st new file mode 100644 index 00000000..27a65e3c --- /dev/null +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -0,0 +1,68 @@ +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 : #accessing } +RandomMutantSelection >> defaultMutationGenerationStrategy [ + + ^ AllMutationsGenerationStrategy new +] + +{ #category : #accessing } +RandomMutantSelection >> initialize [ + + super initialize. + mutationsGenerationStrategy := self defaultMutationGenerationStrategy +] + +{ #category : #accessing } +RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis [ + + ^ self + mutationsFor: aMutationTestingAnalysis + loggingIn: self nullLogger +] + +{ #category : #accessing } +RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ + + | mutations | + mutations := mutationsGenerationStrategy mutationsFor: + aMutationTestingAnalysis loggingIn: aLogger. + ^ self selectMutantsFrom: mutations +] + +{ #category : #accessing } +RandomMutantSelection >> mutationsGenerationStrategy [ + + ^ mutationsGenerationStrategy +] + +{ #category : #accessing } +RandomMutantSelection >> mutationsGenerationStrategy: aMutationsGenerationStrategy [ + + mutationsGenerationStrategy := aMutationsGenerationStrategy +] + +{ #category : #accessing } +RandomMutantSelection >> nullLogger [ + + ^ mutationsGenerationStrategy nullLogger +] + +{ #category : #accessing } +RandomMutantSelection >> selectMutantsFrom: aCollection [ + + ^ self subclassResponsibility +] diff --git a/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st b/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st deleted file mode 100644 index 5d8678bc..00000000 --- a/src/MuTalk-Model/RandomMutantsEvaluationStrategy.class.st +++ /dev/null @@ -1,68 +0,0 @@ -Class { - #name : #RandomMutantsEvaluationStrategy, - #superclass : #Object, - #instVars : [ - 'mutationsEvaluationStrategy' - ], - #category : #'MuTalk-Model-Mutations generation strategies' -} - -{ #category : #'instance creation' } -RandomMutantsEvaluationStrategy class >> using: aMutationsGenerationStrategy [ - - ^ self new mutationsEvaluationStrategy: aMutationsGenerationStrategy -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> defaultMutationGenerationStrategy [ - - ^ AllMutationsGenerationStrategy new -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> initialize [ - - super initialize. - mutationsEvaluationStrategy := self defaultMutationGenerationStrategy -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> mutationsEvaluationStrategy [ - - ^ mutationsEvaluationStrategy -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> mutationsEvaluationStrategy: aMutationsEvaluationStrategy [ - - mutationsEvaluationStrategy := aMutationsEvaluationStrategy -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> mutationsFor: aMutationTestingAnalysis [ - - ^ self - mutationsFor: aMutationTestingAnalysis - loggingIn: self nullLogger -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ - - | mutations | - mutations := mutationsEvaluationStrategy mutationsFor: - aMutationTestingAnalysis loggingIn: aLogger. - ^ self selectMutantsFrom: mutations -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> nullLogger [ - - ^ mutationsEvaluationStrategy nullLogger -] - -{ #category : #accessing } -RandomMutantsEvaluationStrategy >> selectMutantsFrom: aCollection [ - - ^ self subclassResponsibility -] diff --git a/src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st b/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st similarity index 52% rename from src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st rename to src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st index 15585088..2b8cd800 100644 --- a/src/MuTalk-Tests/FixedRandomMutantsSelectionTest.class.st +++ b/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st @@ -1,43 +1,43 @@ Class { - #name : #FixedRandomMutantsSelectionTest, - #superclass : #RandomMutantsEvaluationStrategyTest, + #name : #FixedRandomMutantSelectionTest, + #superclass : #RandomMutantSelectionTest, #category : #'MuTalk-Tests' } { #category : #tests } -FixedRandomMutantsSelectionTest >> testSelectMutantsFrom [ +FixedRandomMutantSelectionTest >> testSelectMutantsFrom [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := FixedRandomMutantsSelection new numberOfMutants: 5. + select := FixedRandomMutantSelection new numberOfMutants: 5. self assert: (select selectMutantsFrom: coll) size equals: 5 ] { #category : #tests } -FixedRandomMutantsSelectionTest >> testSelectMutantsFrom2 [ +FixedRandomMutantSelectionTest >> testSelectMutantsFrom2 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := FixedRandomMutantsSelection new numberOfMutants: 0. + select := FixedRandomMutantSelection new numberOfMutants: 0. self assert: (select selectMutantsFrom: coll) equals: { } asOrderedCollection ] { #category : #tests } -FixedRandomMutantsSelectionTest >> testSelectMutantsFrom3 [ +FixedRandomMutantSelectionTest >> testSelectMutantsFrom3 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := FixedRandomMutantsSelection new numberOfMutants: 10. + select := FixedRandomMutantSelection new numberOfMutants: 10. self assert: (select selectMutantsFrom: coll) equals: coll ] { #category : #tests } -FixedRandomMutantsSelectionTest >> testSelectMutantsFrom4 [ +FixedRandomMutantSelectionTest >> testSelectMutantsFrom4 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := FixedRandomMutantsSelection new numberOfMutants: 20. + select := FixedRandomMutantSelection new numberOfMutants: 20. self assert: (select selectMutantsFrom: coll) equals: coll ] diff --git a/src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st b/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st similarity index 52% rename from src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st rename to src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st index c9bb650b..6a3b9ccc 100644 --- a/src/MuTalk-Tests/PercentRandomMutantsSelectionTest.class.st +++ b/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st @@ -1,52 +1,52 @@ Class { - #name : #PercentRandomMutantsSelectionTest, - #superclass : #RandomMutantsEvaluationStrategyTest, + #name : #PercentRandomMutantSelectionTest, + #superclass : #RandomMutantSelectionTest, #category : #'MuTalk-Tests' } { #category : #tests } -PercentRandomMutantsSelectionTest >> testSelectMutantsFrom [ +PercentRandomMutantSelectionTest >> testSelectMutantsFrom [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := PercentRandomMutantsSelection new percentageOfMutants: 50. + select := PercentRandomMutantSelection new percentageOfMutants: 50. self assert: (select selectMutantsFrom: coll) size equals: 5 ] { #category : #tests } -PercentRandomMutantsSelectionTest >> testSelectMutantsFrom2 [ +PercentRandomMutantSelectionTest >> testSelectMutantsFrom2 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := PercentRandomMutantsSelection new percentageOfMutants: 0. + select := PercentRandomMutantSelection new percentageOfMutants: 0. self assert: (select selectMutantsFrom: coll) equals: { } asOrderedCollection ] { #category : #tests } -PercentRandomMutantsSelectionTest >> testSelectMutantsFrom3 [ +PercentRandomMutantSelectionTest >> testSelectMutantsFrom3 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := PercentRandomMutantsSelection new percentageOfMutants: 100. + select := PercentRandomMutantSelection new percentageOfMutants: 100. self assert: (select selectMutantsFrom: coll) equals: coll ] { #category : #tests } -PercentRandomMutantsSelectionTest >> testSelectMutantsFrom4 [ +PercentRandomMutantSelectionTest >> testSelectMutantsFrom4 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := PercentRandomMutantsSelection new. + select := PercentRandomMutantSelection new. self should: [ select percentageOfMutants: -50 ] raise: Error ] { #category : #tests } -PercentRandomMutantsSelectionTest >> testSelectMutantsFrom5 [ +PercentRandomMutantSelectionTest >> testSelectMutantsFrom5 [ | select coll | coll := (1 to: 10) asOrderedCollection. - select := PercentRandomMutantsSelection new. + select := PercentRandomMutantSelection new. self should: [ select percentageOfMutants: 150 ] raise: Error ] diff --git a/src/MuTalk-Tests/RandomMutantSelectionTest.class.st b/src/MuTalk-Tests/RandomMutantSelectionTest.class.st new file mode 100644 index 00000000..e63b5399 --- /dev/null +++ b/src/MuTalk-Tests/RandomMutantSelectionTest.class.st @@ -0,0 +1,13 @@ +Class { + #name : #RandomMutantSelectionTest, + #superclass : #TestCase, + #category : #'MuTalk-Tests' +} + +{ #category : #tests } +RandomMutantSelectionTest >> testDefaultMutationsGenerationStrategy [ + + self + assert: RandomMutantSelection new mutationsGenerationStrategy species + equals: AllMutationsGenerationStrategy new species +] diff --git a/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st b/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st deleted file mode 100644 index da79d855..00000000 --- a/src/MuTalk-Tests/RandomMutantsEvaluationStrategyTest.class.st +++ /dev/null @@ -1,13 +0,0 @@ -Class { - #name : #RandomMutantsEvaluationStrategyTest, - #superclass : #TestCase, - #category : #'MuTalk-Tests' -} - -{ #category : #tests } -RandomMutantsEvaluationStrategyTest >> testDefaultMutationsGenerationStrategy [ - - self - assert: RandomMutantsEvaluationStrategy new mutationsEvaluationStrategy species - equals: AllMutationsGenerationStrategy new species -] From fcc33fbf2a6f81bf94fc8947fed178f6691de15c Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 14 Nov 2023 10:31:12 +0100 Subject: [PATCH 03/10] Fixing protocol names --- src/MuTalk-Model/RandomMutantSelection.class.st | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st index 27a65e3c..97f142a3 100644 --- a/src/MuTalk-Model/RandomMutantSelection.class.st +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -13,20 +13,20 @@ RandomMutantSelection class >> using: aMutationsGenerationStrategy [ ^ self new mutationsGenerationStrategy: aMutationsGenerationStrategy ] -{ #category : #accessing } +{ #category : #'accessing-defaults' } RandomMutantSelection >> defaultMutationGenerationStrategy [ ^ AllMutationsGenerationStrategy new ] -{ #category : #accessing } +{ #category : #initialization } RandomMutantSelection >> initialize [ super initialize. mutationsGenerationStrategy := self defaultMutationGenerationStrategy ] -{ #category : #accessing } +{ #category : #generating } RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis [ ^ self @@ -34,7 +34,7 @@ RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis [ loggingIn: self nullLogger ] -{ #category : #accessing } +{ #category : #generating } RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogger [ | mutations | @@ -55,7 +55,7 @@ RandomMutantSelection >> mutationsGenerationStrategy: aMutationsGenerationStrate mutationsGenerationStrategy := aMutationsGenerationStrategy ] -{ #category : #accessing } +{ #category : #logging } RandomMutantSelection >> nullLogger [ ^ mutationsGenerationStrategy nullLogger From 8b6aedf3a598ddfc92c3064be43a841f553d9369 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 14 Nov 2023 10:32:21 +0100 Subject: [PATCH 04/10] Added methods --- src/MuTalk-Model/RandomMutantSelection.class.st | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st index 97f142a3..e56fc029 100644 --- a/src/MuTalk-Model/RandomMutantSelection.class.st +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -26,6 +26,12 @@ RandomMutantSelection >> initialize [ mutationsGenerationStrategy := self defaultMutationGenerationStrategy ] +{ #category : #generating } +RandomMutantSelection >> methodsToMutateFrom: aMutationTestingAnalysis [ + + ^ mutationsGenerationStrategy methodsToMutateFrom: aMutationTestingAnalysis +] + { #category : #generating } RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis [ @@ -43,6 +49,15 @@ RandomMutantSelection >> mutationsFor: aMutationTestingAnalysis loggingIn: aLogg ^ self selectMutantsFrom: mutations ] +{ #category : #generating } +RandomMutantSelection >> mutationsFor: aMethod usingAll: aCollectionOfMutantOperators logginIn: aLogger [ + + ^ mutationsGenerationStrategy + mutationsFor: aMethod + usingAll: aCollectionOfMutantOperators + logginIn: aLogger +] + { #category : #accessing } RandomMutantSelection >> mutationsGenerationStrategy [ From 9f3b162c40ebc9892e87e58808e7998606245514 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 14 Nov 2023 17:38:40 +0100 Subject: [PATCH 05/10] Added code to ensure no mutants can be added twice, with tests --- src/MuTalk-Model/FixedRandomMutantSelection.class.st | 2 ++ .../PercentRandomMutantSelection.class.st | 2 ++ .../FixedRandomMutantSelectionTest.class.st | 12 ++++++++++++ .../PercentRandomMutantSelectionTest.class.st | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/MuTalk-Model/FixedRandomMutantSelection.class.st b/src/MuTalk-Model/FixedRandomMutantSelection.class.st index c174aa67..1d5a68d7 100644 --- a/src/MuTalk-Model/FixedRandomMutantSelection.class.st +++ b/src/MuTalk-Model/FixedRandomMutantSelection.class.st @@ -32,6 +32,8 @@ FixedRandomMutantSelection >> selectMutantsFrom: aCollection [ 1 to: numberOfMutants 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) ]. ^ newColl ] diff --git a/src/MuTalk-Model/PercentRandomMutantSelection.class.st b/src/MuTalk-Model/PercentRandomMutantSelection.class.st index b9a2d80a..d102c57c 100644 --- a/src/MuTalk-Model/PercentRandomMutantSelection.class.st +++ b/src/MuTalk-Model/PercentRandomMutantSelection.class.st @@ -35,6 +35,8 @@ PercentRandomMutantSelection >> selectMutantsFrom: aCollection [ 1 to: numberOfMutants 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) ]. ^ newColl ] diff --git a/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st b/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st index 2b8cd800..9e09140f 100644 --- a/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st +++ b/src/MuTalk-Tests/FixedRandomMutantSelectionTest.class.st @@ -41,3 +41,15 @@ FixedRandomMutantSelectionTest >> testSelectMutantsFrom4 [ select := FixedRandomMutantSelection new numberOfMutants: 20. self assert: (select selectMutantsFrom: coll) equals: coll ] + +{ #category : #tests } +FixedRandomMutantSelectionTest >> testSelectMutantsFromDistinctElements [ + + | select coll newColl | + coll := (1 to: 10) asOrderedCollection. + select := FixedRandomMutantSelection new numberOfMutants: 9. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] diff --git a/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st b/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st index 6a3b9ccc..b365a627 100644 --- a/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st +++ b/src/MuTalk-Tests/PercentRandomMutantSelectionTest.class.st @@ -50,3 +50,15 @@ PercentRandomMutantSelectionTest >> testSelectMutantsFrom5 [ select := PercentRandomMutantSelection new. self should: [ select percentageOfMutants: 150 ] raise: Error ] + +{ #category : #tests } +PercentRandomMutantSelectionTest >> testSelectMutantsFromDistinctElements [ + + | select coll newColl | + coll := (1 to: 10) asOrderedCollection. + select := PercentRandomMutantSelection new percentageOfMutants: 90. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] From 75b3658e878e9a2b77dcb41adf111f65f3c379fd Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Thu, 16 Nov 2023 11:19:23 +0100 Subject: [PATCH 06/10] Added two-round random selection, applied for both fixed number random and percentage random, with tests --- ...ixedRandomOperatorMutantSelection.class.st | 32 ++++++ ...centRandomOperatorMutantSelection.class.st | 33 ++++++ ...RandomOperatorMutantSelectionTest.class.st | 97 ++++++++++++++++ ...RandomOperatorMutantSelectionTest.class.st | 108 ++++++++++++++++++ 4 files changed, 270 insertions(+) create mode 100644 src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st create mode 100644 src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st create mode 100644 src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st create mode 100644 src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st diff --git a/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st b/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st new file mode 100644 index 00000000..af2f7a8c --- /dev/null +++ b/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st @@ -0,0 +1,32 @@ +Class { + #name : #FixedRandomOperatorMutantSelection, + #superclass : #FixedRandomMutantSelection, + #category : #'MuTalk-Model-Mutations generation strategies' +} + +{ #category : #accessing } +FixedRandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ + + | size index newColl random dict operators operator | + newColl := aCollection copyEmpty. + random := Random new. + + numberOfMutants = 0 ifTrue: [ ^ newColl ]. + aCollection size <= numberOfMutants ifTrue: [ ^ aCollection ]. + + dict := aCollection groupedBy: [ :e | e operator ]. + operators := dict keys. + 1 to: numberOfMutants do: [ :i | + operator := operators at: + (random nextIntegerBetween: 1 and: operators size). + [ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ] + whileTrue: [ + operator := operators at: + (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) ]. + ^ newColl +] diff --git a/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st b/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st new file mode 100644 index 00000000..69d60906 --- /dev/null +++ b/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st @@ -0,0 +1,33 @@ +Class { + #name : #PercentRandomOperatorMutantSelection, + #superclass : #PercentRandomMutantSelection, + #category : #'MuTalk-Model-Mutations generation strategies' +} + +{ #category : #accessing } +PercentRandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ + + | size index newColl random numberOfMutants dict operators operator | + newColl := aCollection copyEmpty. + random := Random new. + numberOfMutants := aCollection size * percentageOfMutants / 100. + + percentageOfMutants = 0 ifTrue: [ ^ newColl ]. + percentageOfMutants = 100 ifTrue: [ ^ aCollection ]. + + dict := aCollection groupedBy: [ :e | e operator ]. + operators := dict keys. + 1 to: numberOfMutants do: [ :i | + operator := operators at: + (random nextIntegerBetween: 1 and: operators size). + [ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ] + whileTrue: [ + operator := operators at: + (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) ]. + ^ newColl +] diff --git a/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st b/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st new file mode 100644 index 00000000..2c3ee1a8 --- /dev/null +++ b/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st @@ -0,0 +1,97 @@ +Class { + #name : #FixedRandomOperatorMutantSelectionTest, + #superclass : #RandomMutantSelectionTest, + #instVars : [ + 'coll' + ], + #category : #'MuTalk-Tests' +} + +{ #category : #running } +FixedRandomOperatorMutantSelectionTest >> setUp [ + + | mutants | + super setUp. + + coll := OrderedCollection new. + mutants := OrderedCollection new. + mutants addAll: { + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies) }. + coll addAll: mutants +] + +{ #category : #tests } +FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom [ + + | select newColl | + select := FixedRandomOperatorMutantSelection new numberOfMutants: 3. + newColl := select selectMutantsFrom: coll. + self assert: newColl size equals: 3 +] + +{ #category : #tests } +FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom2 [ + + | select newColl | + select := FixedRandomOperatorMutantSelection new numberOfMutants: 0. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: { } asOrderedCollection +] + +{ #category : #tests } +FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom3 [ + + | select newColl | + select := FixedRandomOperatorMutantSelection new numberOfMutants: 6. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom4 [ + + | select newColl | + select := FixedRandomOperatorMutantSelection new numberOfMutants: 10. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFromDistinctElements [ + + | select newColl | + select := FixedRandomOperatorMutantSelection new numberOfMutants: 5. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] diff --git a/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st b/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st new file mode 100644 index 00000000..389deb4a --- /dev/null +++ b/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st @@ -0,0 +1,108 @@ +Class { + #name : #PercentRandomOperatorMutantSelectionTest, + #superclass : #RandomMutantSelectionTest, + #instVars : [ + 'coll' + ], + #category : #'MuTalk-Tests' +} + +{ #category : #running } +PercentRandomOperatorMutantSelectionTest >> setUp [ + + | mutants | + super setUp. + + coll := OrderedCollection new. + mutants := OrderedCollection new. + mutants addAll: { + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies) }. + coll addAll: mutants +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom [ + + | select newColl | + select := PercentRandomOperatorMutantSelection new + percentageOfMutants: 50. + newColl := select selectMutantsFrom: coll. + self assert: newColl size equals: 3 +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom2 [ + + | select newColl | + select := PercentRandomOperatorMutantSelection new + percentageOfMutants: 0. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: { } asOrderedCollection +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom3 [ + + | select newColl | + select := PercentRandomOperatorMutantSelection new + percentageOfMutants: 100. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom4 [ + + | select | + select := PercentRandomOperatorMutantSelection new. + self should: [ select percentageOfMutants: -50 ] raise: Error +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom5 [ + + | select | + select := PercentRandomOperatorMutantSelection new. + self should: [ select percentageOfMutants: 150 ] raise: Error +] + +{ #category : #tests } +PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFromDistinctElements [ + + | select newColl | + select := PercentRandomOperatorMutantSelection new + percentageOfMutants: 90. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] From a2e261c26e20020d7fa29a89b969c7073c13e693 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 21 Nov 2023 10:23:58 +0100 Subject: [PATCH 07/10] Refactoring and protocol name fixed --- .../FixedRandomMutantSelection.class.st | 33 ++-- ...ixedRandomOperatorMutantSelection.class.st | 32 ---- .../PercentRandomMutantSelection.class.st | 38 +++-- ...centRandomOperatorMutantSelection.class.st | 33 ---- .../RandomMutantSelection.class.st | 33 +++- .../RandomOperatorMutantSelection.class.st | 142 ++++++++++++++++++ 6 files changed, 205 insertions(+), 106 deletions(-) delete mode 100644 src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st delete mode 100644 src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st create mode 100644 src/MuTalk-Model/RandomOperatorMutantSelection.class.st diff --git a/src/MuTalk-Model/FixedRandomMutantSelection.class.st b/src/MuTalk-Model/FixedRandomMutantSelection.class.st index 1d5a68d7..bfe846c8 100644 --- a/src/MuTalk-Model/FixedRandomMutantSelection.class.st +++ b/src/MuTalk-Model/FixedRandomMutantSelection.class.st @@ -8,32 +8,25 @@ Class { } { #category : #accessing } -FixedRandomMutantSelection >> numberOfMutants [ +FixedRandomMutantSelection >> highLimitCondition: aSize [ - ^ numberOfMutants + ^ aSize <= self numberOfMutants +] + +{ #category : #accessing } +FixedRandomMutantSelection >> lowLimitCondition [ + + ^ self numberOfMutants = 0 ] { #category : #accessing } -FixedRandomMutantSelection >> numberOfMutants: aNumber [ +FixedRandomMutantSelection >> numberOfMutants [ - numberOfMutants := aNumber + ^ numberOfMutants ] { #category : #accessing } -FixedRandomMutantSelection >> selectMutantsFrom: aCollection [ - - | size index newColl random | - size := aCollection size. - newColl := aCollection copyEmpty. - random := Random new. - - numberOfMutants = 0 ifTrue: [ ^ newColl ]. - aCollection size <= numberOfMutants ifTrue: [ ^ aCollection ]. - - 1 to: numberOfMutants 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) ]. - ^ newColl +FixedRandomMutantSelection >> numberOfMutants: aSize [ + + ^ numberOfMutants ] diff --git a/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st b/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st deleted file mode 100644 index af2f7a8c..00000000 --- a/src/MuTalk-Model/FixedRandomOperatorMutantSelection.class.st +++ /dev/null @@ -1,32 +0,0 @@ -Class { - #name : #FixedRandomOperatorMutantSelection, - #superclass : #FixedRandomMutantSelection, - #category : #'MuTalk-Model-Mutations generation strategies' -} - -{ #category : #accessing } -FixedRandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ - - | size index newColl random dict operators operator | - newColl := aCollection copyEmpty. - random := Random new. - - numberOfMutants = 0 ifTrue: [ ^ newColl ]. - aCollection size <= numberOfMutants ifTrue: [ ^ aCollection ]. - - dict := aCollection groupedBy: [ :e | e operator ]. - operators := dict keys. - 1 to: numberOfMutants do: [ :i | - operator := operators at: - (random nextIntegerBetween: 1 and: operators size). - [ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ] - whileTrue: [ - operator := operators at: - (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) ]. - ^ newColl -] diff --git a/src/MuTalk-Model/PercentRandomMutantSelection.class.st b/src/MuTalk-Model/PercentRandomMutantSelection.class.st index d102c57c..5580cfee 100644 --- a/src/MuTalk-Model/PercentRandomMutantSelection.class.st +++ b/src/MuTalk-Model/PercentRandomMutantSelection.class.st @@ -7,6 +7,24 @@ Class { #category : #'MuTalk-Model-Mutations generation strategies' } +{ #category : #accessing } +PercentRandomMutantSelection >> highLimitCondition: size [ + + ^ percentageOfMutants = 100 +] + +{ #category : #accessing } +PercentRandomMutantSelection >> lowLimitCondition [ + + ^ percentageOfMutants = 0 +] + +{ #category : #accessing } +PercentRandomMutantSelection >> numberOfMutants: aSize [ + + ^ percentageOfMutants * aSize / 100 +] + { #category : #accessing } PercentRandomMutantSelection >> percentageOfMutants [ @@ -20,23 +38,3 @@ PercentRandomMutantSelection >> percentageOfMutants: aPercentage [ Error signal: 'Percantage should be between 0 and 100' ]. percentageOfMutants := aPercentage ] - -{ #category : #accessing } -PercentRandomMutantSelection >> selectMutantsFrom: aCollection [ - - | size index newColl random numberOfMutants | - size := aCollection size. - newColl := aCollection copyEmpty. - random := Random new. - numberOfMutants := size * percentageOfMutants / 100. - - percentageOfMutants = 0 ifTrue: [ ^ newColl ]. - percentageOfMutants = 100 ifTrue: [ ^ aCollection ]. - - 1 to: numberOfMutants 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) ]. - ^ newColl -] diff --git a/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st b/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st deleted file mode 100644 index 69d60906..00000000 --- a/src/MuTalk-Model/PercentRandomOperatorMutantSelection.class.st +++ /dev/null @@ -1,33 +0,0 @@ -Class { - #name : #PercentRandomOperatorMutantSelection, - #superclass : #PercentRandomMutantSelection, - #category : #'MuTalk-Model-Mutations generation strategies' -} - -{ #category : #accessing } -PercentRandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ - - | size index newColl random numberOfMutants dict operators operator | - newColl := aCollection copyEmpty. - random := Random new. - numberOfMutants := aCollection size * percentageOfMutants / 100. - - percentageOfMutants = 0 ifTrue: [ ^ newColl ]. - percentageOfMutants = 100 ifTrue: [ ^ aCollection ]. - - dict := aCollection groupedBy: [ :e | e operator ]. - operators := dict keys. - 1 to: numberOfMutants do: [ :i | - operator := operators at: - (random nextIntegerBetween: 1 and: operators size). - [ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ] - whileTrue: [ - operator := operators at: - (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) ]. - ^ newColl -] diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st index e56fc029..c4a42313 100644 --- a/src/MuTalk-Model/RandomMutantSelection.class.st +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -19,6 +19,12 @@ RandomMutantSelection >> defaultMutationGenerationStrategy [ ^ AllMutationsGenerationStrategy new ] +{ #category : #accessing } +RandomMutantSelection >> highLimitCondition: aSize [ + + ^ self subclassResponsibility +] + { #category : #initialization } RandomMutantSelection >> initialize [ @@ -26,6 +32,12 @@ RandomMutantSelection >> initialize [ mutationsGenerationStrategy := self defaultMutationGenerationStrategy ] +{ #category : #accessing } +RandomMutantSelection >> lowLimitCondition [ + + ^ self subclassResponsibility +] + { #category : #generating } RandomMutantSelection >> methodsToMutateFrom: aMutationTestingAnalysis [ @@ -77,7 +89,26 @@ RandomMutantSelection >> nullLogger [ ] { #category : #accessing } -RandomMutantSelection >> selectMutantsFrom: aCollection [ +RandomMutantSelection >> numberOfMutants: aSize [ ^ self subclassResponsibility ] + +{ #category : #generating } +RandomMutantSelection >> selectMutantsFrom: aCollection [ + + | size index newColl random | + size := aCollection size. + newColl := aCollection copyEmpty. + random := Random new. + + self lowLimitCondition ifTrue: [ ^ newColl ]. + (self highLimitCondition: aCollection size) ifTrue: [ ^ aCollection ]. + + 1 to: (self numberOfMutants: 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) ]. + ^ newColl +] diff --git a/src/MuTalk-Model/RandomOperatorMutantSelection.class.st b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st new file mode 100644 index 00000000..5568f936 --- /dev/null +++ b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st @@ -0,0 +1,142 @@ +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 : #'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 >> numberOfMutants: aSize [ + + ^ randomMutantSelection numberOfMutants: aSize +] + +{ #category : #accessing } +RandomOperatorMutantSelection >> randomMutantSelection [ + + ^ randomMutantSelection +] + +{ #category : #accessing } +RandomOperatorMutantSelection >> randomMutantSelection: anObject [ + + randomMutantSelection := anObject +] + +{ #category : #generating } +RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ + + | size index 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 numberOfMutants: 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. + 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) ]. + ^ newColl +] From a9d3d95c1ca19389f80cc9d5fc24cef7337bd51f Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 21 Nov 2023 11:18:28 +0100 Subject: [PATCH 08/10] Fixed methods --- .../FixedRandomMutantSelection.class.st | 10 ++++++++-- .../PercentRandomMutantSelection.class.st | 12 ++++++------ src/MuTalk-Model/RandomMutantSelection.class.st | 14 +++++++------- .../RandomOperatorMutantSelection.class.st | 14 +++++++------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/MuTalk-Model/FixedRandomMutantSelection.class.st b/src/MuTalk-Model/FixedRandomMutantSelection.class.st index bfe846c8..0f1202e4 100644 --- a/src/MuTalk-Model/FixedRandomMutantSelection.class.st +++ b/src/MuTalk-Model/FixedRandomMutantSelection.class.st @@ -26,7 +26,13 @@ FixedRandomMutantSelection >> numberOfMutants [ ] { #category : #accessing } -FixedRandomMutantSelection >> numberOfMutants: aSize [ +FixedRandomMutantSelection >> numberOfMutants: aNumber [ - ^ numberOfMutants + numberOfMutants := aNumber +] + +{ #category : #accessing } +FixedRandomMutantSelection >> totalNumberOfMutants: aSize [ + + ^ self numberOfMutants ] diff --git a/src/MuTalk-Model/PercentRandomMutantSelection.class.st b/src/MuTalk-Model/PercentRandomMutantSelection.class.st index 5580cfee..d4659fc3 100644 --- a/src/MuTalk-Model/PercentRandomMutantSelection.class.st +++ b/src/MuTalk-Model/PercentRandomMutantSelection.class.st @@ -19,12 +19,6 @@ PercentRandomMutantSelection >> lowLimitCondition [ ^ percentageOfMutants = 0 ] -{ #category : #accessing } -PercentRandomMutantSelection >> numberOfMutants: aSize [ - - ^ percentageOfMutants * aSize / 100 -] - { #category : #accessing } PercentRandomMutantSelection >> percentageOfMutants [ @@ -38,3 +32,9 @@ PercentRandomMutantSelection >> percentageOfMutants: aPercentage [ Error signal: 'Percantage should be between 0 and 100' ]. percentageOfMutants := aPercentage ] + +{ #category : #accessing } +PercentRandomMutantSelection >> totalNumberOfMutants: aSize [ + + ^ percentageOfMutants * aSize / 100 +] diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st index c4a42313..6b387c02 100644 --- a/src/MuTalk-Model/RandomMutantSelection.class.st +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -88,12 +88,6 @@ RandomMutantSelection >> nullLogger [ ^ mutationsGenerationStrategy nullLogger ] -{ #category : #accessing } -RandomMutantSelection >> numberOfMutants: aSize [ - - ^ self subclassResponsibility -] - { #category : #generating } RandomMutantSelection >> selectMutantsFrom: aCollection [ @@ -105,10 +99,16 @@ RandomMutantSelection >> selectMutantsFrom: aCollection [ self lowLimitCondition ifTrue: [ ^ newColl ]. (self highLimitCondition: aCollection size) ifTrue: [ ^ aCollection ]. - 1 to: (self numberOfMutants: aCollection size) do: [ :i | + 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) ]. ^ newColl ] + +{ #category : #accessing } +RandomMutantSelection >> totalNumberOfMutants: aSize [ + + ^ self subclassResponsibility +] diff --git a/src/MuTalk-Model/RandomOperatorMutantSelection.class.st b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st index 5568f936..44ede5e1 100644 --- a/src/MuTalk-Model/RandomOperatorMutantSelection.class.st +++ b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st @@ -93,12 +93,6 @@ RandomOperatorMutantSelection >> nullLogger [ ^ randomMutantSelection nullLogger ] -{ #category : #accessing } -RandomOperatorMutantSelection >> numberOfMutants: aSize [ - - ^ randomMutantSelection numberOfMutants: aSize -] - { #category : #accessing } RandomOperatorMutantSelection >> randomMutantSelection [ @@ -123,7 +117,7 @@ RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ dict := aCollection groupedBy: [ :e | e operator ]. operators := dict keys. - 1 to: (self numberOfMutants: aCollection size) do: [ :i | + 1 to: (self totalNumberOfMutants: aCollection size) do: [ :i | operator := operators at: (random nextIntegerBetween: 1 and: operators size). @@ -140,3 +134,9 @@ RandomOperatorMutantSelection >> selectMutantsFrom: aCollection [ newColl add: ((dict at: operator) at: index) ]. ^ newColl ] + +{ #category : #accessing } +RandomOperatorMutantSelection >> totalNumberOfMutants: aSize [ + + ^ randomMutantSelection totalNumberOfMutants: aSize +] From a9d4a9e775ccf1e5ff44c54110530de72c9aa6a1 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 21 Nov 2023 11:18:43 +0100 Subject: [PATCH 09/10] Updated tests --- ...RandomOperatorMutantSelectionTest.class.st | 97 ----------- ...RandomOperatorMutantSelectionTest.class.st | 108 ------------- ...RandomOperatorMutantSelectionTest.class.st | 151 ++++++++++++++++++ 3 files changed, 151 insertions(+), 205 deletions(-) delete mode 100644 src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st delete mode 100644 src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st create mode 100644 src/MuTalk-Tests/RandomOperatorMutantSelectionTest.class.st diff --git a/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st b/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st deleted file mode 100644 index 2c3ee1a8..00000000 --- a/src/MuTalk-Tests/FixedRandomOperatorMutantSelectionTest.class.st +++ /dev/null @@ -1,97 +0,0 @@ -Class { - #name : #FixedRandomOperatorMutantSelectionTest, - #superclass : #RandomMutantSelectionTest, - #instVars : [ - 'coll' - ], - #category : #'MuTalk-Tests' -} - -{ #category : #running } -FixedRandomOperatorMutantSelectionTest >> setUp [ - - | mutants | - super setUp. - - coll := OrderedCollection new. - mutants := OrderedCollection new. - mutants addAll: { - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator1' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator2' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator3' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator1' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator2' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator3' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies) }. - coll addAll: mutants -] - -{ #category : #tests } -FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom [ - - | select newColl | - select := FixedRandomOperatorMutantSelection new numberOfMutants: 3. - newColl := select selectMutantsFrom: coll. - self assert: newColl size equals: 3 -] - -{ #category : #tests } -FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom2 [ - - | select newColl | - select := FixedRandomOperatorMutantSelection new numberOfMutants: 0. - newColl := select selectMutantsFrom: coll. - self assert: newColl equals: { } asOrderedCollection -] - -{ #category : #tests } -FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom3 [ - - | select newColl | - select := FixedRandomOperatorMutantSelection new numberOfMutants: 6. - newColl := select selectMutantsFrom: coll. - self assert: newColl equals: coll -] - -{ #category : #tests } -FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFrom4 [ - - | select newColl | - select := FixedRandomOperatorMutantSelection new numberOfMutants: 10. - newColl := select selectMutantsFrom: coll. - self assert: newColl equals: coll -] - -{ #category : #tests } -FixedRandomOperatorMutantSelectionTest >> testSelectMutantsFromDistinctElements [ - - | select newColl | - select := FixedRandomOperatorMutantSelection new numberOfMutants: 5. - newColl := select selectMutantsFrom: coll. - self - assert: newColl copyWithoutDuplicates asBag - equals: newColl asBag -] diff --git a/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st b/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st deleted file mode 100644 index 389deb4a..00000000 --- a/src/MuTalk-Tests/PercentRandomOperatorMutantSelectionTest.class.st +++ /dev/null @@ -1,108 +0,0 @@ -Class { - #name : #PercentRandomOperatorMutantSelectionTest, - #superclass : #RandomMutantSelectionTest, - #instVars : [ - 'coll' - ], - #category : #'MuTalk-Tests' -} - -{ #category : #running } -PercentRandomOperatorMutantSelectionTest >> setUp [ - - | mutants | - super setUp. - - coll := OrderedCollection new. - mutants := OrderedCollection new. - mutants addAll: { - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator1' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator2' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method1 - using: 'Operator3' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator1' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator2' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies). - (MethodMutation - for: AuxiliarClassForTestingStrategies >> #method2 - using: 'Operator3' - nodeNumber: 1 - ofClass: AuxiliarClassForTestingStrategies) }. - coll addAll: mutants -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom [ - - | select newColl | - select := PercentRandomOperatorMutantSelection new - percentageOfMutants: 50. - newColl := select selectMutantsFrom: coll. - self assert: newColl size equals: 3 -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom2 [ - - | select newColl | - select := PercentRandomOperatorMutantSelection new - percentageOfMutants: 0. - newColl := select selectMutantsFrom: coll. - self assert: newColl equals: { } asOrderedCollection -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom3 [ - - | select newColl | - select := PercentRandomOperatorMutantSelection new - percentageOfMutants: 100. - newColl := select selectMutantsFrom: coll. - self assert: newColl equals: coll -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom4 [ - - | select | - select := PercentRandomOperatorMutantSelection new. - self should: [ select percentageOfMutants: -50 ] raise: Error -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFrom5 [ - - | select | - select := PercentRandomOperatorMutantSelection new. - self should: [ select percentageOfMutants: 150 ] raise: Error -] - -{ #category : #tests } -PercentRandomOperatorMutantSelectionTest >> testSelectMutantsFromDistinctElements [ - - | select newColl | - select := PercentRandomOperatorMutantSelection new - percentageOfMutants: 90. - newColl := select selectMutantsFrom: coll. - self - assert: newColl copyWithoutDuplicates asBag - equals: newColl asBag -] diff --git a/src/MuTalk-Tests/RandomOperatorMutantSelectionTest.class.st b/src/MuTalk-Tests/RandomOperatorMutantSelectionTest.class.st new file mode 100644 index 00000000..bb76d729 --- /dev/null +++ b/src/MuTalk-Tests/RandomOperatorMutantSelectionTest.class.st @@ -0,0 +1,151 @@ +Class { + #name : #RandomOperatorMutantSelectionTest, + #superclass : #TestCase, + #instVars : [ + 'coll' + ], + #category : #'MuTalk-Tests' +} + +{ #category : #running } +RandomOperatorMutantSelectionTest >> setUp [ + + | mutants | + super setUp. + + coll := OrderedCollection new. + mutants := OrderedCollection new. + mutants addAll: { + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method1 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator1' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator2' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies). + (MethodMutation + for: AuxiliarClassForTestingStrategies >> #method2 + using: 'Operator3' + nodeNumber: 1 + ofClass: AuxiliarClassForTestingStrategies) }. + coll addAll: mutants +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testFixedSelectMutantsFrom [ + + | select newColl | + select := RandomOperatorMutantSelection fixed: 3. + newColl := select selectMutantsFrom: coll. + self assert: newColl size equals: 3 +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testFixedSelectMutantsFrom2 [ + + | select newColl | + select := RandomOperatorMutantSelection fixed: 0. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: { } asOrderedCollection +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testFixedSelectMutantsFrom3 [ + + | select newColl | + select := RandomOperatorMutantSelection fixed: 6. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testFixedSelectMutantsFrom4 [ + + | select newColl | + select := RandomOperatorMutantSelection fixed: 10. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testFixedSelectMutantsFromDistinctElements [ + + | select newColl | + select := RandomOperatorMutantSelection fixed: 5. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFrom [ + + | select newColl | + select := RandomOperatorMutantSelection percent: 50. + newColl := select selectMutantsFrom: coll. + self assert: newColl size equals: 3 +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFrom2 [ + + | select newColl | + select := RandomOperatorMutantSelection percent: 0. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: { } asOrderedCollection +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFrom3 [ + + | select newColl | + select := RandomOperatorMutantSelection percent: 100. + newColl := select selectMutantsFrom: coll. + self assert: newColl equals: coll +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFrom4 [ + + self + should: [ RandomOperatorMutantSelection percent: -50 ] + raise: Error +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFrom5 [ + + self + should: [ RandomOperatorMutantSelection percent: 150 ] + raise: Error +] + +{ #category : #tests } +RandomOperatorMutantSelectionTest >> testPercentSelectMutantsFromDistinctElements [ + + | select newColl | + select := RandomOperatorMutantSelection percent: 90. + newColl := select selectMutantsFrom: coll. + self + assert: newColl copyWithoutDuplicates asBag + equals: newColl asBag +] From 18a123ae320df83bff3e71062bc3b6aa539df954 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 21 Nov 2023 12:07:09 +0100 Subject: [PATCH 10/10] More refactoring --- .../RandomMutantSelection.class.st | 24 +++++++++++++++---- .../RandomOperatorMutantSelection.class.st | 17 +++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/MuTalk-Model/RandomMutantSelection.class.st b/src/MuTalk-Model/RandomMutantSelection.class.st index 6b387c02..bff8a5e6 100644 --- a/src/MuTalk-Model/RandomMutantSelection.class.st +++ b/src/MuTalk-Model/RandomMutantSelection.class.st @@ -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 [ @@ -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. @@ -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 ] diff --git a/src/MuTalk-Model/RandomOperatorMutantSelection.class.st b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st index 44ede5e1..6303b94f 100644 --- a/src/MuTalk-Model/RandomOperatorMutantSelection.class.st +++ b/src/MuTalk-Model/RandomOperatorMutantSelection.class.st @@ -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 [ @@ -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. @@ -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 ]