예제 #1
0
def test_add_contact_four_letters():
    '''
    When a contact that is four letters long is added,
       the last edge should have a prefix total = 1 and one edge
    '''
    from trie import vertex, add_contact

    new_trie = vertex()
    add_contact(new_trie, 'abcd')

    # first letter = 'a'
    assert new_trie.edges[0] is not None

    # first letter = 'ab'
    assert new_trie.edges[0].edges[1] is not None

    # first letter = 'abc'
    assert new_trie.edges[0].edges[1].edges[2] is not None

    # first letter = 'abcd'
    assert new_trie.edges[0].edges[1].edges[2].edges[3] is not None

    # There is one partial that starts with 'a'
    assert new_trie.edges[0].partials == 1

    # There is 1 partial that is 'ab'
    assert new_trie.edges[0].edges[1].partials == 1

    # There is 1 partial that is 'abc'
    assert new_trie.edges[0].edges[1].edges[2].partials == 1

    # There is 1 partial that is 'abcd'
    assert new_trie.edges[0].edges[1].edges[2].edges[3].partials == 1
예제 #2
0
def test_count_partials_one_letter_once():
    '''
    Count how many contacts that start with 'a' if one 'a' is inserted
    '''

    from trie import vertex, add_contact, count_partials

    new_trie = vertex()
    add_contact(new_trie, 'a')

    assert count_partials(new_trie, 'a') == 1
예제 #3
0
def test_add_contact_one_letter():
    '''
    When a contact that is one letter long is added,
       the edge should have a prefix total = 1 and one edge
    '''
    from trie import vertex, add_contact

    new_trie = vertex()
    add_contact(new_trie, 'a')

    # first (null) vertex
    assert new_trie.partials == 1

    # first letter = a
    assert new_trie.edges[0] is not None

    # first letter != b
    assert new_trie.edges[1] is None

    # There is one partial = 'a'
    assert new_trie.edges[0].partials == 1
예제 #4
0
def test_add_three_contacts_four_letters():
    '''
    When three overlapping contact that is four letters long is added,
       the last edge should have a prefix total = 1 and one edge
    '''
    from trie import vertex, add_contact

    new_trie = vertex()
    add_contact(new_trie, 'abcd')
    add_contact(new_trie, 'abde')
    add_contact(new_trie, 'acde')

    # There are 3 partials that starts with 'a'
    assert new_trie.edges[0].partials == 3

    # There are 2 partials that is 'ab'
    assert new_trie.edges[0].edges[1].partials == 2

    # There is 1 partial that is 'ac'
    assert new_trie.edges[0].edges[2].partials == 1

    # There is 1 partial that is 'abcd'
    assert new_trie.edges[0].edges[1].edges[2].edges[3].partials == 1

    # There is 1 partial that is 'abde'
    assert new_trie.edges[0].edges[1].edges[3].edges[4].partials == 1

    # There is 1 partial that is 'acde'
    assert new_trie.edges[0].edges[2].edges[3].edges[4].partials == 1
예제 #5
0
def test_count_partials_three_letter_many_words():
    '''
    Count how many contacts that start with 'abc' if many different
        contacts starting with 'abc' are inserted
    '''

    from trie import vertex, add_contact, count_partials

    new_trie = vertex()
    add_contact(new_trie, 'abc')
    add_contact(new_trie, 'abcsdf')
    add_contact(new_trie, 'abcrt')
    add_contact(new_trie, 'abcttt')

    assert count_partials(new_trie, 'a') == 4