MCPcopy Index your code
hub / github.com/python/cpython / test_find_many_lengths

Method test_find_many_lengths

Lib/test/string_tests.py:397–409  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

395 check_pattern(lambda *args: 0)
396
397 def test_find_many_lengths(self):
398 haystack_repeats = [a * 10**e for e in range(6) for a in (1,2,5)]
399 haystacks = [(n, self.fixtype("abcab"*n + "da")) for n in haystack_repeats]
400
401 needle_repeats = [a * 10**e for e in range(6) for a in (1, 3)]
402 needles = [(m, self.fixtype("abcab"*m + "da")) for m in needle_repeats]
403
404 for n, haystack1 in haystacks:
405 haystack2 = haystack1[:-1]
406 for m, needle in needles:
407 answer1 = 5 * (n - m) if m <= n else -1
408 self.assertEqual(haystack1.find(needle), answer1, msg=(n,m))
409 self.assertEqual(haystack2.find(needle), -1, msg=(n,m))
410
411 def test_adaptive_find(self):
412 # This would be very slow for the naive algorithm,

Callers

nothing calls this directly

Calls 3

fixtypeMethod · 0.95
assertEqualMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected