def test_frequency(): '''Test the frequency method''' ngram_freq = NgramFrequencies(1, '') ngram_freq.dic_ngram["a"] = 3 ngram_freq.dic_ngram["c"] = 2 ngram_freq.dic_ngram["e"] = 6 ngram_freq.total_count = 11 new_dic = ngram_freq.frequency() assert new_dic["a"] == round(3 / 11, 3)
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_frequency(): """test frequency calculation""" ngrams = NgramFrequencies() freq = ngrams.frequency(2, 10) assert freq == 0.2