mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merged revisions 77241 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77241 | antoine.pitrou | 2010-01-02 22:12:58 +0100 (sam., 02 janv. 2010) | 4 lines Issue #7462: Implement the stringlib fast search algorithm for the `rfind`, `rindex`, `rsplit` and `rpartition` methods. Patch by Florent Xicluna. ........
This commit is contained in:
parent
2952148dd2
commit
da2ecaf334
10 changed files with 131 additions and 115 deletions
|
@ -216,6 +216,30 @@ class BaseTest(unittest.TestCase):
|
|||
self.checkraises(TypeError, 'hello', 'rfind')
|
||||
self.checkraises(TypeError, 'hello', 'rfind', 42)
|
||||
|
||||
# For a variety of combinations,
|
||||
# verify that str.rfind() matches __contains__
|
||||
# and that the found substring is really at that location
|
||||
charset = ['', 'a', 'b', 'c']
|
||||
digits = 5
|
||||
base = len(charset)
|
||||
teststrings = set()
|
||||
for i in range(base ** digits):
|
||||
entry = []
|
||||
for j in range(digits):
|
||||
i, m = divmod(i, base)
|
||||
entry.append(charset[m])
|
||||
teststrings.add(''.join(entry))
|
||||
teststrings = [self.fixtype(ts) for ts in teststrings]
|
||||
for i in teststrings:
|
||||
for j in teststrings:
|
||||
loc = i.rfind(j)
|
||||
r1 = (loc != -1)
|
||||
r2 = j in i
|
||||
if r1 != r2:
|
||||
self.assertEqual(r1, r2)
|
||||
if loc != -1:
|
||||
self.assertEqual(i[loc:loc+len(j)], j)
|
||||
|
||||
def test_index(self):
|
||||
self.checkequal(0, 'abcdefghiabc', 'index', '')
|
||||
self.checkequal(3, 'abcdefghiabc', 'index', 'def')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue