@@ -180,45 +180,47 @@ test03StackCannotBeEmpty
180
180
181
181
self testThat: findingStringInEmptyStack throwsSignal: Error andInThatCaseTestThat: errorIsThatStackIsEmpty.! !
182
182
183
- !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8 /2021 23:52:07 '!
183
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10 /2021 16:20:15 '!
184
184
test04CanFindOneMatch
185
185
186
- | matches elements |
186
+ | matches elements prefix |
187
+
188
+ prefix := 'the'.
187
189
elements := #('winter is coming' 'winning is everything' 'the winds of winter' 'winter is here').
188
190
self pushElementsFrom: elements to: stack.
189
191
190
- matches := finder find: 'the' in: stack.
192
+ matches := finder find: prefix in: stack.
191
193
192
- self assert: (matches size = 1).
193
- self assert: ((matches count: [ :aMatch | aMatch = 'the winds of winter' ]) = 1).
194
-
194
+ self testThatThereAre: 1 elementsIn: matches andAllStartWith: prefix.
195
195
! !
196
196
197
- !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8 /2021 23:55:48 '!
197
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10 /2021 15:45:00 '!
198
198
test05CanFindMultipleMatches
199
199
200
- | matches elements |
200
+ | matches elements prefix |
201
+
202
+ prefix := 'wint'.
201
203
elements := #('winter is coming' 'winning is everything' 'the winds of winter' 'winter is here').
202
204
self pushElementsFrom: elements to: stack.
203
205
204
- matches := finder find: 'wint' in: stack.
206
+ matches := finder find: prefix in: stack.
205
207
206
- self assert: (matches size = 2).
207
- self assert: ((matches count: [ :aMatch | aMatch beginsWith: 'wint' ]) = 2).
208
+ self testThatThereAre: 2 elementsIn: matches andAllStartWith: prefix.
208
209
209
210
! !
210
211
211
- !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8 /2021 23:53:59 '!
212
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10 /2021 15:44:18 '!
212
213
test06MatchIsCaseSensitive
213
214
214
- | matches elements |
215
+ | matches elements prefix |
216
+
217
+ prefix := 'Wint'.
215
218
elements := #('winter is coming' 'winning is everything' 'The winds of Winter' 'Winter is here').
216
219
self pushElementsFrom: elements to: stack.
217
220
218
- matches := finder find: 'Wint' in: stack.
221
+ matches := finder find: prefix in: stack.
219
222
220
- self assert: (matches size = 1).
221
- self assert: ((matches count: [ :aMatch | aMatch = 'Winter is here' ]) = 1).
223
+ self testThatThereAre: 1 elementsIn: matches andAllStartWith: prefix.
222
224
223
225
! !
224
226
@@ -251,34 +253,49 @@ test08StackRemainsUntouched
251
253
252
254
! !
253
255
254
- !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/9 /2021 00:22:17 '!
256
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10 /2021 15:42:22 '!
255
257
test09AllElementsInStackMatch
256
258
257
- | matches elements |
259
+ | matches elements prefix |
260
+
261
+ prefix := 'winter'.
258
262
elements := #('winter is coming' 'winter is everything' 'winter is not here' 'winter is here' 'winter, i love it' 'winter.').
259
263
self pushElementsFrom: elements to: stack.
260
264
261
- matches := finder find: 'winter' in: stack.
265
+ matches := finder find: prefix in: stack.
262
266
263
- self assert: (matches size = stack size).
264
- self assert: ((matches count: [ :aMatch | aMatch beginsWith: 'winter' ]) = stack size).
267
+ self testThatThereAre: (stack size) elementsIn: matches andAllStartWith: prefix.
265
268
266
269
! !
267
270
268
- !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/9 /2021 00:26:17 '!
271
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10 /2021 15:40:57 '!
269
272
test10CanFindElementThatOnlyContainsPrefix
270
273
271
- | matches elements |
274
+ | matches elements prefix |
275
+
276
+ prefix := 'winter'.
272
277
elements := #('asasdas' 'sadads' 'A' 'winter').
273
278
self pushElementsFrom: elements to: stack.
274
279
275
- matches := finder find: 'winter' in: stack.
280
+ matches := finder find: prefix in: stack.
276
281
277
- self assert: (matches size = 1).
278
- self assert: ((matches count: [ :aMatch | aMatch = 'winter']) = 1).
282
+ self testThatThereAre: 1 elementsIn: matches andAllStartWith: prefix.
279
283
280
284
! !
281
285
286
+ !SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 16:16:18'!
287
+ test11MatchFoundContainsTheEntireSentenceAndNotJustThePrefix
288
+
289
+ | matches prefix expectedMatch |
290
+
291
+ prefix := 'wint'.
292
+ expectedMatch := 'winter is coming'.
293
+
294
+ stack push: expectedMatch.
295
+ matches := finder find: prefix in: stack.
296
+
297
+ self assert: ((matches at: 1) = expectedMatch).! !
298
+
282
299
283
300
!SentenceFinderByPrefixTest methodsFor: 'helpers' stamp: 'MC 6/8/2021 23:49:46'!
284
301
pushElementsFrom: anArray to: aStack
@@ -292,6 +309,12 @@ testThat: aClosure throwsSignal: anException andInThatCaseTestThat: anotherClosu
292
309
on: anException
293
310
do: anotherClosure.! !
294
311
312
+ !SentenceFinderByPrefixTest methodsFor: 'helpers' stamp: 'MC 6/10/2021 15:43:36'!
313
+ testThatThereAre: aNumber elementsIn: aCollection andAllStartWith: aPrefix.
314
+
315
+ self assert: (aCollection size = aNumber).
316
+ self assert: ((aCollection count: [ :aMatch | aMatch beginsWith: aPrefix]) = aNumber).! !
317
+
295
318
!SentenceFinderByPrefixTest methodsFor: 'helpers' stamp: 'MC 6/9/2021 00:20:31'!
296
319
verifyThat: aStack hasTheSameElementsAs: anotherStack
297
320
@@ -374,7 +397,7 @@ Object subclass: #SentenceFinderByPrefix
374
397
poolDictionaries: ''
375
398
category: 'Stack-Exercise'!
376
399
377
- !SentenceFinderByPrefix methodsFor: 'testing ' stamp: 'MC 6/8/2021 23:06:17'!
400
+ !SentenceFinderByPrefix methodsFor: 'private ' stamp: 'MC 6/8/2021 23:06:17'!
378
401
verifyPrefix: aPrefix andStack: aStack
379
402
380
403
(aPrefix = '' ) ifTrue: [ self error: SentenceFinderByPrefix prefixIsEmptyErrorDescription ].
0 commit comments