forked from pharo-contributions/mutalk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTMutantOperatorTest.class.st
191 lines (158 loc) · 5.59 KB
/
MTMutantOperatorTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
Class {
#name : 'MTMutantOperatorTest',
#superclass : 'TestCase',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}
{ #category : 'testing' }
MTMutantOperatorTest class >> isAbstract [
^ self == MTMutantOperatorTest
]
{ #category : 'accessing' }
MTMutantOperatorTest class >> packageNamesUnderTest [
^ #('MutationTesting-Model')
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToFirstSenderInOneSenderMethod [
^ self compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithOneSender
number: 1)
withSourceInMethod: self class >> #methodWithOneSenderModified
replacingSelector: #methodWithOneSender
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToFirstSenderInTwoSendersMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 1)
withSourceInMethod: self class >> #methodWithTwoSendersModifiedFirst
replacingSelector: #methodWithTwoSenders
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToNonSenderMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithNoSenders
number: 1)
withSourceInMethod: self class >> #methodWithNoSenders
replacingSelector: #methodWithNoSenders
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertApplyingMutantToSecondSenderInTwoSendersMethod [
^self
compareSource:
(self operator
modifiedSourceFor: self class >> #methodWithTwoSenders
number: 2)
withSourceInMethod: self class >> #methodWithTwoSendersModifiedSecond
replacingSelector: #methodWithTwoSenders
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertNumberMutantsGeneratedForNonSenderMethod [
|mutationsGenerated|
mutationsGenerated := self operator mutationsFor: self class >> #methodWithNoSenders.
^mutationsGenerated size = 0.
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertNumberMutantsGeneratedForOneSenderMethod [
|mutationsGenerated|
mutationsGenerated := self operator mutationsFor: self class >> #methodWithOneSender.
^mutationsGenerated size = 1.
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertNumberMutantsGeneratedForTwoSendersMethod [
|mutationsGenerated|
mutationsGenerated := self operator mutationsFor: self class >> #methodWithTwoSenders.
^mutationsGenerated size = 2.
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertTimesToApplyOperatorInTwoSendersMethod [
^ (self operator timesToApplyIn: self class >> #methodWithTwoSenders) = 2
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertTimesToApplyOperatorToNonSenderMethod [
^ (self operator timesToApplyIn: self class >> #methodWithNoSenders) = 0
]
{ #category : 'asserts' }
MTMutantOperatorTest >> assertTimesToApplyOperatorToOneSenderMethod [
^ (self operator timesToApplyIn: self class >> #methodWithOneSender) = 1
]
{ #category : 'formatting' }
MTMutantOperatorTest >> compareSource: aSource withSourceInMethod: aCompiledMethod replacingSelector: aSelector [
"Compare both source replacing the selector of CompiledMethod for aSelector (to make then equal)
and formatting both sources equally."
| sourceSelector secondString methodSelectorString secondStringModified |
sourceSelector := aSelector asString.
secondString := aCompiledMethod sourceCode asString.
methodSelectorString := aCompiledMethod selector asString.
secondStringModified := secondString
copyReplaceAll: methodSelectorString
with: sourceSelector.
^ (self formattedStringFor: aSource)
= (self formattedStringFor: secondStringModified)
]
{ #category : 'formatting' }
MTMutantOperatorTest >> formattedStringFor: aMethodString [
^ (RBParser parseMethod: aMethodString) formattedCode
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithNoSenders [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithOneSender [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithOneSenderModified [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithTwoSenders [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithTwoSendersModifiedFirst [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> methodWithTwoSendersModifiedSecond [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> operator [
self subclassResponsibility
]
{ #category : 'accessing' }
MTMutantOperatorTest >> operatorDescription [
^ self operator description
]
{ #category : 'tests' }
MTMutantOperatorTest >> testApplyMutantToMethod [
self assert: self assertApplyingMutantToNonSenderMethod.
self assert: self assertApplyingMutantToFirstSenderInOneSenderMethod.
self assert: self assertApplyingMutantToFirstSenderInTwoSendersMethod.
self assert: self assertApplyingMutantToSecondSenderInTwoSendersMethod
]
{ #category : 'tests' }
MTMutantOperatorTest >> testNumberMutantsGenerated [
self assert: self assertNumberMutantsGeneratedForNonSenderMethod.
self assert: self assertNumberMutantsGeneratedForOneSenderMethod.
self assert: self assertNumberMutantsGeneratedForTwoSendersMethod
]
{ #category : 'tests' }
MTMutantOperatorTest >> testPrintingAccessors [
self
assert: self operator description
equals: self operatorDescription
]
{ #category : 'tests' }
MTMutantOperatorTest >> testTimesToApplyMutantToMethod [
self assert: self assertTimesToApplyOperatorToNonSenderMethod.
self assert: self assertTimesToApplyOperatorToOneSenderMethod.
self assert: self assertTimesToApplyOperatorInTwoSendersMethod
]