Skip to content
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Темы: Git и GitHub, стандарты оформления кода, хорошие практики, тестирование.

Фамилия, имя: Бугаев Илья

Группа: 25.Б-42


## Этапы выполнения работы

- Сделать **fork** этого репозитория
Expand Down
Binary file added src/__pycache__/checksum.cpython-312.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions src/bin_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def binSearch(xs: list[int], x: int):
def bin_search(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
Expand Down
26 changes: 20 additions & 6 deletions src/checksum.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
def modulo11Checksum(ISBNNumber: str):
def modulo11_checksum(is_bn_number: str):

digits = [int(char) for char in ISBNNumber if char.isdigit()]
if not isbn_number or not isinstance(isbn_number, str):
Copy link

Choose a reason for hiding this comment

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

Ошибка в isbn_number, в функции аргумент назывался is_bn_number.

raise ValueError("Invalid input: must be non-empty string")


checkDigit = digits[-1]
digits = [int(char) for char in is_bn_number if char.isdigit()]

check_digit = digits[-1]

total = 0
for i in range(len(digits) - 1):
weight = 10
weight = 10 - i
digit = digits[i]
total += digit * weight
Comment on lines +7 to 15
Copy link

Choose a reason for hiding this comment

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

У Вас пропущена обработка символа X, который может служить контрольной цифрой.


checksum = total + checkDigit
return checksum % 11 == 0
checksum = total % 11
return checksum == check_digit
Comment on lines +17 to +18
Copy link

Choose a reason for hiding this comment

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

Ошибка в логике.
Нужно было либо оставить checksum = total + checkDigit и сравнивать остаток от деления на 11 с 0.
Либо высчитывать вот так (11 - (sum % 11)) % 11 и тогда уже сравнивать с контрольной цифрой.



while True:
isbn = input("ISBN: ").strip()
if isbn == "-1":
break
if check_isbn(isbn):
Copy link

Choose a reason for hiding this comment

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

У Вас функция называется modulo11_checksum.

print("correct")
else:
print("incorrect")
Comment on lines +21 to +28
Copy link

Choose a reason for hiding this comment

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

Когда pytest импортирует этот файл для тестов, он зависнет, ожидая ввода данных.
Код, который относится к запуску нужно оборачивать в if __name__ == "__main__".

Comment on lines +21 to +28
Copy link

Choose a reason for hiding this comment

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

Нужен блок try-except, который при ошибке уведомлял бы пользователя о сбое в работе, но программа при этом не падала.

Binary file not shown.
16 changes: 12 additions & 4 deletions test/test_bin_searh.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from src.bin_search import binSearch
from src.bin_search import bin_search


def test_middle():
assert binSearch([1, 2, 3, 4, 5], 4) == 3
assert bin_search([1, 2, 3, 4, 5], 3) == 2


def test_start():
assert binSearch([1, 2, 3, 4], 2) == 1
assert bin_search([1, 2, 3, 4], 1) == 0
assert bin_search([1, 2, 3, 4], 2) == 1


def test_end():
assert bin_search([1, 2, 3, 4, 5], 5) == 4
assert bin_search([1, 2, 3, 4], 4) == 3


def test_not_in_list():
assert binSearch([1, 2, 3, 4], 5) == -1
assert bin_search([1, 2, 3, 4], 5) == -1
assert bin_search([1, 2, 3, 4], 0) == -1
assert bin_search([1, 2, 3, 4], 6) == -1
21 changes: 16 additions & 5 deletions test/test_checksum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from src.checksum import modulo11Checksum
from src.checksum import modulo11_checksum

def test_valid_isbn10_with_hyphens():
#Тесты с дефисами
assert modulo11_checksum("2-266-11156-8")
assert modulo11_checksum("0-7475-3269-9")
assert modulo11_checksum("1-56619-909-3")

def test_good():
assert modulo11Checksum("2-266-11156-8")

def test_valid_isbn10_without_hyphens():
#Тест без дефисов
assert modulo11_checksum("2266111568")
assert modulo11_checksum("0747532699")
assert modulo11_checksum("1566199093")

def test_bad():
assert not modulo11Checksum("2-266-11156-3")
def test_invalid_isbn10():
#Тесты невалидности
assert not modulo11_checksum("2-266-11156-3")
assert not modulo11_checksum("0-7475-3269-8")
assert not modulo11_checksum("1566199095")