@@ -321,9 +321,8 @@ def test_rindex(self):
321
321
def test_find_periodic_pattern (self ):
322
322
"""Cover the special path for periodic patterns."""
323
323
def reference_find (p , s ):
324
- m = len (p )
325
324
for i in range (len (s )):
326
- if s [ i : i + m ] == p :
325
+ if s . startswith ( p , i ) :
327
326
return i
328
327
return - 1
329
328
@@ -332,8 +331,8 @@ def reference_find(p, s):
332
331
for _ in range (1000 ):
333
332
p0 = '' .join (choices ('abcde' , k = rr (10 ))) * rr (10 , 20 )
334
333
p = p0 [:len (p0 ) - rr (10 )] # pop off some characters
335
- left = '' .join (choices ('abcdef' , k = rr (200 )))
336
- right = '' .join (choices ('abcdef' , k = rr (200 )))
334
+ left = '' .join (choices ('abcdef' , k = rr (2000 )))
335
+ right = '' .join (choices ('abcdef' , k = rr (2000 )))
337
336
text = left + p + right
338
337
with self .subTest (p = p , text = text ):
339
338
self .checkequal (reference_find (p , text ),
@@ -344,14 +343,14 @@ def test_find_shift_table_overflow(self):
344
343
N = 2 ** 16 + 100 # Overflow the 16-bit shift table
345
344
346
345
# first check the periodic case
347
- # here, the shift for 'b' is N.
346
+ # here, the shift for 'b' is N + 1 .
348
347
pattern1 = 'a' * N + 'b' + 'a' * N
349
348
text1 = 'babbaa' * N + pattern1
350
349
self .checkequal (len (text1 )- len (pattern1 ),
351
350
text1 , 'find' , pattern1 )
352
351
353
352
# now check the non-periodic case
354
- # here, the shift for 'd' is 3*(N+1)
353
+ # here, the shift for 'd' is 3*(N+1)+1
355
354
pattern2 = 'ddd' + 'abc' * N + "eee"
356
355
text2 = pattern2 [:- 1 ] + "ddeede" * 2 * N + pattern2 + "de" * N
357
356
self .checkequal (len (text2 ) - N * len ("de" ) - len (pattern2 ),
0 commit comments