Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Цей код шукає підстрічки у стрічці за допомогою наївного алгоритму.
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -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]:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use inverted logic here in order to avoid 'else' statement

break
else:
result.append((element, element + len(substring)))
return result
23 changes: 23 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -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()