@@ -321,9 +321,8 @@ def test_rindex(self):
321321 def test_find_periodic_pattern (self ):
322322 """Cover the special path for periodic patterns."""
323323 def reference_find (p , s ):
324- m = len (p )
325324 for i in range (len (s )):
326- if s [ i : i + m ] == p :
325+ if s . startswith ( p , i ) :
327326 return i
328327 return - 1
329328
@@ -332,8 +331,8 @@ def reference_find(p, s):
332331 for _ in range (1000 ):
333332 p0 = '' .join (choices ('abcde' , k = rr (10 ))) * rr (10 , 20 )
334333 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 )))
337336 text = left + p + right
338337 with self .subTest (p = p , text = text ):
339338 self .checkequal (reference_find (p , text ),
@@ -344,14 +343,14 @@ def test_find_shift_table_overflow(self):
344343 N = 2 ** 16 + 100 # Overflow the 16-bit shift table
345344
346345 # first check the periodic case
347- # here, the shift for 'b' is N.
346+ # here, the shift for 'b' is N + 1 .
348347 pattern1 = 'a' * N + 'b' + 'a' * N
349348 text1 = 'babbaa' * N + pattern1
350349 self .checkequal (len (text1 )- len (pattern1 ),
351350 text1 , 'find' , pattern1 )
352351
353352 # 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
355354 pattern2 = 'ddd' + 'abc' * N + "eee"
356355 text2 = pattern2 [:- 1 ] + "ddeede" * 2 * N + pattern2 + "de" * N
357356 self .checkequal (len (text2 ) - N * len ("de" ) - len (pattern2 ),
0 commit comments