-
Notifications
You must be signed in to change notification settings - Fork 22
Б42 контрольная #6
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
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 |
|---|---|---|
| @@ -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 . |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,32 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
|
|
||
|
|
||
| if len(digits) != 10: | ||
| print("Цифр должно быть 10", end=' - ') | ||
| return | ||
|
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. Это вернет |
||
|
|
||
|
Comment on lines
+5
to
+8
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 | ||
|
|
||
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
|
|
||
|
|
||
| num = input() | ||
|
|
||
| while num != "-1": | ||
| res = modulo11Checksum(num) | ||
|
|
||
| if res: | ||
| print("correct") | ||
|
|
||
| else: | ||
| print("incorrect") | ||
|
|
||
| num = input() | ||
|
Comment on lines
+21
to
+32
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 commentThe reason will be displayed to describe this comment to others. Learn more. А что не так с тестами из папки |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from checksum import modulo11Checksum | ||
| import pytest | ||
|
|
||
| def test1(): | ||
| num = "99921-58-10-7" | ||
| assert modulo11Checksum(num) == True | ||
|
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. Правильно писать |
||
|
|
||
|
|
||
| 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() | ||
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.
Такое не должно выводиться принтом, тут следовало кинуть исключение.