Skip to content

Commit

Permalink
rename runAnalysisFor: method
Browse files Browse the repository at this point in the history
  • Loading branch information
Durieux Pol committed Dec 15, 2023
1 parent def0e28 commit 025c068
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 56 deletions.
13 changes: 11 additions & 2 deletions src/MuTalk-Tests/MTBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ Class {
#package : 'MuTalk-Tests'
}

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

^ self == MTBudgetTest
]

{ #category : 'running' }
MTBudgetTest >> runAnalysisFor: aConstraint [
MTBudgetTest >> runAnalysisFor: aBudget [

^ self subclassResponsibility
^ self
runAnalysisWithBudget: aBudget
on: { AuxiliarClassForMutationTestingAnalysis }
withTests: { AuxiliarClassForMutationTestingAnalysisTest }
]

{ #category : 'running' }
Expand Down
17 changes: 7 additions & 10 deletions src/MuTalk-Tests/MTFixedNumberOfMutantsBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ Class {
#package : 'MuTalk-Tests'
}

{ #category : 'running' }
MTFixedNumberOfMutantsBudgetTest >> runAnalysisFor: aNumber [
{ #category : 'tests' }
MTFixedNumberOfMutantsBudgetTest >> runAnalysisForFixedNumberOfMutants: aNumber [

^ self
runAnalysisWithBudget: (MTFixedNumberOfMutantsBudget for: aNumber)
on: { AuxiliarClassForMutationTestingAnalysis }
withTests: { AuxiliarClassForMutationTestingAnalysisTest }
self runAnalysisFor: (MTFixedNumberOfMutantsBudget for: aNumber)
]

{ #category : 'tests' }
MTFixedNumberOfMutantsBudgetTest >> testEvaluateAllMutantsWithConstraintGreaterThanActualNumberOfMutations [

self runAnalysisFor: 50.
self runAnalysisForFixedNumberOfMutants: 50.
self
assert: analysis generalResult numberOfEvaluatedMutants
equals: 25
Expand All @@ -26,7 +23,7 @@ MTFixedNumberOfMutantsBudgetTest >> testEvaluateAllMutantsWithConstraintGreaterT
{ #category : 'tests' }
MTFixedNumberOfMutantsBudgetTest >> testEvaluateTheCorrectNumberOfMutants [

self runAnalysisFor: 10.
self runAnalysisForFixedNumberOfMutants: 10.
self
assert: analysis generalResult numberOfEvaluatedMutants
equals: 10
Expand All @@ -35,7 +32,7 @@ MTFixedNumberOfMutantsBudgetTest >> testEvaluateTheCorrectNumberOfMutants [
{ #category : 'tests' }
MTFixedNumberOfMutantsBudgetTest >> testEvaluateZeroMutantsWithConstraintOfZero [

self runAnalysisFor: 0.
self runAnalysisForFixedNumberOfMutants: 0.
self
assert: analysis generalResult numberOfEvaluatedMutants
equals: 0
Expand All @@ -44,7 +41,7 @@ MTFixedNumberOfMutantsBudgetTest >> testEvaluateZeroMutantsWithConstraintOfZero
{ #category : 'tests' }
MTFixedNumberOfMutantsBudgetTest >> testEvaluateZeroMutantsWithNegativeConstraint [

self runAnalysisFor: -10.
self runAnalysisForFixedNumberOfMutants: -10.
self
assert: analysis generalResult numberOfEvaluatedMutants
equals: 0
Expand Down
53 changes: 20 additions & 33 deletions src/MuTalk-Tests/MTPercentageOfMutantsBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,52 @@ Class {
#package : 'MuTalk-Tests'
}

{ #category : 'running' }
MTPercentageOfMutantsBudgetTest >> runAnalysisFor: aPercentage [
{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> percentageOfEvaluatedMutants [

^ analysis generalResult numberOfEvaluatedMutants
/ analysis mutations size * 100
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> runAnalysisForPercentageOfMutants: aPercentage [

| result |
result := self
runAnalysisWithBudget:
(MTPercentageOfMutantsBudget for: aPercentage)
on: { AuxiliarClassForMutationTestingAnalysis }
withTests: { AuxiliarClassForMutationTestingAnalysisTest }.
numberOfMutations := analysis mutations size.
^ result
self runAnalysisFor: (MTPercentageOfMutantsBudget for: aPercentage)
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> testEvaluateAllMutantsWithMoreThanOneHundredPercentConstraint [

self runAnalysisFor: 120.
self
assert:
analysis generalResult numberOfEvaluatedMutants / numberOfMutations * 100
equals: 100
self runAnalysisForPercentageOfMutants: 120.
self assert: self percentageOfEvaluatedMutants equals: 100
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> testEvaluateZeroPercentOfMutantsWithNegativePercentConstraint [

self runAnalysisFor: -10.
self
assert:
analysis generalResult numberOfEvaluatedMutants / numberOfMutations * 100
equals: 0
self runAnalysisForPercentageOfMutants: -10.
self assert: self percentageOfEvaluatedMutants equals: 0
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> testEvaluateZeroPercentOfMutantsWithZeroPercentConstraint [

self runAnalysisFor: 0.
self
assert:
analysis generalResult numberOfEvaluatedMutants / numberOfMutations * 100
equals: 0
self runAnalysisForPercentageOfMutants: 0.
self assert: self percentageOfEvaluatedMutants equals: 0
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> testExactPercentageOfMutants [

self runAnalysisFor: 20.
self
assert:
analysis generalResult numberOfEvaluatedMutants / numberOfMutations * 100
equals: 20
self runAnalysisForPercentageOfMutants: 20.
self assert: self percentageOfEvaluatedMutants equals: 20
]

{ #category : 'tests' }
MTPercentageOfMutantsBudgetTest >> testNonExactPercentageOfMutants [

self runAnalysisFor: 21.
self assert:
analysis generalResult numberOfEvaluatedMutants / numberOfMutations * 100 >= 21.
self runAnalysisForPercentageOfMutants: 21.
self assert: self percentageOfEvaluatedMutants >= 21.
self
assert: analysis generalResult numberOfEvaluatedMutants
equals: 6
Expand Down
20 changes: 9 additions & 11 deletions src/MuTalk-Tests/MTTimeBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ Class {
{ #category : 'running' }
MTTimeBudgetTest >> fixedAnalysisTime [

^ [ self runAnalysisFor: 0 seconds ] timeToRun
^ [ self runAnalysisFor: (MTTimeBudget for: 0 seconds) ] timeToRun
]

{ #category : 'running' }
MTTimeBudgetTest >> runAnalysisFor: aDuration [
{ #category : 'tests' }
MTTimeBudgetTest >> runAnalysisForDuration: aDuration [

^ self
runAnalysisWithBudget: (MTTimeBudget for: aDuration)
on: { AuxiliarClassForMTBudget }
withTests: { AuxiliarTestClassForMTBudget }
^ self runAnalysisFor: (MTTimeBudget for: aDuration)
]

{ #category : 'running' }
Expand Down Expand Up @@ -45,7 +42,7 @@ MTTimeBudgetTest >> testWithNoTimeForMutantsRespectsDeadline [
"Let's run the analysis for so much time that it will run the fixed cost (initial test run, coverage analysis) * N, making sure we will execute some mutants"
fixedAnalysisTime := self fixedAnalysisTime.
duration := fixedAnalysisTime / 4.
analysisTime := [ self runAnalysisFor: duration ] timeToRun.
analysisTime := [ self runAnalysisForDuration: duration ] timeToRun.

"The analysis will always take at least the fixed time and not less"
error := 0.2 seconds.
Expand All @@ -58,7 +55,8 @@ MTTimeBudgetTest >> testWithNoTimeForMutantsRunsNoMutants [
| duration analysisTime result |
"Divide duration by 4 to make sure we never have time for mutants"
duration := self fixedAnalysisTime / 4.
analysisTime := [ result := self runAnalysisFor: duration ] timeToRun.
analysisTime := [ result := self runAnalysisForDuration: duration ]
timeToRun.

"We never treat mutants because the budget was exceeded running the initial test run, coverage analysis, etc"
self assert: result numberOfEvaluatedMutants equals: 0
Expand All @@ -70,7 +68,7 @@ MTTimeBudgetTest >> testWithTimeForMutantsRespectsDeadline [
| duration analysisTime error |
"Let's run the analysis for so much time that it will run the fixed cost (initial test run, coverage analysis) * N, making sure we will execute some mutants"
duration := self fixedAnalysisTime * 4.
analysisTime := [ self runAnalysisFor: duration ] timeToRun.
analysisTime := [ self runAnalysisForDuration: duration ] timeToRun.

"Check if the analysis stopped after duration within the error"
error := 0.2 seconds.
Expand All @@ -83,7 +81,7 @@ MTTimeBudgetTest >> testWithTimeForMutantsRunsManyMutants [
| duration analysisTime result |
"Let's run the analysis for so much time that it will run the fixed cost (initial test run, coverage analysis) * N, making sure we will execute some mutants"
duration := self fixedAnalysisTime * 4.
analysisTime := [ result := self runAnalysisFor: duration ] timeToRun.
analysisTime := [ result := self runAnalysisForDuration: duration ] timeToRun.

"We expect that in the time we gave for the analysis we should have done more than one mutant"
self assert: result numberOfEvaluatedMutants > 1
Expand Down

0 comments on commit 025c068

Please sign in to comment.