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

Improvements to RandomMutantSelectionStrategyTest #46

Merged
merged 9 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
26 changes: 26 additions & 0 deletions src/MuTalk-Model/MethodMutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ MethodMutation class >> for: aMethod using: anOperatorApplied nodeNumber: aNodeN
yourself
]

{ #category : 'comparing' }
MethodMutation >> = anObject [
"Two method mutations are equals if they have the same operator,if they mutate the same method from the same class, and if they have the same node number"

self == anObject ifTrue: [ ^ true ].
anObject species = self class ifFalse: [ ^ false ].
self operator species = anObject operator species ifFalse: [ ^ false ].
self originalMethod = anObject originalMethod ifFalse: [ ^ false ].
self originalClass = anObject originalClass ifFalse: [ ^ false ].
self nodeNumber = anObject nodeNumber ifFalse: [ ^ false ].
^ true
]

{ #category : 'comparing' }
MethodMutation >> hash [

^ self operator species hash + self originalMethod hash
+ self originalClass hash + self nodeNumber hash
]

{ #category : 'initialize-release' }
MethodMutation >> initializeFor: aMethod using: anOperatorApplied nodeNumber: aNodeNumber ofClass: aClass [
originalMethod := aMethod.
Expand Down Expand Up @@ -53,6 +73,12 @@ MethodMutation >> mutatedNode [
^ operator applyTo: self nodeToMutate
]

{ #category : 'accessing' }
MethodMutation >> nodeNumber [

^ nodeNumber
]

{ #category : 'accessing' }
MethodMutation >> nodeNumber: anInteger [
nodeNumber := anInteger
Expand Down
65 changes: 65 additions & 0 deletions src/MuTalk-Tests/RandomMutantSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Class {
#name : 'RandomMutantSelectionStrategyTest',
#superclass : 'TestCase',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'comparing' }
RandomMutantSelectionStrategyTest >> atLeastTwoDifferentMutantCollectionsIn: aCollection [
"aCollection is a collection of mutant collections. This method returns true if among these mutant collections, at least 2 are differents."

1 to: aCollection size - 1 do: [ :i |
i + 1 to: aCollection size do: [ :j |
"By iterating like this, we ensure to compare each mutant collection with every other collections
For example, when i = 1, 2 <= j <= 5, when i = 2, 3 <= j <= 5 (collection 2 and collection 1 have already been compared previously), etc"
(self
sameMutationOrderIn: (aCollection at: i)
and: (aCollection at: j)) ifFalse: [ ^ true ] ] ].
^ false
guillep marked this conversation as resolved.
Show resolved Hide resolved
]

{ #category : 'comparing' }
RandomMutantSelectionStrategyTest >> sameMutationOrderIn: mutantCollection1 and: mutantCollection2 [
"Compares the order of the mutants in 2 mutant collections. The mutants may be the same in both collections, but we check if they are in the same order
Returns true if they are in the same order, else false"

| mutant1 mutant2 |
mutantCollection1 size = mutantCollection2 size ifFalse: [ ^ false ].
1 to: mutantCollection1 size do: [ :i |
mutant1 := mutantCollection1 at: i.
mutant2 := mutantCollection2 at: i.
mutant1 = mutant2 ifFalse: [ ^ false ] ].
^ true
guillep marked this conversation as resolved.
Show resolved Hide resolved
]

{ #category : 'tests' }
RandomMutantSelectionStrategyTest >> testAtLeastTwoDifferentMutantCollectionsAmongFive [
"This test is to ensure that RandomMutantSelectionStrategy doesn't always produce the same mutant collections.
If it can produce at least two different collections, we assume it correctly randomize the inital mutant collection.
Here, two mutant collections are differents when their mutants are not in the same order."

| analysis mutationsCollection |
"mutationsCollection is a collection of mutant collections"
mutationsCollection := OrderedCollection new.
1 to: 5 do: [ :i |
analysis := MutationTestingAnalysis
testCasesFrom:
{ AuxiliarClassForMutationTestingAnalysisTest }
mutating: { AuxiliarClassForMutationTestingAnalysis }
using: MutantOperator contents
with: AllTestsMethodsRunningTestSelectionStrategy new
with: RandomMutantSelectionStrategy new.
mutationsCollection add: analysis generateMutations ].

self assert:
(self atLeastTwoDifferentMutantCollectionsIn: mutationsCollection)
]

{ #category : 'tests' }
RandomMutantSelectionStrategyTest >> testDefaultMutationsGenerationStrategyIsAllMutantSelectionStrategy [

self
assert: RandomMutantSelectionStrategy new mutationsGenerationStrategy species
equals: AllMutantSelectionStrategy new species
]
50 changes: 0 additions & 50 deletions src/MuTalk-Tests/RandomMutantSelectionTest.class.st

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Class {
#name : 'RandomOperatorMutantSelectionStrategyTest',
#superclass : 'RandomMutantSelectionStrategyTest',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}
guillep marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 0 additions & 6 deletions src/MuTalk-Tests/RandomOperatorMutantSelectionTest.class.st

This file was deleted.

Loading