diff --git a/README.md b/README.md index e93444f..b43c084 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ Темы: Git и GitHub, стандарты оформления кода, хорошие практики, тестирование. +Фамилия, имя: Бугаев Илья + +Группа: 25.Б-42 + + ## Этапы выполнения работы - Сделать **fork** этого репозитория diff --git a/src/__pycache__/checksum.cpython-312.pyc b/src/__pycache__/checksum.cpython-312.pyc new file mode 100644 index 0000000..59c8d2e Binary files /dev/null and b/src/__pycache__/checksum.cpython-312.pyc differ diff --git a/src/bin_search.py b/src/bin_search.py index 713abfc..3249226 100644 --- a/src/bin_search.py +++ b/src/bin_search.py @@ -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 diff --git a/src/checksum.py b/src/checksum.py index 74b4fb0..5905eb9 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -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): + 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 - checksum = total + checkDigit - return checksum % 11 == 0 + checksum = total % 11 + return checksum == check_digit + + +while True: + isbn = input("ISBN: ").strip() + if isbn == "-1": + break + if check_isbn(isbn): + print("correct") + else: + print("incorrect") diff --git a/test/__pycache__/test_checksum.cpython-312-pytest-8.4.2.pyc b/test/__pycache__/test_checksum.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000..a98ba6c Binary files /dev/null and b/test/__pycache__/test_checksum.cpython-312-pytest-8.4.2.pyc differ diff --git a/test/test_bin_searh.py b/test/test_bin_searh.py index d18d85b..b513ef9 100644 --- a/test/test_bin_searh.py +++ b/test/test_bin_searh.py @@ -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 diff --git a/test/test_checksum.py b/test/test_checksum.py index f64a64c..3eae4ad 100644 --- a/test/test_checksum.py +++ b/test/test_checksum.py @@ -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")