diff --git a/README.md b/README.md index 6a4f722..336782f 100644 --- a/README.md +++ b/README.md @@ -25,15 +25,4 @@ python main.py ``` *** - -this program shows you the results of insertion and merge sorts for each algorithm, it also shows some additional information, such as: -* time, -* swap counter, -* comparison counter. - -counters represent the numbers of corresponding operations that occurred during the sorting process. - -the list of objects is taken from *basin.csv* file. Each row there represents a new object as a sequence of its properties' values separated by commas. The order is: -``` -address, volume_of_water, max_number_of_visitors -``` +Цей код шукає підстрічки у стрічці за допомогою наївного алгоритму. diff --git a/main.py b/main.py new file mode 100644 index 0000000..e1d2cbf --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ +def naive_search(string: str, substring: str) -> list: + result = [] + if string is not None and substring is not None and len(string) >= len(substring) and len(substring) != 0: + for element in range(len(string) - len(substring) + 1): + for sub_element in range(len(substring)): + if not string[element + sub_element] == substring[sub_element]: + break + else: + result.append((element, element + len(substring))) + return result \ No newline at end of file diff --git a/tests.py b/tests.py new file mode 100644 index 0000000..56ce760 --- /dev/null +++ b/tests.py @@ -0,0 +1,23 @@ +import unittest + +from main import naive_search + + +class MyTestCase(unittest.TestCase): + def test_naive_search(self): + self.assertEqual(naive_search("aabaacaadaabaaba", "aaba"), [(0, 4), (9, 13), (12, 16)]) + self.assertEqual(naive_search("AABCCAADDEE", "FAA"), []) + self.assertEqual(naive_search("AAAAAAA", "AAAA"), [(0, 4), (1, 5), (2, 6), (3, 7)]) + self.assertEqual(naive_search("AAAAAAAAAAAAAAAAAB", "AAAB"), [(14, 18)]) + + def test_empty_string(self): + self.assertEqual(naive_search("","abc"), []) + + def test_empty_substr(self): + self.assertEqual(naive_search("abc",""),[]) + + + + +if __name__ == '__main__': + unittest.main()