From edc0257ff4a20d28ca2f881cd944e549da87b95f Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 16:16:26 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=B1=D0=B8=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin_search.py b/src/bin_search.py index 713abfc..3c91f7d 100644 --- a/src/bin_search.py +++ b/src/bin_search.py @@ -1,6 +1,6 @@ def binSearch(xs: list[int], x: int): left, right = 0, len(xs) - 1 - while left < right: + while left <= right: mid = (left + right) // 2 if xs[mid] == x: return mid From 16fad32858e6bdc6f4ebba3f683466c43c35747e Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 16:20:48 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test_bin_search.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test_bin_search.py diff --git a/src/test_bin_search.py b/src/test_bin_search.py new file mode 100644 index 0000000..e7b22b5 --- /dev/null +++ b/src/test_bin_search.py @@ -0,0 +1,36 @@ +from bin_search import binSearch +import pytest +import random + + +def test_nothing(): + ls = [] + x = random.randint(-1000, 1000) + assert binSearch(ls, x) == -1 + + +def test_one(): + ls = [2] + assert binSearch(ls, ls[0]) == 0 + + +def test_next(): + ls = [1, 2, 3, 4, 5] + assert binSearch(ls, ls[3]) == 3 + + +def test_all(): + ls = [x for x in range(0, 100)] + x = random.randint(0, 100) + + assert binSearch(ls, ls[x]) == x + +def test_all2(): + ls = [x for x in range(0, 100)] + x = random.randint(102, 1000) + + assert binSearch(ls, x) == -1 + + +if __name__ == '__main__': + pytest.main() From 11a8d759000b8b6e72f2e93ab34cfc5632a56852 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 16:41:10 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=B2=D0=B5=D1=81=D0=BE=D0=BC=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checksum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/checksum.py b/src/checksum.py index 74b4fb0..a6100ba 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -6,7 +6,7 @@ def modulo11Checksum(ISBNNumber: str): total = 0 for i in range(len(digits) - 1): - weight = 10 + weight = 10 - i digit = digits[i] total += digit * weight From 15f5f348ddaac37bb3b87f4a6cbf4b55a2051705 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 16:41:40 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=87=D0=B5=D0=BA=20=D1=81=D1=83=D0=BC=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test_checksum.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test_checksum.py diff --git a/src/test_checksum.py b/src/test_checksum.py new file mode 100644 index 0000000..7b9d5fa --- /dev/null +++ b/src/test_checksum.py @@ -0,0 +1,23 @@ +from checksum import modulo11Checksum +import pytest + +def test1(): + num = "99921-58-10-7" + assert modulo11Checksum(num) == True + + +def test1_wrong(): + num = "99921-58-10-4" + assert modulo11Checksum(num) == False + +def test_wiki(): + num = "2-266-11156-6" + assert modulo11Checksum(num) == True + + +def test_wiki_wrong(): + num = "2-266-11156-3" + assert modulo11Checksum(num) == False + +if __name__ == '__main__': + pytest.main() From 3cf8d178b6a5fd74903f55cb65608250fd697ea9 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 16:58:06 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D0=BF=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D0=BE=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checksum.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/checksum.py b/src/checksum.py index a6100ba..838002b 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -1,7 +1,11 @@ def modulo11Checksum(ISBNNumber: str): digits = [int(char) for char in ISBNNumber if char.isdigit()] - + + if len(digits) != 10: + print("Цифр должно быть 10", end=' - ') + return + checkDigit = digits[-1] total = 0 @@ -12,3 +16,17 @@ def modulo11Checksum(ISBNNumber: str): checksum = total + checkDigit return checksum % 11 == 0 + + +num = input() + +while num != "-1": + res = modulo11Checksum(num) + + if res: + print("correct") + + else: + print("incorrect") + + num = input() From 58f292826f0e7a81586e8e2ba4e0414375df1789 Mon Sep 17 00:00:00 2001 From: stuffacc Date: Fri, 7 Nov 2025 17:05:46 +0300 Subject: [PATCH 6/6] ruff fix --- .github/workflows/ruff.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 164630d..c12fb02 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -1,8 +1,18 @@ name: Ruff -on: [push, pull_request] +on: push jobs: - ruff: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: astral-sh/ruff-action@v3 + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: "3.12.3" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + # Update output format to enable automatic inline annotations. + - name: Run Ruff + run: ruff check --output-format=github .