Skip to content

Commit

Permalink
Merge pull request #110 from DurieuxPol/enh/betterDefaults
Browse files Browse the repository at this point in the history
Changed default values of analysis
  • Loading branch information
guillep authored Apr 16, 2024
2 parents 5e7978b + fba74ed commit 639f4c6
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ MTCoveragePropagationPreparationTest >> testWorking [
| analysis moreInfo mutant |
analysis := MTAnalysis new
testClasses: { MTCIHelperTest };
classesToMutate: { MTCIHelper }.
classesToMutate: { MTCIHelper };
budget: MTFreeBudget new.
analysis run.

moreInfo := MTCoveragePropagationPreparation new
Expand Down
19 changes: 1 addition & 18 deletions src/MuTalk-Model/MTAbstractMutantOperator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Class {
{ #category : 'accessing' }
MTAbstractMutantOperator class >> allConcreteSubclasses [

^ self allSubclasses reject: [ :ea |
ea isAbstract | ea isOriginalOperator not ]
^ self allSubclasses reject: #isAbstract
]

{ #category : 'accessing' }
Expand All @@ -22,28 +21,12 @@ MTAbstractMutantOperator class >> contents [
elem1 description <= elem2 description ]
]

{ #category : 'accessing' }
MTAbstractMutantOperator class >> contentsAll [
"This returns all operators (block based and traditional) "

^ ((self allSubclasses reject: [ :ea |
ea isAbstract or: [ ea isDeprecated ] ]) collect: [ :class |
class new ]) asSortedCollection: [ :elem1 :elem2 |
elem1 description <= elem2 description ]
]

{ #category : 'testing' }
MTAbstractMutantOperator class >> isAbstract [

^ self == MTAbstractMutantOperator
]

{ #category : 'testing' }
MTAbstractMutantOperator class >> isOriginalOperator [

^ true
]

{ #category : 'as yet unclassified' }
MTAbstractMutantOperator class >> recursionsDetectionStatement [

Expand Down
82 changes: 66 additions & 16 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,21 @@ MTAnalysis >> coverageAnalysisResult: anObject [

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultBudget [
"Since tests often take little time to run, we multiply it by 30"

^ MTFreeBudget new
^ MTTimeBudget for: self totalTestsTime * 30
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultLogger [

^ MTNullLogger new
^ MTTranscriptLogger new
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultMutantGenerationStrategy [

^ MTAllMutantGenerationStrategy new
^ MTAllMutantGenerationStrategy withRandomOperatorMutantSelection
]

{ #category : 'accessing - defaults' }
Expand All @@ -78,13 +79,20 @@ MTAnalysis >> defaultOperators [
{ #category : 'accessing - defaults' }
MTAnalysis >> defaultTestFilter [

^ MTFreeTestFilter new
| times |
times := testCases collect: #lastTimeToRun.
(times anySatisfy: #isNil) ifTrue: [
^ Error signal:
'Either there is no test cases, or the initial test run has not been executed yet' ].
^ MTCompositeTestFilter for: {
MTRedTestFilter new.
(MTTimeTestFilter for: (self percentile: 90 for: times sorted)) }
]

{ #category : 'accessing - defaults' }
MTAnalysis >> defaultTestSelectionStrategy [

^ MTAllTestsMethodsRunningTestSelectionStrategy new
^ MTSelectingFromCoverageTestSelectionStrategy new
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -151,7 +159,9 @@ MTAnalysis >> initialTestRun [

| results |
results := testCases collect: [ :aTestCase | aTestCase run ].
testFilter validateFailuresIn: results.

"The test filter is initialized lazily here because the default one needs the run time of tests, so the initial test run must be executed first"
self testFilter validateFailuresIn: results.
testCases := testFilter filterTests: testCases
]

Expand All @@ -165,8 +175,6 @@ MTAnalysis >> initialize [
mutantResults := OrderedCollection new.
elapsedTime := 0.
logger := self defaultLogger.
budget := self defaultBudget.
testFilter := self defaultTestFilter.
stopOnErrorOrFail := true
]

Expand Down Expand Up @@ -223,6 +231,13 @@ MTAnalysis >> mutations: anObject [
mutations := anObject
]

{ #category : 'initialization' }
MTAnalysis >> noLimitations [

budget := MTFreeBudget new.
testFilter := MTFreeTestFilter new
]

{ #category : 'accessing' }
MTAnalysis >> operators [

Expand All @@ -242,6 +257,17 @@ MTAnalysis >> packagesToMutate: aCollectionOfPackages [
packageName asPackage definedClasses ]
]

{ #category : 'computing' }
MTAnalysis >> percentile: aPercentage for: aCollection [

| size index |
aCollection isEmpty ifTrue: [
^ CollectionIsEmpty signalWith: aCollection ].
size := aCollection size.
index := (aPercentage percent * size) rounded.
^ aCollection at: index
]

{ #category : 'running' }
MTAnalysis >> run [
"Obtain mutants applying the operators in the classes (or
Expand All @@ -250,8 +276,9 @@ MTAnalysis >> run [
We obtain a result for each mutant generated"

^ [
budget start.
self initialTestRun.
"The budget is started after the initial test run because the default one needs the run time of tests"
self startBudget.
logger logAnalysisStartFor: self.
elapsedTime := [
self generateCoverageAnalysis.
Expand All @@ -265,6 +292,14 @@ MTAnalysis >> run [
false ]
]

{ #category : 'starting' }
MTAnalysis >> startBudget [
"The budget is initialized here because the default one needs the run time of tests, so the initial test run must be executed first"

budget ifNil: [ budget := self defaultBudget ].
budget start
]

{ #category : 'accessing' }
MTAnalysis >> stopOnErrorOrFail: aBoolean [

Expand Down Expand Up @@ -292,12 +327,17 @@ MTAnalysis >> testCases: anObject [
{ #category : 'accessing' }
MTAnalysis >> testCasesFrom: aClassCollection [

^ aClassCollection
inject: OrderedCollection new
into: [ :testCase :testClass |
testClass isAbstract ifFalse: [
testCase addAll: (self testCasesReferencesFrom: testClass) ].
testCase ]
| tests |
tests := aClassCollection
inject: OrderedCollection new
into: [ :testCase :testClass |
testClass isAbstract ifFalse: [
testCase addAll:
(self testCasesReferencesFrom: testClass) ].
testCase ].
tests isEmpty ifTrue: [
Warning signal: 'There is currently no tests' ].
^ tests
]

{ #category : 'tests' }
Expand All @@ -316,7 +356,7 @@ MTAnalysis >> testClasses: aClassCollection [
{ #category : 'accessing' }
MTAnalysis >> testFilter [

^ testFilter
^ testFilter ifNil: [ testFilter := self defaultTestFilter ]
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -346,3 +386,13 @@ MTAnalysis >> testSelectionStrategy: anObject [

testSelectionStrategy := anObject
]

{ #category : 'accessing' }
MTAnalysis >> totalTestsTime [

| times |
times := testCases collect: #lastTimeToRun.
(times anySatisfy: #isNil) ifTrue: [
^ Error signal: 'The initial test run has not been executed yet' ].
^ times reduce: [ :t1 :t2 | t1 + t2 ]
]
5 changes: 0 additions & 5 deletions src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ MTPredicateBasedMutantOperator class >> isAbstract [
^ self == MTPredicateBasedMutantOperator
]

{ #category : 'testing' }
MTPredicateBasedMutantOperator class >> isOriginalOperator [
^ false
]

{ #category : 'private' }
MTPredicateBasedMutantOperator >> affectedNodeFor: aParseTree at: nodeIndex [

Expand Down
3 changes: 2 additions & 1 deletion src/MuTalk-Tests/MTAnalysisLoggerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ MTAnalysisLoggerTest >> testExecutingSimpleMutation [
classesToMutate:
(Array with: MTAuxiliarClassForMTAnalysis);
operators: (Array with: operator);
logger: logger.
logger: logger;
budget: MTFreeBudget new.
analysis run.
self assert: logger loggedStartAnalysis.
self assert: (logger
Expand Down
Loading

0 comments on commit 639f4c6

Please sign in to comment.