-
Notifications
You must be signed in to change notification settings - Fork 22
Ашихмина Людмила Александровна Б42 #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
68667e1
c927cbf
1480c2e
3136461
7aaf603
5dce1ac
8b652f5
befee25
29743d5
875eee6
f92d27d
1400210
902baf0
e4cf9d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,5 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: astral-sh/ruff-action@v3 | ||
| - run: ruff check . | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. В задании требовалось также реализовать консольную утилиту. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,23 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
| digits = [] | ||
| for char in ISBNNumber: | ||
| if char.isdigit(): | ||
| digits.append(int(char)) | ||
| elif (len(digits) == 9) and char == 'X': | ||
| digits.append(10) | ||
| elif char != '-' and char != ' ': | ||
| return False | ||
|
|
||
|
|
||
| if len(digits) != 10: | ||
| return False | ||
|
Comment on lines
+9
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Рекомендация: при неверной длине строки (или других ошибках) лучше выбрасывать исключение, чтобы различать некорректный формат входных данных и просто невалидную контрольную сумму. |
||
|
|
||
| checkDigit = digits[-1] | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| weight = 10 - i | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не хватает тестов на пустой массив, на массив из 1 элемента. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| from src.checksum import modulo11Checksum | ||
|
|
||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-8") | ||
|
|
||
|
|
||
| def test_bad(): | ||
| assert not modulo11Checksum("2-266-11156-3") | ||
| assert not modulo11Checksum("2-266-11156-8") | ||
| assert not modulo11Checksum("1-563-9873X-X") | ||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-3") | ||
| assert modulo11Checksum("1-563-68745-X") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно бросать исключение. Такой
returnможет быть неожиданным для пользователя, потому что он ожидает, что возвращаемым значением будет число, а возвращается строка.