diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d09842c..5908b8f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: | diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d0c924 --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d564eb6 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/src/bin_search.py b/src/bin_search.py index 713abfc..c55ccbb 100644 --- a/src/bin_search.py +++ b/src/bin_search.py @@ -1,6 +1,10 @@ def binSearch(xs: list[int], x: int): + if x not in xs: + raise ValueError("такого элемента нет") + if xs != sorted(xs): + raise ValueError("Массив не отсортирован") left, right = 0, len(xs) - 1 - while left < right: + while left <= right: mid = (left + right) // 2 if xs[mid] == x: return mid diff --git a/test/test_bin_searh.py b/test/test_bin_searh.py index d18d85b..9ad49cd 100644 --- a/test/test_bin_searh.py +++ b/test/test_bin_searh.py @@ -1,3 +1,4 @@ +import pytest from src.bin_search import binSearch @@ -11,3 +12,13 @@ def test_start(): def test_not_in_list(): assert binSearch([1, 2, 3, 4], 5) == -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) diff --git a/test/test_checksum.py b/test/test_checksum.py index f64a64c..d7d7a3f 100644 --- a/test/test_checksum.py +++ b/test/test_checksum.py @@ -1,3 +1,4 @@ +import pytest from src.checksum import modulo11Checksum