Теврюков Илья Андреевич Б42#4
Conversation
…ht'. Added comprehensive test suite for binary search. Implemented ISBN validator utility. Fixed weight calculation from 'weight = 10' to 'weight = 10 - i'. Added necessary input validation and error handling. Extended test coverage for all components.
Godrik0
left a comment
There was a problem hiding this comment.
ISBN10: 3/10
Бинарный поиск: 2/5
Оформление кода: 3/10 (snake_case, лицензия, описание PR, .gitignore, нет обработки ошибок)
| right = mid - 1 | ||
| return -1 | ||
| def binSearch(xs: list[int], x: int): | ||
| xs = sorted(xs) |
There was a problem hiding this comment.
Бинарный поиск должен работать за
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
| def modulo11Checksum(ISBNNumber: str): | ||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] |
There was a problem hiding this comment.
У Вас пропущена обработка символа X, который может служить контрольной цифрой.
| def modulo11Checksum(ISBNNumber: str): | ||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
| if len(digits) != 10: | ||
| return -1 |
There was a problem hiding this comment.
Вы в одном месте возвращаете -1, а в другом bool. В Python -1 оценивается как True в булевом контексте.
|
|
||
|
|
||
| def test_good_with_x_check_digit(): | ||
| assert modulo11Checksum("0-304-33376-") |
There was a problem hiding this comment.
modulo11Checksum выкинет дефисы, получит 9 цифр, вернет -1, а assert сработает как True и тест пройдет.
| ISBNNumber = input() | ||
|
|
||
| while ISBNNumber != '-1': | ||
| res = modulo11Checksum(ISBNNumber) | ||
| if res == 1: | ||
| print('correct') | ||
| elif res == -1: | ||
| print('Incorrect number length') | ||
| else: | ||
| print('incorrect') | ||
| ISBNNumber = input() | ||
|
|
There was a problem hiding this comment.
Когда pytest импортирует этот файл для тестов, он зависнет, ожидая ввода данных.
Код, который относится к запуску нужно оборачивать в if __name__ == "__main__".
No description provided.