Beispiel #1
0
def context2():
    context = Context()
    context.add_sentence('--')  # TT M
    context.add_alphabet(MorseAlphabet())

    encoder = WordEncoder(context)
    context.add_word_encoder(encoder)
    encoder.add_word('T')
    return context
def test_add_one_word(context):
    encoder = WordEncoder(context)
    encoded_dict = encoder.get_dict()

    encoder.add_word('HTE')
    word = encoded_dict['....-.']
    assert word.duplicates == 1
    assert word.word == '....-.'
    assert len(encoder) == 1
Beispiel #3
0
def test_add_one_word():
    encoder = WordEncoder()

    encoder.add_word('HTE')
    encoded_dict = encoder.get_dict()
    assert encoded_dict['....-.'] == 1
    encoder.add_word('HTE')
    encoded_dict = encoder.get_dict()
    assert encoded_dict['....-.'] == 2
    assert len(encoder.get_list()) == 1
def test_add_two_word_with_screening(context):
    encoder = WordEncoder(context, use_screening=True)
    encoded_dict = encoder.get_dict()

    encoder.add_word('HTE')
    assert str(encoded_dict['....-.']) == '....-.'

    encoder.add_word('K')
    assert '-.-' not in encoded_dict

    assert len(encoder) == 1
def test_add_two_word_with_duplicates(context):
    encoder = WordEncoder(context)
    encoded_dict = encoder.get_dict()

    encoder.add_word('HTE')
    assert str(encoded_dict['....-.']) == '....-.'

    encoder.add_word('HTE')
    assert str(encoded_dict['....-.']) == '....-.#2'

    assert len(encoder) == 1
def test_add_two_words(context):
    encoder = WordEncoder(context)
    encoded_dict = encoder.get_dict()

    encoder.add_word('HTE')
    assert str(encoded_dict['....-.']) == '....-.'

    encoder.add_word('ET')
    assert str(encoded_dict['.-']) == '.-'

    assert len(encoder) == 2
Beispiel #7
0
def context1():
    context = Context()
    context.add_sentence('......-...-..---')  # HELLO
    context.add_alphabet(MorseAlphabet())

    encoder = WordEncoder(context)
    context.add_word_encoder(encoder)
    encoder.add_word('HELLO')
    encoder.add_word('HELL')
    encoder.add_word('TEST')
    return context
Beispiel #8
0
def context4():
    context = Context()
    context.add_sentence('......-...-..---')  # HELLO
    context.add_alphabet(MorseAlphabet())

    encoder = WordEncoder(context)
    context.add_word_encoder(encoder)
    encoder.add_word('HELLO')
    encoder.add_word('EEEEELLO')  # same encoding

    context.add_word_finder(WordFinder(context))

    return context
Beispiel #9
0
def context2():
    context = Context()
    context.add_sentence('......-...-..---')  # HELLO
    context.add_alphabet(MorseAlphabet())

    encoder = WordEncoder(context)
    context.add_word_encoder(encoder)
    encoder.add_word('HELL')
    encoder.add_word('O')  # invalid in pos 0

    context.add_word_finder(WordFinder(context))

    return context
def test_add_two_word_indexed(context):
    encoder = WordEncoder(context, use_size_index=True)
    index = encoder.get_index_dict()

    encoder.add_word('ET')
    assert index[2][0].word == '.-'
    encoder.add_word('EE')
    assert index[2][1].word == '..'
    encoder.add_word('EM')
    assert index[3][0].word == '.--'
def test_add_one_word_with_sep(context):
    encoder = WordEncoder(context, sep='|')
    encoded_dict = encoder.get_dict()
    encoder.add_word('HTE')
    assert encoded_dict['....|-|.'].word == '....|-|.'
Beispiel #12
0
def test_add_one_word_with_alphabet():
    morse = MorseAlphabet()
    encoder = WordEncoder(sep='|', alphabet=morse)
    encoder.add_word('HTE')
    encoded_dict = encoder.get_dict()
    assert encoded_dict['....|-|.'] == 1