From 5b327421722d2a4b048f6589a3f8524bf780dc16 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 9 Apr 2024 17:12:25 +0200 Subject: [PATCH 01/16] changed default values for analysis --- src/MuTalk-Model/MTAnalysis.class.st | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index c119188..a26ad4d 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -60,19 +60,19 @@ MTAnalysis >> defaultBudget [ { #category : 'accessing - defaults' } MTAnalysis >> defaultLogger [ - ^ MTNullLogger new + ^ MTTranscriptLogger new ] { #category : 'accessing - defaults' } MTAnalysis >> defaultMutantGenerationStrategy [ - ^ MTAllMutantGenerationStrategy new + ^ MTAllMutantGenerationStrategy withRandomOperatorMutantSelection ] { #category : 'accessing - defaults' } MTAnalysis >> defaultOperators [ - ^ MTAbstractMutantOperator contents + ^ MTAbstractMutantOperator contentsAll ] { #category : 'accessing - defaults' } @@ -84,7 +84,7 @@ MTAnalysis >> defaultTestFilter [ { #category : 'accessing - defaults' } MTAnalysis >> defaultTestSelectionStrategy [ - ^ MTAllTestsMethodsRunningTestSelectionStrategy new + ^ MTSelectingFromCoverageTestSelectionStrategy new ] { #category : 'accessing' } From de66d35c9af68de968e0d6b5a34fba4418df47d5 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 9 Apr 2024 17:21:37 +0200 Subject: [PATCH 02/16] changed default budget + budget starts later during the analysis --- src/MuTalk-Model/MTAnalysis.class.st | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index a26ad4d..45e5618 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -54,7 +54,7 @@ MTAnalysis >> coverageAnalysisResult: anObject [ { #category : 'accessing - defaults' } MTAnalysis >> defaultBudget [ - ^ MTFreeBudget new + ^ MTTimeBudget for: 3 * self totalTestsTime ] { #category : 'accessing - defaults' } @@ -165,7 +165,6 @@ MTAnalysis >> initialize [ mutantResults := OrderedCollection new. elapsedTime := 0. logger := self defaultLogger. - budget := self defaultBudget. testFilter := self defaultTestFilter. stopOnErrorOrFail := true ] @@ -250,8 +249,8 @@ MTAnalysis >> run [ We obtain a result for each mutant generated" ^ [ - budget start. self initialTestRun. + self startBudget. logger logAnalysisStartFor: self. elapsedTime := [ self generateCoverageAnalysis. @@ -265,6 +264,13 @@ MTAnalysis >> run [ false ] ] +{ #category : 'starting' } +MTAnalysis >> startBudget [ + + budget ifNil: [ budget := self defaultBudget ]. + budget start +] + { #category : 'accessing' } MTAnalysis >> stopOnErrorOrFail: aBoolean [ @@ -346,3 +352,11 @@ MTAnalysis >> testSelectionStrategy: anObject [ testSelectionStrategy := anObject ] + +{ #category : 'accessing' } +MTAnalysis >> totalTestsTime [ + + | times | + times := testCases collect: #lastTimeToRun. + ^ times reduce: [ :t1 :t2 | t1 + t2 ] +] From 9b702184cd5e21a417dc1c230bfab94afbcac94c Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 10 Apr 2024 11:52:06 +0200 Subject: [PATCH 03/16] change to matrix to fix tests --- src/MuTalk-Utilities/MTMatrix.class.st | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/MuTalk-Utilities/MTMatrix.class.st b/src/MuTalk-Utilities/MTMatrix.class.st index 1aad627..7df053a 100644 --- a/src/MuTalk-Utilities/MTMatrix.class.st +++ b/src/MuTalk-Utilities/MTMatrix.class.st @@ -290,15 +290,21 @@ MTMatrix >> mutations: anObject [ { #category : 'running' } MTMatrix >> runAnalysis [ - analysis := MTAnalysis new - classesToMutate: classesToMutate; - testClasses: testClasses; - doNotStopOnErrorOrFail. + analysis ifNil: [ self setUpAnalysis ]. analysis run. testCases := analysis testCases. mutations := analysis mutations ] +{ #category : 'initialization' } +MTMatrix >> setUpAnalysis [ + + analysis := MTAnalysis new + classesToMutate: classesToMutate; + testClasses: testClasses; + doNotStopOnErrorOrFail +] + { #category : 'accessing' } MTMatrix >> testCases [ From 516fe5fa57edaf7f2084d04ec4295bcdb939d974 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 10 Apr 2024 12:03:00 +0200 Subject: [PATCH 04/16] fix tests --- src/MuTalk-Tests/MTAnalysisTest.class.st | 7 +++++-- src/MuTalk-Tests/MTBudgetTest.class.st | 3 ++- src/MuTalk-Tests/MTTimeBudgetTest.class.st | 3 +++ src/MuTalk-Utilities-Tests/MTMatrixTest.class.st | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index 74b71c7..aa0179b 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -77,13 +77,14 @@ MTAnalysisTest >> testDefaultParameters [ analysis := MTAnalysis new. self assert: (analysis operators collect: [ :op | op species ]) - equals: (MTAbstractMutantOperator contents collect: [ :op | op species ]). + equals: + (MTAbstractMutantOperator contentsAll collect: [ :op | op species ]). self assert: analysis mutantGenerationStrategy species equals: MTAllMutantGenerationStrategy. self assert: analysis testSelectionStrategy species - equals: MTAllTestsMethodsRunningTestSelectionStrategy. + equals: MTSelectingFromCoverageTestSelectionStrategy. self assert: analysis budget species equals: MTFreeBudget ] @@ -257,6 +258,8 @@ MTAnalysisTest >> testRunningAllTests [ testClasses: { MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail }; classesToMutate: { MTAuxiliarClassForMTAnalysis }; + testSelectionStrategy: + MTAllTestsMethodsRunningTestSelectionStrategy new; doNotStopOnErrorOrFail. "In this class, tests fail after a certain of executions" diff --git a/src/MuTalk-Tests/MTBudgetTest.class.st b/src/MuTalk-Tests/MTBudgetTest.class.st index 044c043..fbfa2e0 100644 --- a/src/MuTalk-Tests/MTBudgetTest.class.st +++ b/src/MuTalk-Tests/MTBudgetTest.class.st @@ -29,7 +29,8 @@ MTBudgetTest >> runAnalysisWithBudget: aBudget on: classesToMutate withTests: te analysis := MTAnalysis new testClasses: testCases; classesToMutate: classesToMutate; - budget: aBudget. + budget: aBudget; + operators: MTAbstractMutantOperator contents. analysis run. ^ analysis generalResult diff --git a/src/MuTalk-Tests/MTTimeBudgetTest.class.st b/src/MuTalk-Tests/MTTimeBudgetTest.class.st index 0ba8580..f463bf4 100644 --- a/src/MuTalk-Tests/MTTimeBudgetTest.class.st +++ b/src/MuTalk-Tests/MTTimeBudgetTest.class.st @@ -23,6 +23,9 @@ MTTimeBudgetTest >> runAnalysisWithBudget: aBudget on: classesToMutate withTests analysis := MTAnalysis new testClasses: testCases; classesToMutate: classesToMutate; + logger: MTNullLogger new; + testSelectionStrategy: + MTAllTestsMethodsRunningTestSelectionStrategy new; mutantGenerationStrategy: (MTManualMutationGenerationStrategy with: (Generator on: [ :gen | diff --git a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st index 462d012..0961595 100644 --- a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st +++ b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st @@ -16,6 +16,8 @@ MTMatrixTest >> setUp [ super setUp. matrix := MTMatrix forClasses: { MTAuxiliarClassForMatrix }. + matrix setUpAnalysis. + matrix analysis operators: MTAbstractMutantOperator contents. matrix build. self setUpVariablesForTest ] From 5519d1f6b9bef9db3816f8371263cc0e60ccff37 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 10 Apr 2024 16:52:46 +0200 Subject: [PATCH 05/16] changed default test filter and budget, and fix tests --- src/MuTalk-Model/MTAnalysis.class.st | 22 ++++++++-- .../MTAnalysisLoggerTest.class.st | 3 +- src/MuTalk-Tests/MTAnalysisTest.class.st | 43 +++++++++++-------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index 45e5618..9a8da08 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -54,7 +54,7 @@ MTAnalysis >> coverageAnalysisResult: anObject [ { #category : 'accessing - defaults' } MTAnalysis >> defaultBudget [ - ^ MTTimeBudget for: 3 * self totalTestsTime + ^ MTTimeBudget for: self totalTestsTime * 30 ] { #category : 'accessing - defaults' } @@ -78,7 +78,12 @@ MTAnalysis >> defaultOperators [ { #category : 'accessing - defaults' } MTAnalysis >> defaultTestFilter [ - ^ MTFreeTestFilter new + ^ MTCompositeTestFilter for: { + MTRedTestFilter new. + (MTTimeTestFilter for: + (self + percentile: 90 + for: (testCases collect: #lastTimeToRun) sorted)) } ] { #category : 'accessing - defaults' } @@ -151,6 +156,7 @@ MTAnalysis >> initialTestRun [ | results | results := testCases collect: [ :aTestCase | aTestCase run ]. + testFilter ifNil: [ testFilter := self defaultTestFilter ]. testFilter validateFailuresIn: results. testCases := testFilter filterTests: testCases ] @@ -165,7 +171,6 @@ MTAnalysis >> initialize [ mutantResults := OrderedCollection new. elapsedTime := 0. logger := self defaultLogger. - testFilter := self defaultTestFilter. stopOnErrorOrFail := true ] @@ -241,6 +246,16 @@ MTAnalysis >> packagesToMutate: aCollectionOfPackages [ packageName asPackage definedClasses ] ] +{ #category : 'computing' } +MTAnalysis >> percentile: aPercentage for: aCollection [ + + | size index | + aCollection isEmpty ifTrue: [ ^ nil ]. + size := aCollection size. + index := (aPercentage percent * size) rounded. + ^ aCollection at: index +] + { #category : 'running' } MTAnalysis >> run [ "Obtain mutants applying the operators in the classes (or @@ -357,6 +372,7 @@ MTAnalysis >> testSelectionStrategy: anObject [ MTAnalysis >> totalTestsTime [ | times | + testCases isEmpty ifTrue: [ ^ 0 milliSecond ]. times := testCases collect: #lastTimeToRun. ^ times reduce: [ :t1 :t2 | t1 + t2 ] ] diff --git a/src/MuTalk-Tests/MTAnalysisLoggerTest.class.st b/src/MuTalk-Tests/MTAnalysisLoggerTest.class.st index ea6e775..45219a3 100644 --- a/src/MuTalk-Tests/MTAnalysisLoggerTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisLoggerTest.class.st @@ -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 diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index aa0179b..1156260 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -74,7 +74,7 @@ MTAnalysisTest >> testCorrectNumberOfTestCasesWithParametrizedTestCase [ MTAnalysisTest >> testDefaultParameters [ | analysis | - analysis := MTAnalysis new. + analysis := MTAnalysis new testClasses: { }. self assert: (analysis operators collect: [ :op | op species ]) equals: @@ -85,7 +85,7 @@ MTAnalysisTest >> testDefaultParameters [ self assert: analysis testSelectionStrategy species equals: MTSelectingFromCoverageTestSelectionStrategy. - self assert: analysis budget species equals: MTFreeBudget + self assert: analysis defaultBudget species equals: MTTimeBudget ] { #category : 'testing' } @@ -99,7 +99,8 @@ MTAnalysisTest >> testExecutingInfiniteLoopAnalysis [ analysis := MTAnalysis new testClasses: { MTFakeInfiniteLoopsTest }; classesToMutate: { MTFakeInfiniteLoopForTest }; - operators: { MTReplaceLessOrEqualWithTrueOperator new }. + operators: { MTReplaceLessOrEqualWithTrueOperator new }; + budget: MTFreeBudget new. analysis run. @@ -121,7 +122,8 @@ MTAnalysisTest >> testExecutingInfiniteRecursionAnalysis [ testClasses: { MTFakeInfiniteLoopsTest }; classesToMutate: { MTFakeInfiniteLoopForTest }; operators: - { MTReplaceIfTrueReceiverWithFalseOperator new }. + { MTReplaceIfTrueReceiverWithFalseOperator new }; + budget: MTFreeBudget new. analysis run. @@ -137,11 +139,11 @@ MTAnalysisTest >> testExecutingSimpleMutation [ | analysis results generalResult mutationResult | analysis := MTAnalysis new testClasses: - (Array with: - MTAuxiliarClassForMTAnalysisTest); + (Array with: MTAuxiliarClassForMTAnalysisTest); classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: self plusForMinusReplacementMutation. + operators: self plusForMinusReplacementMutation; + budget: MTFreeBudget new. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -157,11 +159,11 @@ MTAnalysisTest >> testExecutingSimpleMutationForClassMethods [ | analysis results generalResult mutationResult | analysis := MTAnalysis new testClasses: - (Array with: - MTAuxiliarClassForMTAnalysisTest); + (Array with: MTAuxiliarClassForMTAnalysisTest); classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: self selectForRejectReplacementMutation. + operators: self selectForRejectReplacementMutation; + budget: MTFreeBudget new. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -177,11 +179,11 @@ MTAnalysisTest >> testExecutingSimpleMutationWhenNotRunnedAnalysis [ | analysis results generalResult | analysis := MTAnalysis new testClasses: - (Array with: - MTAuxiliarClassForMTAnalysisTest); + (Array with: MTAuxiliarClassForMTAnalysisTest); classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: self plusForMinusReplacementMutation. + operators: self plusForMinusReplacementMutation; + testFilter: MTFreeTestFilter new. "analysis run." generalResult := analysis generalResult. results := analysis mutantResults. @@ -200,7 +202,8 @@ MTAnalysisTest >> testExecutingTwoMutantsFromDiferentMethods [ testClasses: Array new; classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: operatorSelection. + operators: operatorSelection; + budget: MTFreeBudget new. analysis run. results := analysis mutantResults. self assert: results size equals: 2. @@ -218,7 +221,8 @@ MTAnalysisTest >> testExecutingTwoMutantsFromSameMethod [ testClasses: Array new; classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: operatorSelection. + operators: operatorSelection; + budget: MTFreeBudget new. analysis run. results := analysis mutantResults. self assert: results size equals: 2. @@ -236,11 +240,11 @@ MTAnalysisTest >> testExecutingTwoMutations [ operatorSelection addAll: self ifTrueForIfFalseReplacementMutation. analysis := MTAnalysis new testClasses: - (Array with: - MTAuxiliarClassForMTAnalysisTest); + (Array with: MTAuxiliarClassForMTAnalysisTest); classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); - operators: operatorSelection. + operators: operatorSelection; + budget: MTFreeBudget new. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -260,7 +264,8 @@ MTAnalysisTest >> testRunningAllTests [ classesToMutate: { MTAuxiliarClassForMTAnalysis }; testSelectionStrategy: MTAllTestsMethodsRunningTestSelectionStrategy new; - doNotStopOnErrorOrFail. + doNotStopOnErrorOrFail; + budget: MTFreeBudget new. "In this class, tests fail after a certain of executions" MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail reset. From 5e555477cd41d16b3df0e9ef95fe8c4a8d12199e Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 10 Apr 2024 16:55:38 +0200 Subject: [PATCH 06/16] add comment --- src/MuTalk-Model/MTAnalysis.class.st | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index 9a8da08..1355354 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -53,8 +53,9 @@ MTAnalysis >> coverageAnalysisResult: anObject [ { #category : 'accessing - defaults' } MTAnalysis >> defaultBudget [ + "Since tests often take little time to run, we multiply it by 30" - ^ MTTimeBudget for: self totalTestsTime * 30 + ^ MTTimeBudget for: self totalTestsTime * 30 ] { #category : 'accessing - defaults' } From ff4f2bb317ff64400ea7432b2cf7bf68c1758845 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Wed, 10 Apr 2024 17:03:56 +0200 Subject: [PATCH 07/16] fix tests with free budget --- .../MTCoveragePropagationPreparationTest.class.st | 3 ++- src/MuTalk-Utilities-Tests/MTMatrixTest.class.st | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MuTalk-CI-Tests/MTCoveragePropagationPreparationTest.class.st b/src/MuTalk-CI-Tests/MTCoveragePropagationPreparationTest.class.st index d808a57..b5f22b6 100644 --- a/src/MuTalk-CI-Tests/MTCoveragePropagationPreparationTest.class.st +++ b/src/MuTalk-CI-Tests/MTCoveragePropagationPreparationTest.class.st @@ -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 diff --git a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st index 0961595..2fa90dc 100644 --- a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st +++ b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st @@ -17,7 +17,9 @@ MTMatrixTest >> setUp [ super setUp. matrix := MTMatrix forClasses: { MTAuxiliarClassForMatrix }. matrix setUpAnalysis. - matrix analysis operators: MTAbstractMutantOperator contents. + matrix analysis + operators: MTAbstractMutantOperator contents; + budget: MTFreeBudget new. matrix build. self setUpVariablesForTest ] From c14a423a3c33a5e861cc4cf440be78d7f2efbaa4 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 12:14:49 +0200 Subject: [PATCH 08/16] removed original operators and the distinction between contents and contentsAll --- .../MTAbstractMutantOperator.class.st | 19 +------------------ src/MuTalk-Model/MTAnalysis.class.st | 2 +- .../MTPredicateBasedMutantOperator.class.st | 5 ----- .../MTMutantOperatorAnalysisTest.class.st | 4 ++-- .../MTMutantOperatorAnalysis.class.st | 5 ++--- .../MTNonMutatedMethodsAnalysis.class.st | 3 +-- 6 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/MuTalk-Model/MTAbstractMutantOperator.class.st b/src/MuTalk-Model/MTAbstractMutantOperator.class.st index 929259f..48df435 100644 --- a/src/MuTalk-Model/MTAbstractMutantOperator.class.st +++ b/src/MuTalk-Model/MTAbstractMutantOperator.class.st @@ -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' } @@ -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 [ diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index 1355354..b096049 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -73,7 +73,7 @@ MTAnalysis >> defaultMutantGenerationStrategy [ { #category : 'accessing - defaults' } MTAnalysis >> defaultOperators [ - ^ MTAbstractMutantOperator contentsAll + ^ MTAbstractMutantOperator contents ] { #category : 'accessing - defaults' } diff --git a/src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st b/src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st index 26a413c..4eafb90 100644 --- a/src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st +++ b/src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st @@ -12,11 +12,6 @@ MTPredicateBasedMutantOperator class >> isAbstract [ ^ self == MTPredicateBasedMutantOperator ] -{ #category : 'testing' } -MTPredicateBasedMutantOperator class >> isOriginalOperator [ - ^ false -] - { #category : 'private' } MTPredicateBasedMutantOperator >> affectedNodeFor: aParseTree at: nodeIndex [ diff --git a/src/MuTalk-Utilities-Tests/MTMutantOperatorAnalysisTest.class.st b/src/MuTalk-Utilities-Tests/MTMutantOperatorAnalysisTest.class.st index 1113d53..0f64d5b 100644 --- a/src/MuTalk-Utilities-Tests/MTMutantOperatorAnalysisTest.class.st +++ b/src/MuTalk-Utilities-Tests/MTMutantOperatorAnalysisTest.class.st @@ -22,7 +22,7 @@ MTMutantOperatorAnalysisTest >> testGetAllOperators [ | actual expected | actual := operatorAnalysis operatorsProducingAtLeast: 0. - expected := (MTAbstractMutantOperator contentsAll collect: #species) asSet. + expected := (MTAbstractMutantOperator contents collect: #species) asSet. self assert: actual equals: expected ] @@ -45,7 +45,7 @@ MTMutantOperatorAnalysisTest >> testOperatorsProducingUnder [ | actual expected | actual := operatorAnalysis operatorsProducingAtMost: 2. - expected := (MTAbstractMutantOperator contentsAll collect: #species) asSet + expected := (MTAbstractMutantOperator contents collect: #species) asSet reject: [ :operator | { MTLiteralIntegersIncreaseOperator. diff --git a/src/MuTalk-Utilities/MTMutantOperatorAnalysis.class.st b/src/MuTalk-Utilities/MTMutantOperatorAnalysis.class.st index d558bb0..9876023 100644 --- a/src/MuTalk-Utilities/MTMutantOperatorAnalysis.class.st +++ b/src/MuTalk-Utilities/MTMutantOperatorAnalysis.class.st @@ -44,8 +44,7 @@ MTMutantOperatorAnalysis >> operatorDictionaryFromAnalysis [ | analysis dic | analysis := MTAnalysis new classesToMutate: classes; - testClasses: { }; - operators: MTAbstractMutantOperator contentsAll. + testClasses: { }. analysis generateMutations. @@ -75,7 +74,7 @@ MTMutantOperatorAnalysis >> operatorsSelectedWith: aBlock [ MTMutantOperatorAnalysis >> operatorsWithoutMutantsFor: aDictionary [ | operatorsWithoutMutants | - operatorsWithoutMutants := (MTAbstractMutantOperator contentsAll collect: + operatorsWithoutMutants := (MTAbstractMutantOperator contents collect: #species) reject: [ :ope | aDictionary keys includes: ope ]. diff --git a/src/MuTalk-Utilities/MTNonMutatedMethodsAnalysis.class.st b/src/MuTalk-Utilities/MTNonMutatedMethodsAnalysis.class.st index 5a00359..886ac4b 100644 --- a/src/MuTalk-Utilities/MTNonMutatedMethodsAnalysis.class.st +++ b/src/MuTalk-Utilities/MTNonMutatedMethodsAnalysis.class.st @@ -29,8 +29,7 @@ MTNonMutatedMethodsAnalysis >> mutatedMethods [ | analysis mutatedMethods | analysis := MTAnalysis new classesToMutate: classes; - testClasses: { }; - operators: MTAbstractMutantOperator contentsAll. + testClasses: { }. mutatedMethods := Set withAll: (analysis generateMutations collect: From 4f2619e1f6b8c647f31b5589e01ab589e12a715a Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 12:16:48 +0200 Subject: [PATCH 09/16] changed references to contentsAll to contents, or simply removed them if not necessary --- src/MuTalk-Tests/MTAnalysisTest.class.st | 2 +- .../MTRandomClassMutantSelectionStrategyTest.class.st | 3 +-- .../MTRandomMethodMutantSelectionStrategyTest.class.st | 3 +-- .../MTRandomOperatorMutantSelectionStrategyTest.class.st | 3 +-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index 1156260..8364899 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -78,7 +78,7 @@ MTAnalysisTest >> testDefaultParameters [ self assert: (analysis operators collect: [ :op | op species ]) equals: - (MTAbstractMutantOperator contentsAll collect: [ :op | op species ]). + (MTAbstractMutantOperator contents collect: [ :op | op species ]). self assert: analysis mutantGenerationStrategy species equals: MTAllMutantGenerationStrategy. diff --git a/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st index 9c9a332..cf8e701 100644 --- a/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st @@ -25,8 +25,7 @@ MTRandomClassMutantSelectionStrategyTest >> testAround33PercentOfMutantsForEachC MTAuxiliarClassForRandomClassMutantSelectionStrategy1. MTAuxiliarClassForRandomClassMutantSelectionStrategy2. MTAuxiliarClassForRandomClassMutantSelectionStrategy3 }; - testClasses: { }; - operators: MTAbstractMutantOperator contentsAll. + testClasses: { }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomClassMutantSelectionStrategy withSeed: seed). diff --git a/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st index 6c775b2..5f2de0e 100644 --- a/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st @@ -24,8 +24,7 @@ MTRandomMethodMutantSelectionStrategyTest >> testAround25PercentOfMutantsForEach analysis := MTAnalysis new classesToMutate: { MTAuxiliarClassForRandomMethodMutantSelectionStrategy }; - testClasses: { }; - operators: MTAbstractMutantOperator contentsAll. + testClasses: { }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomMethodMutantSelectionStrategy withSeed: seed). diff --git a/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st index fce5b08..fb470ab 100644 --- a/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st @@ -22,8 +22,7 @@ MTRandomOperatorMutantSelectionStrategyTest >> testAroundOneSeventhPercentOfMuta analysis := MTAnalysis new classesToMutate: { MTAuxiliarClassForRandomOperatorMutantSelectionStrategy }; - testClasses: { }; - operators: MTAbstractMutantOperator contentsAll. + testClasses: { }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomOperatorMutantSelectionStrategy withSeed: seed). From e14cffd6ae8071a6d47506537d675d265b4a630a Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 14:33:47 +0200 Subject: [PATCH 10/16] adapt tests to the higher number of mutants --- src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st | 4 ++-- src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st b/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st index dd0d9ea..7d7b411 100644 --- a/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st +++ b/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st @@ -14,10 +14,10 @@ MTFixedNumberOfMutantsBudgetTest >> runAnalysisForFixedNumberOfMutants: aNumber { #category : 'tests' } MTFixedNumberOfMutantsBudgetTest >> testEvaluateAllMutantsWithConstraintGreaterThanActualNumberOfMutations [ - self runAnalysisForFixedNumberOfMutants: 50. + self runAnalysisForFixedNumberOfMutants: 100. self assert: analysis generalResult numberOfEvaluatedMutants - equals: 25 + equals: 96 ] { #category : 'tests' } diff --git a/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st b/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st index 77ea5f8..d267406 100644 --- a/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st +++ b/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st @@ -45,8 +45,8 @@ MTPercentageOfMutantsBudgetTest >> testEvaluateZeroPercentOfMutantsWithZeroPerce { #category : 'tests' } MTPercentageOfMutantsBudgetTest >> testExactPercentageOfMutants [ - self runAnalysisForPercentageOfMutants: 20. - self assert: self percentageOfEvaluatedMutants equals: 20 + self runAnalysisForPercentageOfMutants: 25. + self assert: self percentageOfEvaluatedMutants equals: 25 ] { #category : 'tests' } @@ -56,5 +56,5 @@ MTPercentageOfMutantsBudgetTest >> testNonExactPercentageOfMutants [ self assert: self percentageOfEvaluatedMutants >= 21. self assert: analysis generalResult numberOfEvaluatedMutants - equals: 6 + equals: 21 ] From 98655b737c54503fa2eda362e33df29bf3f8df75 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 14:40:31 +0200 Subject: [PATCH 11/16] fix utilities tests --- src/MuTalk-Utilities-Tests/MTMatrixTest.class.st | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st index 2fa90dc..dfb2312 100644 --- a/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st +++ b/src/MuTalk-Utilities-Tests/MTMatrixTest.class.st @@ -18,7 +18,9 @@ MTMatrixTest >> setUp [ matrix := MTMatrix forClasses: { MTAuxiliarClassForMatrix }. matrix setUpAnalysis. matrix analysis - operators: MTAbstractMutantOperator contents; + operators: + (MTParseRewriterMutantOperator allConcreteSubclasses collect: [ + :operator | operator new ]); budget: MTFreeBudget new. matrix build. self setUpVariablesForTest From 55d8d5bc0f04202cdda0a19912b50c11c9c3deba Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 14:52:23 +0200 Subject: [PATCH 12/16] revert operators to fix budget tests --- src/MuTalk-Tests/MTBudgetTest.class.st | 4 +++- src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st | 4 ++-- src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/MuTalk-Tests/MTBudgetTest.class.st b/src/MuTalk-Tests/MTBudgetTest.class.st index fbfa2e0..10212b4 100644 --- a/src/MuTalk-Tests/MTBudgetTest.class.st +++ b/src/MuTalk-Tests/MTBudgetTest.class.st @@ -30,7 +30,9 @@ MTBudgetTest >> runAnalysisWithBudget: aBudget on: classesToMutate withTests: te testClasses: testCases; classesToMutate: classesToMutate; budget: aBudget; - operators: MTAbstractMutantOperator contents. + operators: + (MTParseRewriterMutantOperator allConcreteSubclasses + collect: [ :operator | operator new ]). analysis run. ^ analysis generalResult diff --git a/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st b/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st index 7d7b411..dd0d9ea 100644 --- a/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st +++ b/src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st @@ -14,10 +14,10 @@ MTFixedNumberOfMutantsBudgetTest >> runAnalysisForFixedNumberOfMutants: aNumber { #category : 'tests' } MTFixedNumberOfMutantsBudgetTest >> testEvaluateAllMutantsWithConstraintGreaterThanActualNumberOfMutations [ - self runAnalysisForFixedNumberOfMutants: 100. + self runAnalysisForFixedNumberOfMutants: 50. self assert: analysis generalResult numberOfEvaluatedMutants - equals: 96 + equals: 25 ] { #category : 'tests' } diff --git a/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st b/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st index d267406..77ea5f8 100644 --- a/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st +++ b/src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st @@ -45,8 +45,8 @@ MTPercentageOfMutantsBudgetTest >> testEvaluateZeroPercentOfMutantsWithZeroPerce { #category : 'tests' } MTPercentageOfMutantsBudgetTest >> testExactPercentageOfMutants [ - self runAnalysisForPercentageOfMutants: 25. - self assert: self percentageOfEvaluatedMutants equals: 25 + self runAnalysisForPercentageOfMutants: 20. + self assert: self percentageOfEvaluatedMutants equals: 20 ] { #category : 'tests' } @@ -56,5 +56,5 @@ MTPercentageOfMutantsBudgetTest >> testNonExactPercentageOfMutants [ self assert: self percentageOfEvaluatedMutants >= 21. self assert: analysis generalResult numberOfEvaluatedMutants - equals: 21 + equals: 6 ] From efa3d6abc8a569996b1bf92235faa65758099ba4 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 17:43:24 +0200 Subject: [PATCH 13/16] refactor default budget and test filter --- src/MuTalk-Model/MTAnalysis.class.st | 48 ++++++++++++++----- src/MuTalk-Tests/MTAnalysisTest.class.st | 26 +++++----- .../MTFakeInfiniteLoopForTest.class.st | 6 +-- src/MuTalk-Tests/MTFileLoggerTest.class.st | 3 +- ...mClassMutantSelectionStrategyTest.class.st | 2 +- ...MethodMutantSelectionStrategyTest.class.st | 2 +- ...eratorMutantSelectionStrategyTest.class.st | 2 +- src/MuTalk-Tests/MTTestFilterTest.class.st | 3 +- 8 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index b096049..d4ff6a4 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -79,12 +79,14 @@ MTAnalysis >> defaultOperators [ { #category : 'accessing - defaults' } MTAnalysis >> defaultTestFilter [ + | 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: (testCases collect: #lastTimeToRun) sorted)) } + (MTTimeTestFilter for: (self percentile: 90 for: times sorted)) } ] { #category : 'accessing - defaults' } @@ -157,7 +159,9 @@ MTAnalysis >> initialTestRun [ | results | results := testCases collect: [ :aTestCase | aTestCase run ]. - testFilter ifNil: [ testFilter := self defaultTestFilter ]. + + "The test filter is initialized here because the default one needs the run time of tests, so the initial test run must be executed first" + self initializeTestFilter. testFilter validateFailuresIn: results. testCases := testFilter filterTests: testCases ] @@ -175,6 +179,12 @@ MTAnalysis >> initialize [ stopOnErrorOrFail := true ] +{ #category : 'initialization' } +MTAnalysis >> initializeTestFilter [ + + testFilter ifNil: [ testFilter := self defaultTestFilter ] +] + { #category : 'accessing' } MTAnalysis >> logger [ @@ -228,6 +238,13 @@ MTAnalysis >> mutations: anObject [ mutations := anObject ] +{ #category : 'initialization' } +MTAnalysis >> noLimitations [ + + budget := MTFreeBudget new. + testFilter := MTFreeTestFilter new +] + { #category : 'accessing' } MTAnalysis >> operators [ @@ -282,6 +299,7 @@ MTAnalysis >> run [ { #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 @@ -314,12 +332,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' } @@ -373,7 +396,8 @@ MTAnalysis >> testSelectionStrategy: anObject [ MTAnalysis >> totalTestsTime [ | times | - testCases isEmpty ifTrue: [ ^ 0 milliSecond ]. 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 ] ] diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index 8364899..91f8027 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -74,7 +74,9 @@ MTAnalysisTest >> testCorrectNumberOfTestCasesWithParametrizedTestCase [ MTAnalysisTest >> testDefaultParameters [ | analysis | - analysis := MTAnalysis new testClasses: { }. + analysis := MTAnalysis new testClasses: + { MTAuxiliarClassForMTAnalysisTest }. + analysis initialTestRun. self assert: (analysis operators collect: [ :op | op species ]) equals: @@ -100,7 +102,7 @@ MTAnalysisTest >> testExecutingInfiniteLoopAnalysis [ testClasses: { MTFakeInfiniteLoopsTest }; classesToMutate: { MTFakeInfiniteLoopForTest }; operators: { MTReplaceLessOrEqualWithTrueOperator new }; - budget: MTFreeBudget new. + noLimitations. analysis run. @@ -123,7 +125,7 @@ MTAnalysisTest >> testExecutingInfiniteRecursionAnalysis [ classesToMutate: { MTFakeInfiniteLoopForTest }; operators: { MTReplaceIfTrueReceiverWithFalseOperator new }; - budget: MTFreeBudget new. + noLimitations. analysis run. @@ -143,7 +145,7 @@ MTAnalysisTest >> testExecutingSimpleMutation [ classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: self plusForMinusReplacementMutation; - budget: MTFreeBudget new. + noLimitations. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -163,7 +165,7 @@ MTAnalysisTest >> testExecutingSimpleMutationForClassMethods [ classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: self selectForRejectReplacementMutation; - budget: MTFreeBudget new. + noLimitations. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -183,7 +185,7 @@ MTAnalysisTest >> testExecutingSimpleMutationWhenNotRunnedAnalysis [ classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: self plusForMinusReplacementMutation; - testFilter: MTFreeTestFilter new. + noLimitations. "analysis run." generalResult := analysis generalResult. results := analysis mutantResults. @@ -199,11 +201,11 @@ MTAnalysisTest >> testExecutingTwoMutantsFromDiferentMethods [ operatorSelection := OrderedCollection new. operatorSelection addAll: self ifFalseForIfTrueReplacementMutation. analysis := MTAnalysis new - testClasses: Array new; + testClasses: { MTAuxiliarTestClassForTestingStrategies }; classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: operatorSelection; - budget: MTFreeBudget new. + noLimitations. analysis run. results := analysis mutantResults. self assert: results size equals: 2. @@ -218,11 +220,11 @@ MTAnalysisTest >> testExecutingTwoMutantsFromSameMethod [ operatorSelection := OrderedCollection new. operatorSelection addAll: self minusForPlusReplacementMutation. analysis := MTAnalysis new - testClasses: Array new; + testClasses: { MTAuxiliarTestClassForTestingStrategies }; classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: operatorSelection; - budget: MTFreeBudget new. + noLimitations. analysis run. results := analysis mutantResults. self assert: results size equals: 2. @@ -244,7 +246,7 @@ MTAnalysisTest >> testExecutingTwoMutations [ classesToMutate: (Array with: MTAuxiliarClassForMTAnalysis); operators: operatorSelection; - budget: MTFreeBudget new. + noLimitations. analysis run. generalResult := analysis generalResult. results := analysis mutantResults. @@ -265,7 +267,7 @@ MTAnalysisTest >> testRunningAllTests [ testSelectionStrategy: MTAllTestsMethodsRunningTestSelectionStrategy new; doNotStopOnErrorOrFail; - budget: MTFreeBudget new. + noLimitations. "In this class, tests fail after a certain of executions" MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail reset. diff --git a/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st b/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st index 8bf71dc..ed133c6 100644 --- a/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st +++ b/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st @@ -5,17 +5,17 @@ Class { #package : 'MuTalk-Tests' } -{ #category : 'factorials' } +{ #category : 'not defined protocol' } MTFakeInfiniteLoopForTest >> iterativeFactorial: anInt [ | factorial i | ^ anInt = 1 ifTrue: [ 1 ] - ifFalse: [ + ifFalse: [ factorial := 1. i := 2. "Use a whileTrue: so a mutation can introduce an infinite loop here" - [ i <= anInt ] whileTrue: [ + [ true ] whileTrue: [ factorial := factorial * i. i := i + 1 ]. factorial ] diff --git a/src/MuTalk-Tests/MTFileLoggerTest.class.st b/src/MuTalk-Tests/MTFileLoggerTest.class.st index c6bb1a1..b16f241 100644 --- a/src/MuTalk-Tests/MTFileLoggerTest.class.st +++ b/src/MuTalk-Tests/MTFileLoggerTest.class.st @@ -14,7 +14,8 @@ MTFileLoggerTest >> testLogFileExists [ analysis := MTAnalysis new classesToMutate: { MTAuxiliarClassForMTAnalysis }; testClasses: { MTAuxiliarClassForMTAnalysisTest }; - logger: (MTFileLogger toFileNamed: logFileName). + logger: (MTFileLogger toFileNamed: logFileName); + budget: MTFreeBudget new. analysis run. diff --git a/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st index cf8e701..1397a95 100644 --- a/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomClassMutantSelectionStrategyTest.class.st @@ -25,7 +25,7 @@ MTRandomClassMutantSelectionStrategyTest >> testAround33PercentOfMutantsForEachC MTAuxiliarClassForRandomClassMutantSelectionStrategy1. MTAuxiliarClassForRandomClassMutantSelectionStrategy2. MTAuxiliarClassForRandomClassMutantSelectionStrategy3 }; - testClasses: { }. + testClasses: { MTAuxiliarClassForMTAnalysisTest }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomClassMutantSelectionStrategy withSeed: seed). diff --git a/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st index 5f2de0e..c15ab85 100644 --- a/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomMethodMutantSelectionStrategyTest.class.st @@ -24,7 +24,7 @@ MTRandomMethodMutantSelectionStrategyTest >> testAround25PercentOfMutantsForEach analysis := MTAnalysis new classesToMutate: { MTAuxiliarClassForRandomMethodMutantSelectionStrategy }; - testClasses: { }. + testClasses: { MTAuxiliarClassForMTAnalysisTest }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomMethodMutantSelectionStrategy withSeed: seed). diff --git a/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st b/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st index fb470ab..6e438d7 100644 --- a/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st +++ b/src/MuTalk-Tests/MTRandomOperatorMutantSelectionStrategyTest.class.st @@ -22,7 +22,7 @@ MTRandomOperatorMutantSelectionStrategyTest >> testAroundOneSeventhPercentOfMuta analysis := MTAnalysis new classesToMutate: { MTAuxiliarClassForRandomOperatorMutantSelectionStrategy }; - testClasses: { }. + testClasses: { MTAuxiliarClassForMTAnalysisTest }. analysis mutantGenerationStrategy mutantSelectionStrategy: (MTRandomOperatorMutantSelectionStrategy withSeed: seed). diff --git a/src/MuTalk-Tests/MTTestFilterTest.class.st b/src/MuTalk-Tests/MTTestFilterTest.class.st index b7e133d..8efe45d 100644 --- a/src/MuTalk-Tests/MTTestFilterTest.class.st +++ b/src/MuTalk-Tests/MTTestFilterTest.class.st @@ -20,7 +20,8 @@ MTTestFilterTest >> runAnalysisWithFilter: aTestFilter on: classesToMutate withT analysis := MTAnalysis new testClasses: testCases; classesToMutate: classesToMutate; - testFilter: aTestFilter. + testFilter: aTestFilter; + budget: MTFreeBudget new. analysis run ] From 148dbf2b09c10fdb25f6f392b45028dd50ca4c08 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 17:45:52 +0200 Subject: [PATCH 14/16] fix --- src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st b/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st index ed133c6..8bf71dc 100644 --- a/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st +++ b/src/MuTalk-Tests/MTFakeInfiniteLoopForTest.class.st @@ -5,17 +5,17 @@ Class { #package : 'MuTalk-Tests' } -{ #category : 'not defined protocol' } +{ #category : 'factorials' } MTFakeInfiniteLoopForTest >> iterativeFactorial: anInt [ | factorial i | ^ anInt = 1 ifTrue: [ 1 ] - ifFalse: [ + ifFalse: [ factorial := 1. i := 2. "Use a whileTrue: so a mutation can introduce an infinite loop here" - [ true ] whileTrue: [ + [ i <= anInt ] whileTrue: [ factorial := factorial * i. i := i + 1 ]. factorial ] From 937205baa81f5648c728cc39c07c7fe440683237 Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Mon, 15 Apr 2024 18:06:52 +0200 Subject: [PATCH 15/16] add tests for exceptions --- src/MuTalk-Model/MTAnalysis.class.st | 4 ++- src/MuTalk-Tests/MTAnalysisTest.class.st | 33 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index d4ff6a4..6493a33 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -268,7 +268,8 @@ MTAnalysis >> packagesToMutate: aCollectionOfPackages [ MTAnalysis >> percentile: aPercentage for: aCollection [ | size index | - aCollection isEmpty ifTrue: [ ^ nil ]. + aCollection isEmpty ifTrue: [ + ^ CollectionIsEmpty signalWith: aCollection ]. size := aCollection size. index := (aPercentage percent * size) rounded. ^ aCollection at: index @@ -283,6 +284,7 @@ MTAnalysis >> run [ ^ [ 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 := [ diff --git a/src/MuTalk-Tests/MTAnalysisTest.class.st b/src/MuTalk-Tests/MTAnalysisTest.class.st index 91f8027..486a923 100644 --- a/src/MuTalk-Tests/MTAnalysisTest.class.st +++ b/src/MuTalk-Tests/MTAnalysisTest.class.st @@ -90,6 +90,39 @@ MTAnalysisTest >> testDefaultParameters [ self assert: analysis defaultBudget species equals: MTTimeBudget ] +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenInitializingDefaultTestFilterBeforeInitialTestRun [ + + | analysis | + analysis := MTAnalysis new + classesToMutate: { MTAuxiliarClassForMTAnalysis }; + testClasses: { MTAuxiliarClassForMTAnalysisTest }. + + self should: [ analysis initializeTestFilter ] raise: Error +] + +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenStartingDefaultBudgetBeforeInitialTestRun [ + + | analysis | + analysis := MTAnalysis new + classesToMutate: { MTAuxiliarClassForMTAnalysis }; + testClasses: { MTAuxiliarClassForMTAnalysisTest }. + + self should: [ analysis startBudget ] raise: Error +] + +{ #category : 'tests' } +MTAnalysisTest >> testErrorWhenTryingToGetPercentileOfEmptyCollection [ + + | analysis | + analysis := MTAnalysis new. + + self + should: [ analysis percentile: 1 for: { } ] + raise: Error +] + { #category : 'testing' } MTAnalysisTest >> testExecutingInfiniteLoopAnalysis [ From fba74ed351216f1f647a10ab203ca96e1d32b9cf Mon Sep 17 00:00:00 2001 From: Durieux Pol Date: Tue, 16 Apr 2024 14:03:15 +0200 Subject: [PATCH 16/16] lazy initialization --- src/MuTalk-Model/MTAnalysis.class.st | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/MuTalk-Model/MTAnalysis.class.st b/src/MuTalk-Model/MTAnalysis.class.st index 6493a33..0378680 100644 --- a/src/MuTalk-Model/MTAnalysis.class.st +++ b/src/MuTalk-Model/MTAnalysis.class.st @@ -160,9 +160,8 @@ MTAnalysis >> initialTestRun [ | results | results := testCases collect: [ :aTestCase | aTestCase run ]. - "The test filter is initialized here because the default one needs the run time of tests, so the initial test run must be executed first" - self initializeTestFilter. - 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 ] @@ -179,12 +178,6 @@ MTAnalysis >> initialize [ stopOnErrorOrFail := true ] -{ #category : 'initialization' } -MTAnalysis >> initializeTestFilter [ - - testFilter ifNil: [ testFilter := self defaultTestFilter ] -] - { #category : 'accessing' } MTAnalysis >> logger [ @@ -363,7 +356,7 @@ MTAnalysis >> testClasses: aClassCollection [ { #category : 'accessing' } MTAnalysis >> testFilter [ - ^ testFilter + ^ testFilter ifNil: [ testFilter := self defaultTestFilter ] ] { #category : 'accessing' }