Example #1
0
 def test_count_url(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 = WordCount()
     self.assertEqual(
         handlers.UrlHandler("http://txt2html.sourceforge.net/sample.txt",
                             cnt_obj).count_word_occurance("sample"), 7)
Example #2
0
 def test_count_file(self):
     remove_results_file()
     cnt_obj = WordCount()
     curr_dir = os.getcwd()
     self.assertEqual(
         handlers.FileHandler(curr_dir + "/tests/sample.txt",
                              cnt_obj).count_distinct_words(), 319)
     cnt_obj = WordCount()
     self.assertEqual(
         handlers.FileHandler(curr_dir + "/tests/sample.txt",
                              cnt_obj).count_word_occurance("sample"), 7)
Example #3
0
 def test_count_string(self):
     remove_results_file()
     cnt_obj = WordCount()
     self.assertEqual(
         handlers.StringHandler(
             "Hi! My name is (what?), my name is (who?), my name is Slim Shady",
             cnt_obj).count_distinct_words(), 5)
     cnt_obj = WordCount()
     self.assertEqual(
         handlers.StringHandler(
             "Hi! My name is (what?), my name is (who?), my name is Slim Shady",
             cnt_obj).count_word_occurance("my"), 3)
Example #4
0
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()
Example #5
0
 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)
Example #6
0
 def test_string_input(self):
     cnt_obj = WordCount()
     self.assertIsInstance(
         InputFactory().create_input_obj("bla bla", cnt_obj),
         handlers.StringHandler)
     self.assertIsInstance(
         InputFactory().create_input_obj(
             "Hi! My name is (what?), my name is (who?), my name is Slim Shady",
             cnt_obj), handlers.StringHandler)
Example #7
0
 def test_url_input(self):
     cnt_obj = WordCount()
     self.assertIsInstance(
         InputFactory().create_input_obj(
             "http://txt2html.sourceforge.net/sample.txt", cnt_obj),
         handlers.UrlHandler)
Example #8
0
 def test_file_input(self):
     cnt_obj = WordCount()
     curr_dir = os.getcwd()
     self.assertIsInstance(
         InputFactory().create_input_obj(curr_dir + "/tests/sample.txt",
                                         cnt_obj), handlers.FileHandler)