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

Changed default values of analysis #110

Merged
merged 17 commits into from
Apr 16, 2024
Merged
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
49 changes: 40 additions & 9 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,44 @@ 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' }
MTAnalysis >> defaultOperators [

^ MTAbstractMutantOperator contents
^ MTAbstractMutantOperator contentsAll
]

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

^ MTFreeTestFilter new
^ MTCompositeTestFilter for: {
MTRedTestFilter new.
(MTTimeTestFilter for:
(self
percentile: 90
for: (testCases collect: #lastTimeToRun) sorted)) }
]

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

^ MTAllTestsMethodsRunningTestSelectionStrategy new
^ MTSelectingFromCoverageTestSelectionStrategy new
]

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

| results |
results := testCases collect: [ :aTestCase | aTestCase run ].
testFilter ifNil: [ testFilter := self defaultTestFilter ].
testFilter validateFailuresIn: results.
testCases := testFilter filterTests: testCases
]
Expand All @@ -165,8 +172,6 @@ MTAnalysis >> initialize [
mutantResults := OrderedCollection new.
elapsedTime := 0.
logger := self defaultLogger.
budget := self defaultBudget.
testFilter := self defaultTestFilter.
stopOnErrorOrFail := true
]

Expand Down Expand Up @@ -242,6 +247,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
Expand All @@ -250,8 +265,8 @@ MTAnalysis >> run [
We obtain a result for each mutant generated"

^ [
budget start.
self initialTestRun.
self startBudget.
logger logAnalysisStartFor: self.
elapsedTime := [
self generateCoverageAnalysis.
Expand All @@ -265,6 +280,13 @@ MTAnalysis >> run [
false ]
]

{ #category : 'starting' }
MTAnalysis >> startBudget [

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

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

Expand Down Expand Up @@ -346,3 +368,12 @@ MTAnalysis >> testSelectionStrategy: anObject [

testSelectionStrategy := anObject
]

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

| times |
testCases isEmpty ifTrue: [ ^ 0 milliSecond ].
times := testCases collect: #lastTimeToRun.
^ times reduce: [ :t1 :t2 | t1 + t2 ]
]
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
50 changes: 29 additions & 21 deletions src/MuTalk-Tests/MTAnalysisTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,18 @@ MTAnalysisTest >> testCorrectNumberOfTestCasesWithParametrizedTestCase [
MTAnalysisTest >> testDefaultParameters [

| analysis |
analysis := MTAnalysis new.
analysis := MTAnalysis new testClasses: { }.
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.
self assert: analysis budget species equals: MTFreeBudget
equals: MTSelectingFromCoverageTestSelectionStrategy.
self assert: analysis defaultBudget species equals: MTTimeBudget
]

{ #category : 'testing' }
Expand All @@ -98,7 +99,8 @@ MTAnalysisTest >> testExecutingInfiniteLoopAnalysis [
analysis := MTAnalysis new
testClasses: { MTFakeInfiniteLoopsTest };
classesToMutate: { MTFakeInfiniteLoopForTest };
operators: { MTReplaceLessOrEqualWithTrueOperator new }.
operators: { MTReplaceLessOrEqualWithTrueOperator new };
budget: MTFreeBudget new.

analysis run.

Expand All @@ -120,7 +122,8 @@ MTAnalysisTest >> testExecutingInfiniteRecursionAnalysis [
testClasses: { MTFakeInfiniteLoopsTest };
classesToMutate: { MTFakeInfiniteLoopForTest };
operators:
{ MTReplaceIfTrueReceiverWithFalseOperator new }.
{ MTReplaceIfTrueReceiverWithFalseOperator new };
budget: MTFreeBudget new.

analysis run.

Expand All @@ -136,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.
Expand All @@ -156,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.
Expand All @@ -176,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.
Expand All @@ -199,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.
Expand All @@ -217,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.
Expand All @@ -235,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.
Expand All @@ -257,7 +262,10 @@ MTAnalysisTest >> testRunningAllTests [
testClasses:
{ MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail };
classesToMutate: { MTAuxiliarClassForMTAnalysis };
doNotStopOnErrorOrFail.
testSelectionStrategy:
MTAllTestsMethodsRunningTestSelectionStrategy new;
doNotStopOnErrorOrFail;
budget: MTFreeBudget new.

"In this class, tests fail after a certain of executions"
MTAuxiliarTestClassForContinuingTestsExecutionAfterFirstFail reset.
Expand Down
3 changes: 2 additions & 1 deletion src/MuTalk-Tests/MTBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/MuTalk-Tests/MTTimeBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 4 additions & 0 deletions src/MuTalk-Utilities-Tests/MTMatrixTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ MTMatrixTest >> setUp [

super setUp.
matrix := MTMatrix forClasses: { MTAuxiliarClassForMatrix }.
matrix setUpAnalysis.
matrix analysis
operators: MTAbstractMutantOperator contents;
budget: MTFreeBudget new.
matrix build.
self setUpVariablesForTest
]
Expand Down
14 changes: 10 additions & 4 deletions src/MuTalk-Utilities/MTMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
Loading