def test_top_n_counts(): '''Test the top n counts method''' ngram_freq = NgramFrequencies(1, '') ngram_freq.dic_ngram["ab"] = 3 ngram_freq.dic_ngram["cd"] = 2 ngram_freq.dic_ngram["ef"] = 6 list_top_count = ngram_freq.top_n_counts(3) assert list_top_count[0][0] == "ef" assert list_top_count[1][0] == "ab" assert list_top_count[2][0] == "cd"
def test_ngram_frequencies(): nf = NgramFrequencies(2) assert nf.add_item("He_is") == 1 assert nf.add_item("He_is") == 2 assert nf.add_item("He_is") == 3 assert nf.add_item("I_am") == 1 assert nf.add_item("I_am") == 2 assert nf.add_item("I_am") == 3 assert nf.add_item("I_am") == 4 assert nf.add_item("I_am") == 5 assert nf.add_item("I_am") == 6 assert nf.add_item("They_are") == 1 assert nf.frequency("They_are") == 0.1 assert nf.top_n_counts() == [("I_am", 6), ("He_is", 3)] assert nf.top_n_freqs() == [("I_am", 0.6), ("He_is", 0.3)]
def test_top_n_counts(): """test returning a list of items sorted on the count""" ngrams = NgramFrequencies() new_dic = {"a": 1, "b": 2, "c": 3, "d": 4} top_list = ngrams.top_n_counts(new_dic) assert top_list == [("d", 4), ("c", 3), ("b", 2), ("a", 1)]