def app(): cnt_obj = WordCount() input_mode = sys.argv[1] if AppModeEnum(input_mode) == AppModeEnum.UNIQ_CNT: input_obj = process_input(sys.argv[2:], False, cnt_obj) print(FIRST_RESULT_MSG + str(input_obj.count_distinct_words()) + "\n") elif AppModeEnum(input_mode) == AppModeEnum.SPEC_CNT: input_obj = process_input(sys.argv[2:], True, cnt_obj) word_as_input = sys.argv[-1] print(SECOND_RESULT_MSG + str(input_obj.count_word_occurance(word_as_input)) + "\n") cnt_obj.serialize()
def test_persist_results(self): remove_results_file() cnt_obj = WordCount() self.assertEqual( handlers.UrlHandler("http://txt2html.sourceforge.net/sample.txt", cnt_obj).count_distinct_words(), 319) cnt_obj.serialize() cnt_obj.deserialize() self.assertEqual( handlers.UrlHandler("http://txt2html.sourceforge.net/sample.txt", cnt_obj).count_distinct_words(), 0) cnt_obj.serialize() cnt_obj.deserialize() self.assertEqual( handlers.StringHandler("sample", cnt_obj).count_word_occurance("sample"), 15)