test__hash.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:capnpy 作者: antocuni 项目源码 文件源码
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('')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号