class Test_WordStat(unittest.TestCase): def setUp(self): s = 'The President said he will ask Congress to increase grants'\ ' to states for vocational rehabilitation' self.w = WordStat(s) def test_WordStat(self): check_fd = [{'word_freq': 1, 'word_pos': 'v', 'word': 'ask'}, {'word_freq': 1, 'word_pos': 'n', 'word': 'congress'}, {'word_freq': 1, 'word_pos': 'n', 'word': 'grant'}, {'word_freq': 1, 'word_pos': 'v', 'word': 'increase'}, {'word_freq': 1, 'word_pos': 'n', 'word': 'president'}, {'word_freq': 1, 'word_pos': 'n', 'word': 'rehabilitation'}, {'word_freq': 1, 'word_pos': 'v', 'word': 'say'}, {'word_freq': 1, 'word_pos': 'n', 'word': 'state'}, {'word_freq': 1, 'word_pos': 'a', 'word': 'vocational'}] self.w.process() test_fd = self.w.freq_dist test_fd.sort(key=lambda x: x['word']) # sort alphabetically by words self.assertEqual(test_fd, check_fd)
def setUp(self): s = 'The President said he will ask Congress to increase grants'\ ' to states for vocational rehabilitation' self.w = WordStat(s)