Skip to content

Commit 639f4c6

Browse files
authored
Merge pull request #110 from DurieuxPol/enh/betterDefaults
Changed default values of analysis
2 parents 5e7978b + fba74ed commit 639f4c6

18 files changed

+172
-84
lines changed

src/MuTalk-CI-Tests/MTCoveragePropagationPreparationTest.class.st

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ MTCoveragePropagationPreparationTest >> testWorking [
1414
| analysis moreInfo mutant |
1515
analysis := MTAnalysis new
1616
testClasses: { MTCIHelperTest };
17-
classesToMutate: { MTCIHelper }.
17+
classesToMutate: { MTCIHelper };
18+
budget: MTFreeBudget new.
1819
analysis run.
1920

2021
moreInfo := MTCoveragePropagationPreparation new

src/MuTalk-Model/MTAbstractMutantOperator.class.st

+1-18
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Class {
99
{ #category : 'accessing' }
1010
MTAbstractMutantOperator class >> allConcreteSubclasses [
1111

12-
^ self allSubclasses reject: [ :ea |
13-
ea isAbstract | ea isOriginalOperator not ]
12+
^ self allSubclasses reject: #isAbstract
1413
]
1514

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

25-
{ #category : 'accessing' }
26-
MTAbstractMutantOperator class >> contentsAll [
27-
"This returns all operators (block based and traditional) "
28-
29-
^ ((self allSubclasses reject: [ :ea |
30-
ea isAbstract or: [ ea isDeprecated ] ]) collect: [ :class |
31-
class new ]) asSortedCollection: [ :elem1 :elem2 |
32-
elem1 description <= elem2 description ]
33-
]
34-
3524
{ #category : 'testing' }
3625
MTAbstractMutantOperator class >> isAbstract [
3726

3827
^ self == MTAbstractMutantOperator
3928
]
4029

41-
{ #category : 'testing' }
42-
MTAbstractMutantOperator class >> isOriginalOperator [
43-
44-
^ true
45-
]
46-
4730
{ #category : 'as yet unclassified' }
4831
MTAbstractMutantOperator class >> recursionsDetectionStatement [
4932

src/MuTalk-Model/MTAnalysis.class.st

+66-16
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,21 @@ MTAnalysis >> coverageAnalysisResult: anObject [
5353

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

57-
^ MTFreeBudget new
58+
^ MTTimeBudget for: self totalTestsTime * 30
5859
]
5960

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

63-
^ MTNullLogger new
64+
^ MTTranscriptLogger new
6465
]
6566

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

69-
^ MTAllMutantGenerationStrategy new
70+
^ MTAllMutantGenerationStrategy withRandomOperatorMutantSelection
7071
]
7172

7273
{ #category : 'accessing - defaults' }
@@ -78,13 +79,20 @@ MTAnalysis >> defaultOperators [
7879
{ #category : 'accessing - defaults' }
7980
MTAnalysis >> defaultTestFilter [
8081

81-
^ MTFreeTestFilter new
82+
| times |
83+
times := testCases collect: #lastTimeToRun.
84+
(times anySatisfy: #isNil) ifTrue: [
85+
^ Error signal:
86+
'Either there is no test cases, or the initial test run has not been executed yet' ].
87+
^ MTCompositeTestFilter for: {
88+
MTRedTestFilter new.
89+
(MTTimeTestFilter for: (self percentile: 90 for: times sorted)) }
8290
]
8391

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

87-
^ MTAllTestsMethodsRunningTestSelectionStrategy new
95+
^ MTSelectingFromCoverageTestSelectionStrategy new
8896
]
8997

9098
{ #category : 'accessing' }
@@ -151,7 +159,9 @@ MTAnalysis >> initialTestRun [
151159

152160
| results |
153161
results := testCases collect: [ :aTestCase | aTestCase run ].
154-
testFilter validateFailuresIn: results.
162+
163+
"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"
164+
self testFilter validateFailuresIn: results.
155165
testCases := testFilter filterTests: testCases
156166
]
157167

@@ -165,8 +175,6 @@ MTAnalysis >> initialize [
165175
mutantResults := OrderedCollection new.
166176
elapsedTime := 0.
167177
logger := self defaultLogger.
168-
budget := self defaultBudget.
169-
testFilter := self defaultTestFilter.
170178
stopOnErrorOrFail := true
171179
]
172180

@@ -223,6 +231,13 @@ MTAnalysis >> mutations: anObject [
223231
mutations := anObject
224232
]
225233

234+
{ #category : 'initialization' }
235+
MTAnalysis >> noLimitations [
236+
237+
budget := MTFreeBudget new.
238+
testFilter := MTFreeTestFilter new
239+
]
240+
226241
{ #category : 'accessing' }
227242
MTAnalysis >> operators [
228243

@@ -242,6 +257,17 @@ MTAnalysis >> packagesToMutate: aCollectionOfPackages [
242257
packageName asPackage definedClasses ]
243258
]
244259

260+
{ #category : 'computing' }
261+
MTAnalysis >> percentile: aPercentage for: aCollection [
262+
263+
| size index |
264+
aCollection isEmpty ifTrue: [
265+
^ CollectionIsEmpty signalWith: aCollection ].
266+
size := aCollection size.
267+
index := (aPercentage percent * size) rounded.
268+
^ aCollection at: index
269+
]
270+
245271
{ #category : 'running' }
246272
MTAnalysis >> run [
247273
"Obtain mutants applying the operators in the classes (or
@@ -250,8 +276,9 @@ MTAnalysis >> run [
250276
We obtain a result for each mutant generated"
251277

252278
^ [
253-
budget start.
254279
self initialTestRun.
280+
"The budget is started after the initial test run because the default one needs the run time of tests"
281+
self startBudget.
255282
logger logAnalysisStartFor: self.
256283
elapsedTime := [
257284
self generateCoverageAnalysis.
@@ -265,6 +292,14 @@ MTAnalysis >> run [
265292
false ]
266293
]
267294

295+
{ #category : 'starting' }
296+
MTAnalysis >> startBudget [
297+
"The budget is initialized here because the default one needs the run time of tests, so the initial test run must be executed first"
298+
299+
budget ifNil: [ budget := self defaultBudget ].
300+
budget start
301+
]
302+
268303
{ #category : 'accessing' }
269304
MTAnalysis >> stopOnErrorOrFail: aBoolean [
270305

@@ -292,12 +327,17 @@ MTAnalysis >> testCases: anObject [
292327
{ #category : 'accessing' }
293328
MTAnalysis >> testCasesFrom: aClassCollection [
294329

295-
^ aClassCollection
296-
inject: OrderedCollection new
297-
into: [ :testCase :testClass |
298-
testClass isAbstract ifFalse: [
299-
testCase addAll: (self testCasesReferencesFrom: testClass) ].
300-
testCase ]
330+
| tests |
331+
tests := aClassCollection
332+
inject: OrderedCollection new
333+
into: [ :testCase :testClass |
334+
testClass isAbstract ifFalse: [
335+
testCase addAll:
336+
(self testCasesReferencesFrom: testClass) ].
337+
testCase ].
338+
tests isEmpty ifTrue: [
339+
Warning signal: 'There is currently no tests' ].
340+
^ tests
301341
]
302342

303343
{ #category : 'tests' }
@@ -316,7 +356,7 @@ MTAnalysis >> testClasses: aClassCollection [
316356
{ #category : 'accessing' }
317357
MTAnalysis >> testFilter [
318358

319-
^ testFilter
359+
^ testFilter ifNil: [ testFilter := self defaultTestFilter ]
320360
]
321361

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

347387
testSelectionStrategy := anObject
348388
]
389+
390+
{ #category : 'accessing' }
391+
MTAnalysis >> totalTestsTime [
392+
393+
| times |
394+
times := testCases collect: #lastTimeToRun.
395+
(times anySatisfy: #isNil) ifTrue: [
396+
^ Error signal: 'The initial test run has not been executed yet' ].
397+
^ times reduce: [ :t1 :t2 | t1 + t2 ]
398+
]

src/MuTalk-Model/MTPredicateBasedMutantOperator.class.st

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ MTPredicateBasedMutantOperator class >> isAbstract [
1212
^ self == MTPredicateBasedMutantOperator
1313
]
1414

15-
{ #category : 'testing' }
16-
MTPredicateBasedMutantOperator class >> isOriginalOperator [
17-
^ false
18-
]
19-
2015
{ #category : 'private' }
2116
MTPredicateBasedMutantOperator >> affectedNodeFor: aParseTree at: nodeIndex [
2217

src/MuTalk-Tests/MTAnalysisLoggerTest.class.st

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ MTAnalysisLoggerTest >> testExecutingSimpleMutation [
1717
classesToMutate:
1818
(Array with: MTAuxiliarClassForMTAnalysis);
1919
operators: (Array with: operator);
20-
logger: logger.
20+
logger: logger;
21+
budget: MTFreeBudget new.
2122
analysis run.
2223
self assert: logger loggedStartAnalysis.
2324
self assert: (logger

0 commit comments

Comments
 (0)