Skip to content

Commit 0288626

Browse files
authored
Merge pull request #121 from DurieuxPol/other/chapter
Example for the MuTalk chapter and small changes
2 parents 2f218fd + f48ac84 commit 0288626

9 files changed

+172
-11
lines changed

src/BaselineOfMuTalk/BaselineOfMuTalk.class.st

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@ Class {
77

88
{ #category : 'baselines' }
99
BaselineOfMuTalk >> baseline: spec [
10-
<baseline>
1110

11+
<baseline>
1212
spec for: #common do: [
1313
spec
14-
package: 'TestCoverage';
14+
package: 'TestCoverage';
1515
package: 'MuTalk-Model' with: [ spec requires: #( 'TestCoverage' ) ];
1616
package: 'MuTalk-TestResources' with: [ spec requires: #( 'MuTalk-Model' ) ];
1717
package: 'MuTalk-TestResourcesForExtensionMethods' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' ) ];
1818
package: 'MuTalk-CI' with: [ spec requires: #( 'MuTalk-Model' ) ];
1919
package: 'MuTalk-CI-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-CI' ) ];
20-
package: 'MuTalk-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods') ];
21-
package: 'MuTalk-SpecUI' with: [ spec requires: #('MuTalk-Model') ];
20+
package: 'MuTalk-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods' ) ];
21+
package: 'MuTalk-SpecUI' with: [ spec requires: #( 'MuTalk-Model' ) ];
2222
package: 'MuTalk-Utilities' with: [ spec requires: #( 'MuTalk-Model' ) ];
23-
package: 'MuTalk-Utilities-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-Utilities' ) ].
23+
package: 'MuTalk-Utilities-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-Utilities' ) ];
24+
package: 'MuTalk-Examples' with: [ spec requires: #( 'MuTalk-Model' ) ].
2425

2526
spec
2627
group: 'default'
27-
with:
28-
#( 'TestCoverage' 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods' 'MuTalk-Tests'
29-
'MuTalk-CI' 'MuTalk-CI-Tests' 'MuTalk-SpecUI' 'MuTalk-Utilities' 'MuTalk-Utilities-Tests' ) ]
28+
with: #( 'TestCoverage' 'MuTalk-Model' 'MuTalk-TestResources'
29+
'MuTalk-TestResourcesForExtensionMethods'
30+
'MuTalk-Tests' 'MuTalk-CI' 'MuTalk-CI-Tests' 'MuTalk-SpecUI'
31+
'MuTalk-Utilities' 'MuTalk-Utilities-Tests'
32+
'MuTalk-Examples' ) ]
3033
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Extension { #name : 'MTAnalysis' }
2+
3+
{ #category : '*MuTalk-Examples' }
4+
MTAnalysis class >> exampleAnalysis [
5+
6+
<script>
7+
| analysis |
8+
analysis := self new.
9+
analysis classesToMutate: { MyVehicle }.
10+
analysis testClasses: { MyVehicleTest }.
11+
12+
analysis run.
13+
analysis generalResult inspect
14+
]
15+
16+
{ #category : '*MuTalk-Examples' }
17+
MTAnalysis class >> exampleAnalysisWithLessOperators [
18+
19+
<script>
20+
| mtAnalysis removedOperators nonMutatedAnalysis |
21+
mtAnalysis := self new.
22+
mtAnalysis classesToMutate: { MyVehicle }.
23+
mtAnalysis testClasses: { MyVehicleTest }.
24+
25+
removedOperators := { MTEmptyMethodOperator }.
26+
mtAnalysis operators:
27+
(MTAbstractMutantOperator contents reject: [ :operator |
28+
removedOperators includes: operator class ]).
29+
30+
mtAnalysis run.
31+
mtAnalysis generalResult inspect.
32+
33+
"Uncomment the following instructions to get non mutated methods"
34+
35+
"nonMutatedAnalysis := MTNonMutatedMethodsAnalysis forClasses: { MyVehicle }.
36+
nonMutatedAnalysis mtAnalysis: mtAnalysis.
37+
nonMutatedAnalysis methodsWithoutMutation inspect"
38+
]
39+
40+
{ #category : '*MuTalk-Examples' }
41+
MTAnalysis class >> exampleWithHeatmap [
42+
43+
<script>
44+
| matrix |
45+
matrix := MTMatrix forClasses: { MyVehicle }.
46+
matrix build.
47+
matrix generateHeatmap
48+
]
49+
50+
{ #category : '*MuTalk-Examples' }
51+
MTAnalysis class >> exampleWithMatrix [
52+
53+
<script>
54+
| matrix |
55+
matrix := MTMatrix forClasses: { MyVehicle }.
56+
matrix build.
57+
matrix generateMatrix
58+
]
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"
2+
This class serves only as an example in the MuTalk chapter.
3+
"
4+
Class {
5+
#name : 'MyVehicle',
6+
#superclass : 'Object',
7+
#instVars : [
8+
'numberOfWheels'
9+
],
10+
#category : 'MuTalk-Examples',
11+
#package : 'MuTalk-Examples'
12+
}
13+
14+
{ #category : 'instance creation' }
15+
MyVehicle class >> newBike [
16+
17+
^ self new initializeWithNumberOfWheels: 2
18+
]
19+
20+
{ #category : 'instance creation' }
21+
MyVehicle class >> newSimpleCar [
22+
23+
^ self new initializeWithNumberOfWheels: 4
24+
]
25+
26+
{ #category : 'instance creation' }
27+
MyVehicle class >> newWithWheels: aNumber [
28+
29+
^ self new initializeWithNumberOfWheels: aNumber
30+
]
31+
32+
{ #category : 'as yet unclassified' }
33+
MyVehicle >> emptyMethod [
34+
35+
36+
]
37+
38+
{ #category : 'testing' }
39+
MyVehicle >> hasFourWheels [
40+
41+
^ self numberOfWheels = 4
42+
]
43+
44+
{ #category : 'initialization' }
45+
MyVehicle >> initializeWithNumberOfWheels: aNumberOfWheels [
46+
47+
self numberOfWheels: aNumberOfWheels
48+
]
49+
50+
{ #category : 'accessing' }
51+
MyVehicle >> numberOfWheels [
52+
53+
^ numberOfWheels
54+
]
55+
56+
{ #category : 'accessing' }
57+
MyVehicle >> numberOfWheels: aNumber [
58+
59+
numberOfWheels := aNumber
60+
]
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Class {
2+
#name : 'MyVehicleTest',
3+
#superclass : 'TestCase',
4+
#category : 'MuTalk-Examples',
5+
#package : 'MuTalk-Examples'
6+
}
7+
8+
{ #category : 'tests' }
9+
MyVehicleTest >> testBikeHasTwoWheels [
10+
11+
| bike |
12+
bike := MyVehicle newBike.
13+
self assert: bike numberOfWheels equals: 2
14+
]
15+
16+
{ #category : 'tests' }
17+
MyVehicleTest >> testHasFourWheels [
18+
19+
| aVehicle |
20+
aVehicle := MyVehicle newWithWheels: 4.
21+
self assert: aVehicle hasFourWheels
22+
]
23+
24+
{ #category : 'tests' }
25+
MyVehicleTest >> testSimpleCarHasFourWheels [
26+
27+
| car |
28+
car := MyVehicle newSimpleCar.
29+
self assert: car hasFourWheels
30+
]

src/MuTalk-Examples/package.st

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Package { #name : 'MuTalk-Examples' }

src/MuTalk-Model/MTAnalysis.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ MTAnalysis >> generateCoverageAnalysis [
129129
{ #category : 'running' }
130130
MTAnalysis >> generateMutations [
131131

132-
logger logStartMutationGeneration: self methodSize.
133132
^ mutations ifNil: [
133+
logger logStartMutationGeneration: self methodSize.
134134
mutations := mutantGenerationStrategy
135135
mutationsFor: self
136136
loggingIn: logger.

src/MuTalk-Tests/MTTimeBudgetTest.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ MTTimeBudgetTest >> testWithNoTimeForMutantsRunsNoMutants [
5656

5757
| duration analysisTime result |
5858
"Divide duration by 4 to make sure we never have time for mutants"
59-
duration := self fixedAnalysisTime / 4.
59+
duration := self fixedAnalysisTime / 10.
6060
analysisTime := [ result := self runAnalysisForDuration: duration ]
6161
timeToRun.
6262

src/MuTalk-Utilities/MTMatrix.class.st

+4-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ MTMatrix >> generateHeatmap [
210210
heatmap dataMatrix: (self
211211
dataMatrixForTests: testDictionary
212212
andMutations: mutationDictionary).
213+
"the data change the color palette domain, but we want it to be from 0 to 100"
214+
heatmap colorPalette domain: { 0. 50. 100 }.
213215

214216
heatmap open
215217
]
@@ -245,8 +247,9 @@ MTMatrix >> initializeHeatmap [
245247
heatmap labelShapeCell labelShape bold.
246248
heatmap shape extent: 50 @ 20.
247249
heatmap colorPalette: (NSScale linear range: {
250+
Color red.
248251
Color yellow.
249-
Color red }).
252+
Color green }).
250253
^ heatmap
251254
]
252255

src/MuTalk-Utilities/MTUtilityAnalysis.class.st

+6
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ MTUtilityAnalysis >> mtAnalysis [
5454

5555
^ mtAnalysis
5656
]
57+
58+
{ #category : 'accessing' }
59+
MTUtilityAnalysis >> mtAnalysis: anAnalysis [
60+
61+
mtAnalysis := anAnalysis
62+
]

0 commit comments

Comments
 (0)