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

Example for the MuTalk chapter and small changes #121

Merged
merged 7 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/BaselineOfMuTalk/BaselineOfMuTalk.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ Class {

{ #category : 'baselines' }
BaselineOfMuTalk >> baseline: spec [
<baseline>

<baseline>
spec for: #common do: [
spec
package: 'TestCoverage';
package: 'TestCoverage';
package: 'MuTalk-Model' with: [ spec requires: #( 'TestCoverage' ) ];
package: 'MuTalk-TestResources' with: [ spec requires: #( 'MuTalk-Model' ) ];
package: 'MuTalk-TestResourcesForExtensionMethods' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' ) ];
package: 'MuTalk-CI' with: [ spec requires: #( 'MuTalk-Model' ) ];
package: 'MuTalk-CI-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-CI' ) ];
package: 'MuTalk-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods') ];
package: 'MuTalk-SpecUI' with: [ spec requires: #('MuTalk-Model') ];
package: 'MuTalk-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods' ) ];
package: 'MuTalk-SpecUI' with: [ spec requires: #( 'MuTalk-Model' ) ];
package: 'MuTalk-Utilities' with: [ spec requires: #( 'MuTalk-Model' ) ];
package: 'MuTalk-Utilities-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-Utilities' ) ].
package: 'MuTalk-Utilities-Tests' with: [ spec requires: #( 'MuTalk-Model' 'MuTalk-Utilities' ) ];
package: 'MuTalk-Examples' with: [ spec requires: #( 'MuTalk-Model' ) ].

spec
group: 'default'
with:
#( 'TestCoverage' 'MuTalk-Model' 'MuTalk-TestResources' 'MuTalk-TestResourcesForExtensionMethods' 'MuTalk-Tests'
'MuTalk-CI' 'MuTalk-CI-Tests' 'MuTalk-SpecUI' 'MuTalk-Utilities' 'MuTalk-Utilities-Tests' ) ]
with: #( 'TestCoverage' 'MuTalk-Model' 'MuTalk-TestResources'
'MuTalk-TestResourcesForExtensionMethods'
'MuTalk-Tests' 'MuTalk-CI' 'MuTalk-CI-Tests' 'MuTalk-SpecUI'
'MuTalk-Utilities' 'MuTalk-Utilities-Tests'
'MuTalk-Examples' ) ]
]
58 changes: 58 additions & 0 deletions src/MuTalk-Examples/MTAnalysis.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Extension { #name : 'MTAnalysis' }

{ #category : '*MuTalk-Examples' }
MTAnalysis class >> exampleAnalysis [

<script>
| analysis |
analysis := self new.
analysis classesToMutate: { MyVehicle }.
analysis testClasses: { MyVehicleTest }.

analysis run.
analysis generalResult inspect
]

{ #category : '*MuTalk-Examples' }
MTAnalysis class >> exampleAnalysisWithLessOperators [

<script>
| mtAnalysis removedOperators nonMutatedAnalysis |
mtAnalysis := self new.
mtAnalysis classesToMutate: { MyVehicle }.
mtAnalysis testClasses: { MyVehicleTest }.

removedOperators := { MTEmptyMethodOperator }.
mtAnalysis operators:
(MTAbstractMutantOperator contents reject: [ :operator |
removedOperators includes: operator class ]).

mtAnalysis run.
mtAnalysis generalResult inspect.

"Uncomment the following instructions to get non mutated methods"

"nonMutatedAnalysis := MTNonMutatedMethodsAnalysis forClasses: { MyVehicle }.
nonMutatedAnalysis mtAnalysis: mtAnalysis.
nonMutatedAnalysis methodsWithoutMutation inspect"
]

{ #category : '*MuTalk-Examples' }
MTAnalysis class >> exampleWithHeatmap [

<script>
| matrix |
matrix := MTMatrix forClasses: { MyVehicle }.
matrix build.
matrix generateHeatmap
]

{ #category : '*MuTalk-Examples' }
MTAnalysis class >> exampleWithMatrix [

<script>
| matrix |
matrix := MTMatrix forClasses: { MyVehicle }.
matrix build.
matrix generateMatrix
]
60 changes: 60 additions & 0 deletions src/MuTalk-Examples/MyVehicle.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"
This class serves only as an example in the MuTalk chapter.
"
Class {
#name : 'MyVehicle',
#superclass : 'Object',
#instVars : [
'numberOfWheels'
],
#category : 'MuTalk-Examples',
#package : 'MuTalk-Examples'
}

{ #category : 'instance creation' }
MyVehicle class >> newBike [

^ self new initializeWithNumberOfWheels: 2
]

{ #category : 'instance creation' }
MyVehicle class >> newSimpleCar [

^ self new initializeWithNumberOfWheels: 4
]

{ #category : 'instance creation' }
MyVehicle class >> newWithWheels: aNumber [

^ self new initializeWithNumberOfWheels: aNumber
]

{ #category : 'as yet unclassified' }
MyVehicle >> emptyMethod [


]

{ #category : 'testing' }
MyVehicle >> hasFourWheels [

^ self numberOfWheels = 4
]

{ #category : 'initialization' }
MyVehicle >> initializeWithNumberOfWheels: aNumberOfWheels [

self numberOfWheels: aNumberOfWheels
]

{ #category : 'accessing' }
MyVehicle >> numberOfWheels [

^ numberOfWheels
]

{ #category : 'accessing' }
MyVehicle >> numberOfWheels: aNumber [

numberOfWheels := aNumber
]
30 changes: 30 additions & 0 deletions src/MuTalk-Examples/MyVehicleTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Class {
#name : 'MyVehicleTest',
#superclass : 'TestCase',
#category : 'MuTalk-Examples',
#package : 'MuTalk-Examples'
}

{ #category : 'tests' }
MyVehicleTest >> testBikeHasTwoWheels [

| bike |
bike := MyVehicle newBike.
self assert: bike numberOfWheels equals: 2
]

{ #category : 'tests' }
MyVehicleTest >> testHasFourWheels [

| aVehicle |
aVehicle := MyVehicle newWithWheels: 4.
self assert: aVehicle hasFourWheels
]

{ #category : 'tests' }
MyVehicleTest >> testSimpleCarHasFourWheels [

| car |
car := MyVehicle newSimpleCar.
self assert: car hasFourWheels
]
1 change: 1 addition & 0 deletions src/MuTalk-Examples/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'MuTalk-Examples' }
2 changes: 1 addition & 1 deletion src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ MTAnalysis >> generateCoverageAnalysis [
{ #category : 'running' }
MTAnalysis >> generateMutations [

logger logStartMutationGeneration: self methodSize.
^ mutations ifNil: [
logger logStartMutationGeneration: self methodSize.
mutations := mutantGenerationStrategy
mutationsFor: self
loggingIn: logger.
Expand Down
2 changes: 1 addition & 1 deletion src/MuTalk-Tests/MTTimeBudgetTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ MTTimeBudgetTest >> testWithNoTimeForMutantsRunsNoMutants [

| duration analysisTime result |
"Divide duration by 4 to make sure we never have time for mutants"
duration := self fixedAnalysisTime / 4.
duration := self fixedAnalysisTime / 10.
analysisTime := [ result := self runAnalysisForDuration: duration ]
timeToRun.

Expand Down
5 changes: 4 additions & 1 deletion src/MuTalk-Utilities/MTMatrix.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ MTMatrix >> generateHeatmap [
heatmap dataMatrix: (self
dataMatrixForTests: testDictionary
andMutations: mutationDictionary).
"the data change the color palette domain, but we want it to be from 0 to 100"
heatmap colorPalette domain: { 0. 50. 100 }.

heatmap open
]
Expand Down Expand Up @@ -245,8 +247,9 @@ MTMatrix >> initializeHeatmap [
heatmap labelShapeCell labelShape bold.
heatmap shape extent: 50 @ 20.
heatmap colorPalette: (NSScale linear range: {
Color red.
Color yellow.
Color red }).
Color green }).
^ heatmap
]

Expand Down
6 changes: 6 additions & 0 deletions src/MuTalk-Utilities/MTUtilityAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ MTUtilityAnalysis >> mtAnalysis [

^ mtAnalysis
]

{ #category : 'accessing' }
MTUtilityAnalysis >> mtAnalysis: anAnalysis [

mtAnalysis := anAnalysis
]
Loading