def test_strhash():
expected_hash_empty_string = 0
if IS_PYPY:
if PY3:
# pypy3.5 v5.8 uses salt even for empty string
expected_hash_empty_string = hash('')
elif sys.pypy_version_info[:2] < (5,4):
# pypy changed this on 5.4, related to issue #3
expected_hash_empty_string = -1
else:
expected_hash_empty_string = -2
#
h = _hash.strhash
assert h(b'', 0, 0) == hash('') == expected_hash_empty_string
assert h(b'hello', 0, 5) == hash('hello')
assert h(b'hello', 1, 4) == hash('ello')
assert h(b'hello', 1, 3) == hash('ell')
assert h(b'hello', 1, 100) == hash('ello')
assert h(b'hello', 1, 0) == hash('')
assert h(b'hello', 100, 5) == hash('')
评论列表
文章目录