Skip to content

Commit c233c9c

Browse files
Tests del finder terminados
1 parent d3e64f5 commit c233c9c

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

04-Stack/TP_Stack.st

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -180,45 +180,47 @@ test03StackCannotBeEmpty
180180

181181
self testThat: findingStringInEmptyStack throwsSignal: Error andInThatCaseTestThat: errorIsThatStackIsEmpty.! !
182182

183-
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8/2021 23:52:07'!
183+
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 16:20:15'!
184184
test04CanFindOneMatch
185185

186-
| matches elements |
186+
| matches elements prefix |
187+
188+
prefix := 'the'.
187189
elements := #('winter is coming' 'winning is everything' 'the winds of winter' 'winter is here').
188190
self pushElementsFrom: elements to: stack.
189191

190-
matches := finder find: 'the' in: stack.
192+
matches := finder find: prefix in: stack.
191193

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.
195195
! !
196196

197-
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8/2021 23:55:48'!
197+
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 15:45:00'!
198198
test05CanFindMultipleMatches
199199

200-
| matches elements |
200+
| matches elements prefix |
201+
202+
prefix := 'wint'.
201203
elements := #('winter is coming' 'winning is everything' 'the winds of winter' 'winter is here').
202204
self pushElementsFrom: elements to: stack.
203205

204-
matches := finder find: 'wint' in: stack.
206+
matches := finder find: prefix in: stack.
205207

206-
self assert: (matches size = 2).
207-
self assert: ((matches count: [ :aMatch | aMatch beginsWith: 'wint' ]) = 2).
208+
self testThatThereAre: 2 elementsIn: matches andAllStartWith: prefix.
208209

209210
! !
210211

211-
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/8/2021 23:53:59'!
212+
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 15:44:18'!
212213
test06MatchIsCaseSensitive
213214

214-
| matches elements |
215+
| matches elements prefix |
216+
217+
prefix := 'Wint'.
215218
elements := #('winter is coming' 'winning is everything' 'The winds of Winter' 'Winter is here').
216219
self pushElementsFrom: elements to: stack.
217220

218-
matches := finder find: 'Wint' in: stack.
221+
matches := finder find: prefix in: stack.
219222

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.
222224

223225
! !
224226

@@ -251,34 +253,49 @@ test08StackRemainsUntouched
251253

252254
! !
253255

254-
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/9/2021 00:22:17'!
256+
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 15:42:22'!
255257
test09AllElementsInStackMatch
256258

257-
| matches elements |
259+
| matches elements prefix |
260+
261+
prefix := 'winter'.
258262
elements := #('winter is coming' 'winter is everything' 'winter is not here' 'winter is here' 'winter, i love it' 'winter.').
259263
self pushElementsFrom: elements to: stack.
260264

261-
matches := finder find: 'winter' in: stack.
265+
matches := finder find: prefix in: stack.
262266

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.
265268

266269
! !
267270

268-
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/9/2021 00:26:17'!
271+
!SentenceFinderByPrefixTest methodsFor: 'tests' stamp: 'MC 6/10/2021 15:40:57'!
269272
test10CanFindElementThatOnlyContainsPrefix
270273

271-
| matches elements |
274+
| matches elements prefix |
275+
276+
prefix := 'winter'.
272277
elements := #('asasdas' 'sadads' 'A' 'winter').
273278
self pushElementsFrom: elements to: stack.
274279

275-
matches := finder find: 'winter' in: stack.
280+
matches := finder find: prefix in: stack.
276281

277-
self assert: (matches size = 1).
278-
self assert: ((matches count: [ :aMatch | aMatch = 'winter']) = 1).
282+
self testThatThereAre: 1 elementsIn: matches andAllStartWith: prefix.
279283

280284
! !
281285

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+
282299

283300
!SentenceFinderByPrefixTest methodsFor: 'helpers' stamp: 'MC 6/8/2021 23:49:46'!
284301
pushElementsFrom: anArray to: aStack
@@ -292,6 +309,12 @@ testThat: aClosure throwsSignal: anException andInThatCaseTestThat: anotherClosu
292309
on: anException
293310
do: anotherClosure.! !
294311

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+
295318
!SentenceFinderByPrefixTest methodsFor: 'helpers' stamp: 'MC 6/9/2021 00:20:31'!
296319
verifyThat: aStack hasTheSameElementsAs: anotherStack
297320

@@ -374,7 +397,7 @@ Object subclass: #SentenceFinderByPrefix
374397
poolDictionaries: ''
375398
category: 'Stack-Exercise'!
376399

377-
!SentenceFinderByPrefix methodsFor: 'testing' stamp: 'MC 6/8/2021 23:06:17'!
400+
!SentenceFinderByPrefix methodsFor: 'private' stamp: 'MC 6/8/2021 23:06:17'!
378401
verifyPrefix: aPrefix andStack: aStack
379402

380403
(aPrefix = '' ) ifTrue: [ self error: SentenceFinderByPrefix prefixIsEmptyErrorDescription ].

0 commit comments

Comments
 (0)