예제 #1
0
def test_uniquely_decodable_invalid():
    c = code.Code(
        {'a':'01',
         'b':'21',
         'c':'0110',
         'd':'212',
         'e':'1001'}
    )
    assert not c.is_uniquely_decodable()
예제 #2
0
def test_decoding_brute_force():
    c = code.Code(
        {'a':'01',
         'b':'21',
         'c':'0112',
         'd':'212',
         'e':'011'}
    )
    assert c.encode('abcade') == '0121011201212011'
    assert c.decode(c.encode('abcade')) == 'abcade'
예제 #3
0
def test_word_length():
    s = source.Source({
        'a':1/4,
        'b':1/4,
        'c':1/2
    })
    c1 = code.Code({
        'a':'01',
        'b':'1',
        'c':'00',
    })
    assert abs(c1.get_word_length(s) - 1.75) < 0.00001

    c2 = code.Code({
        'a':'01',
        'b':'00',
        'c':'1',
    })

    assert abs(c2.get_word_length(s) - 1.5) < 0.00001
예제 #4
0
def test_decoding_trie():
    """UnCodeGL will only use data structure to decode
    when is a prefix code
    """
    c = code.Code(
        {'a':'012',
         'b':'210',
         'c':'0112',
         'd':'212',
         'e':'010'}
    )
    s = 'bcdaeba'
    assert c.encode(s) == '2100112212012010210012'
    assert c.decode(c.encode(s)) == s
예제 #5
0
def test_constructor():
    c = code.Code({'a':'0','b':'10','c':'11','d':'12'})
    assert c.code_alphabet == {'0','1','2'}
    assert c.source_words == {'a','b','c','d'}
    assert c.arity == 3
예제 #6
0
def test_is_prefix_true():
    c = code.Code({'a':'0','b':'10','c':'11','d':'12'})
    assert c.is_prefix()
예제 #7
0
def test_is_prefix_false():
    c = code.Code({'a':'0','b':'10','c':'11','d':'112'})
    assert not c.is_prefix()