Beispiel #1
0
def test_add_new_word_to_dict():
    a = Anagramizer()
    expected = {
        'ader': set(['dear']),
    }
    assert a.add_word('dear')
    assert a._words == expected
Beispiel #2
0
def test_save_to_file_cpmpressed():
    a = Anagramizer('tests/data/test_initialization.txt')
    save_file = 'tests/data/tmp_test_save_to_file.gz'
    expected = 'Adam\nMat\napple\nart\ndear\nmat\nrat\nread\ntar'
    a._save_to_file(save_file, True)
    with gzip.open(save_file, 'rb') as f:
        save_content = f.read().decode()
    assert save_content == expected
    os.unlink(save_file)
Beispiel #3
0
def test_remove_anagrams():
    a = Anagramizer('tests/data/test_initialization.txt')
    expected = {
        'aadm': set(['Adam']),
        'aelpp': set(['apple']),
        'amt': set(['Mat', 'mat']),
        'art': set(['rat', 'tar', 'art']),
    }
    assert a.remove_anagrams('read')
    assert not a.remove_anagrams('xyzzz')
    assert a._words == expected
Beispiel #4
0
def test_remove_word_from_dict():
    a = Anagramizer()
    expected = {
        'ader': set([]),
    }
    assert not a.remove_word('tar')
    a.add_word('dear')  # testedby another test?
    assert a.remove_word('dear')
    assert a._words == expected
Beispiel #5
0
            if len(anagram_set) >= size:
                anagrams.append(ana)
        return (jsonify({'anagrams': anagrams}), HTTPStatus.OK)

    @app.route('/anagrams/test', methods=('POST', ))
    def test_anagrams(word):
        words = request.get_json(force=True)['words']
        return (jsonify({'anagrams':
                         anagramizer.are_anagrams(words)}), HTTPStatus.OK)

    @app.route('/anagrams/stats', methods=(
        'GET',
        'POST',
    ))
    def get_stats():
        if not anagramizer.stats['latest']:
            anagramizer.calc_stats()
        return (jsonify(anagramizer.stats), HTTPStatus.OK)

    return app


# grab the dictionary file otherwise assume it stored in cwd
dictionary_file = os.getenv('ANAGAMIZER_DICTIONARY', '.dictionary_cache.gz')

# initialize the corpus
anagramizer = Anagramizer(dictionary_file)

application = create_app()
atexit.register(anagramizer._save_to_file, dictionary_file, compress=True)
Beispiel #6
0
def main():
    file = WordList('wordsEn.txt')
    a = Anagramizer('more money', file)
    anagrams = a.generateAnagrams()
    print(anagrams)
Beispiel #7
0
def test_remove_all_words():
    a = Anagramizer('tests/data/test_initialization.txt')
    assert len(a._words) > 0
    a.remove_all()
    assert len(a._words) == 0
Beispiel #8
0
def test_add_existing_word_to_dict(initial_expected_structure):
    a = Anagramizer('tests/data/test_initialization.txt')
    assert a.add_word('dear')
    assert a._words == initial_expected_structure
Beispiel #9
0
def test_empty_initialization(initial_expected_structure):
    a = Anagramizer('')
    assert a._words == {}
Beispiel #10
0
def test_gzip_initialization(initial_expected_structure):
    a = Anagramizer('tests/data/test_initialization.txt.gz')
    assert a._words == initial_expected_structure
Beispiel #11
0
def test_are_anagrams(words, expected):
    a = Anagramizer()
    assert a.are_anagrams(words) == expected
Beispiel #12
0
def test_getting_anagrams(word, limit, include_proper, expected_list):
    a = Anagramizer('tests/data/test_initialization.txt')
    assert a.get_anagrams(word, limit, include_proper) == expected_list
Beispiel #13
0
def test_word_exists(word, expected):
    a = Anagramizer('tests/data/test_initialization.txt')
    assert a._word_exists(word) == expected
Beispiel #14
0
def test_word_list():
    a = Anagramizer('tests/data/test_initialization.txt')
    expected = [
        'Adam', 'Mat', 'apple', 'art', 'dear', 'mat', 'rat', 'read', 'tar'
    ]
    assert a.word_list() == expected