示例#1
0
文件: test_bx.py 项目: clibc/shorten
def test_bx_decode_empty():
    alphabet = ""
    string = "a string"
    nose.tools.assert_raises(ValueError, lambda: bx_decode(string, alphabet))

    alphabet = "abc"
    string = ""
    nose.tools.assert_raises(ValueError, lambda: bx_decode(string, alphabet))
示例#2
0
文件: test_bx.py 项目: clibc/shorten
def test_bx_encode_decode_mapping():
    alphabet = "abc"
    mapping = {"a": 0, "b": 1, "c": 2}

    encoded = bx_encode(3, alphabet)
    assert encoded == "ba"

    decoded = bx_decode(encoded, alphabet, mapping)
    assert decoded == 3

    decoded = bx_decode("ba", alphabet, mapping)
    assert decoded == 3
示例#3
0
文件: test_bx.py 项目: clibc/shorten
def test_bx_encode_decode_deadbeef():
    alphabet = "0123456789abcdef"

    deadbeef = bx_encode(0xDEADBEEF, alphabet)
    assert deadbeef == "deadbeef"

    deadbeef = bx_decode(deadbeef, alphabet)
    assert deadbeef == 0xDEADBEEF