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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "3.12"

- name: Install dependencies
run: |
Expand Down
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
*.so

# Virtual environments
venv/
env/
.venv/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Testing
.pytest_cache/
.coverage
htmlcov/

# Project-specific
*.log
temp/
tmp/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Elizaveta Menshikova

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 5 additions & 1 deletion src/bin_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
def binSearch(xs: list[int], x: int):
if x not in xs:
raise ValueError("такого элемента нет")
if xs != sorted(xs):
raise ValueError("Массив не отсортирован")
Comment on lines +2 to +5
Copy link

Choose a reason for hiding this comment

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

Эти проверки полностью лишают смысла весь алгоритм. Поиск в xs имеет сложность $O(N)$, сортировка имеет сложность $O(N \log{N})$.
Можно было проверять, что x имеет тип int.

left, right = 0, len(xs) - 1
while left < right:
while left <= right:
mid = (left + right) // 2
if xs[mid] == x:
return mid
Expand Down
11 changes: 11 additions & 0 deletions test/test_bin_searh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from src.bin_search import binSearch


Expand All @@ -11,3 +12,13 @@ def test_start():

def test_not_in_list():
assert binSearch([1, 2, 3, 4], 5) == -1
Comment on lines 13 to 14
Copy link

Choose a reason for hiding this comment

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

В текущей реализации метода, этот тест неверен. У вас бросается ошибка если элемента нет, а тут ожидается -1.



def test_unsorted():
with pytest.raises(ValueError, match="Массив не отсортирован"):
binSearch([8, 3, 6, 1], 6)


def test_unsorted():
with pytest.raises(ValueError, match="такого элемента нет"):
binSearch([1, 2, 3], 9)
Comment on lines +17 to +24
Copy link

Choose a reason for hiding this comment

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

Тесты имеют одинаковое название, вторая функция перезапишет первую.

1 change: 1 addition & 0 deletions test/test_checksum.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from src.checksum import modulo11Checksum


Expand Down