def test_change_pattern(self):
        _filename = "line_feeder_integrationtest_file.txt"
        file = open(_filename, 'w')
        file.write("aaaa\n\naa\naaa")
        file.close()

        pattern = "a"
        algorithm = BoyerMoore(self._get_heuristic(), pattern)
        lf = LineFeeder(algorithm, _filename)
        res = lf.get_results()
        self.assertEqual(res, [0, 1, 2, 3, 4, 5, 6, 7, 8])
        pattern = "aa"
        algorithm.set_pattern(pattern)
        lf = LineFeeder(algorithm, _filename)
        res = lf.get_results()
        self.assertEqual(res, [0, 1, 2, 3, 4, 5, 6, 7])
        os.remove(_filename)
    def test_find_single_match(self):
        _filename = "line_feeder_integrationtest_file.txt"
        file = open(_filename, 'w')
        file.write("asdjasd\nvhajsdv\najsdbh\nasjd\n asdbha sjasdjasv\nbdjas")
        file.close()

        pattern = "jasdj"
        algorithm = BoyerMoore(self._get_heuristic(), pattern)
        lf = LineFeeder(algorithm, _filename)
        res = lf.get_results()
        self.assertEqual(res, [33])
        os.remove(_filename)
Пример #3
0
def read_arguments(arg_list):
    algo_list = []
    comb_list = []
    reading_heur = False
    reading_comb = False
    reading_path_pattern = True
    path = ''
    pattern = ''
    for arg in arg_list:
        if '-h' in arg:
            reading_heur = True
            reading_comb = False
        elif '-c' in arg:
            reading_heur = False
            reading_comb = True
        elif reading_comb:
            if reading_path_pattern:
                path = arg
                if not os.path.isfile(path):
                    raise Exception("File (" + path + ") doesn't exist")
            else:
                pattern = arg
                comb_list.append((path, pattern))
            reading_path_pattern = not reading_path_pattern
        elif reading_heur:
            if '+' in arg:
                if any(composite_part not in heur_dict
                       for composite_part in arg.split('+')):
                    raise Exception('Wrong input for heuristic')
                c_h_list = [
                    heur_dict[composite_part]()
                    for composite_part in arg.split('+')
                ]
                algo_list.append(BoyerMoore(CompositeHeuristic(c_h_list)))
            else:
                if arg not in heur_dict:
                    raise Exception('Wrong input for heuristic')
                algo_list.append(BoyerMoore(heur_dict[arg]()))

    return algo_list, comb_list
    def test_more_match(self):
        _filename = "line_feeder_integrationtest_file.txt"
        file = open(_filename, 'w')
        file.write(
            "\nasaj\nakvhajsdajakvvajsd\nbajakvhas\njd asajakvdbha sjasdjaja\nkvasvbd\njas\n\n\n"
        )
        file.close()

        pattern = "ajakv"
        algorithm = BoyerMoore(self._get_heuristic(), pattern)
        lf = LineFeeder(algorithm, _filename)
        res = lf.get_results()
        self.assertEqual(res, [2, 12, 23, 36, 52])
        os.remove(_filename)
Пример #5
0
 def test_change_text(self):
     text = "aaaaaaaaa"
     pattern = "a"
     algorithm = BoyerMoore(self._get_heuristic(), pattern, text)
     res = algorithm.get_results()
     self.assertEqual(res, [0, 1, 2, 3, 4, 5, 6, 7, 8])
     text = "bbbbbbbbbbbbbbb"
     algorithm.set_text(text)
     res = algorithm.get_results()
     self.assertEqual(res, [])
Пример #6
0
 def test_single_letter(self):
     text = "aaaaaaaaa"
     pattern = "a"
     algorithm = BoyerMoore(self._get_heuristic(), pattern, text)
     res = algorithm.get_results()
     self.assertEqual(res, [0, 1, 2, 3, 4, 5, 6, 7, 8])
Пример #7
0
 def test_more_match(self):
     text = "asajakvhajsdajakvvajsdbajakvhasjd asajakvdbha sjasdjajakvasvbdjas"
     pattern = "ajakv"
     algorithm = BoyerMoore(self._get_heuristic(), pattern, text)
     res = algorithm.get_results()
     self.assertEqual(res, [2, 12, 23, 36, 52])
Пример #8
0
 def test_find_no_match(self):
     text = "asdjasdvhajsdvajsdbhasjd asdbha sjasdjasvbdjas"
     pattern = "asff"
     algorithm = BoyerMoore(self._get_heuristic(), pattern, text)
     res = algorithm.get_results()
     self.assertEqual(res, [])