-
Notifications
You must be signed in to change notification settings - Fork 22
Кузьмищев Леонид Сергеевич 25Б-42 #15
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
Draft
leonilkuz-13
wants to merge
9
commits into
python-course-matmex:main
Choose a base branch
from
leonilkuz-13:test_branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38fe174
Correction of variable names and function names according to the styl…
leonilkuz-13 e07dd28
Fixing a bug in binary search
leonilkuz-13 28eb0c9
Fixed a bug in binary search when passing an empty array.
leonilkuz-13 e548865
Correcting tests and adding new ones.
leonilkuz-13 8ad7213
fixing the order of imports
leonilkuz-13 88828ce
bug fixes checksum
leonilkuz-13 b002d3c
fixes test and add test
leonilkuz-13 674f828
utility added
leonilkuz-13 542a252
add README
leonilkuz-13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,3 @@ | ||
| # Контрольная работа 1 (2 вариант) | ||
|
|
||
| Темы: Git и GitHub, стандарты оформления кода, хорошие практики, тестирование. | ||
|
|
||
| ## Этапы выполнения работы | ||
|
|
||
| - Сделать **fork** этого репозитория | ||
| - Добавить недостающие файлы для "хорошо оформленного" репозитория | ||
| - Исправить ошибки, из-за которых не проходит CI | ||
| - Найти и исправить баг(и), которые есть в `src/checksum.py` и `src/bin_search.py` | ||
| - Добавить исключения в соответствующих случаях (например, когда когда поиск) | ||
| - Исправить и/или дополнить тесты так, чтобы они покрывали найденные ошибки | ||
| - Для каждого бага должен быть отдельный **commit** с его исправлением, в его описании должно быть пояснение (можно на русском) решённой проблемы | ||
| - На основе [ISBN10](https://ru.wikipedia.org/wiki/%D0%9C%D0%B5%D0%B6%D0%B4%D1%83%D0%BD%D0%B0%D1%80%D0%BE%D0%B4%D0%BD%D1%8B%D0%B9_%D1%81%D1%82%D0%B0%D0%BD%D0%B4%D0%B0%D1%80%D1%82%D0%BD%D1%8B%D0%B9_%D0%BA%D0%BD%D0%B8%D0%B6%D0%BD%D1%8B%D0%B9_%D0%BD%D0%BE%D0%BC%D0%B5%D1%80) реализовать простую консольную утилиту | ||
| - Пользователь вводит в консоль номер ISBN $\to$ ему выводится "correct" или "incorrect" в зависимости от правильности номера | ||
| - Выход из утилиты происходит по вводу пользователем `-1` | ||
| - Ошибки не должны прерывать прерывать работу утилиты, но пользователь должен быть уведомлен о том, что он сделал что-то не так | ||
| - Реализация утилиты должна быть в модуле `src/checksum.py` | ||
| - Сделать **pull request** (один на обе задачи) с решением в main ветку этого репозитория | ||
| - **pull request** должен содержать описание проделанной работы, ваше ФИО и номер группы | ||
| - Если не получилось/забыли сделать адекватное описание исправленных ошибок в описании к **commit**, то нужно сделать это хотя бы в комментариях к **pull request** | ||
| **ФИО**: Кузьмищев Леонид Сергеевич | ||
| **Группа**: 25Б-42 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,39 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
| def modulo11_checksum(isbn_number: str): | ||
| def correct_number(isbn_number): | ||
| digits = [] | ||
| for i in isbn_number: | ||
| if i.isdigit(): | ||
| digits.append(int(i)) | ||
| elif i.upper() == "X" and len(digits) == 9: | ||
| digits.append(10) | ||
| elif i != "-": | ||
| return None | ||
| return digits if len(digits) == 10 else None | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
|
|
||
| checkDigit = digits[-1] | ||
| digits = correct_number(isbn_number) | ||
| if digits is None: | ||
| return False | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| digit = digits[i] | ||
| total += digit * weight | ||
| for i in range(9): | ||
| weight = 10 - i | ||
| total += digits[i] * (weight) | ||
|
|
||
| total += digits[-1] | ||
|
|
||
| return total % 11 == 0 | ||
|
|
||
|
|
||
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
| print("Exit - -1") | ||
| print("To enter, enter any number") | ||
| string = input() | ||
| while True: | ||
| print("enter ISBN_number or came out") | ||
| if string == "-1": | ||
| print("you came out") | ||
| break | ||
| string = input() | ||
| if modulo11_checksum(string): | ||
| print("correct") | ||
| else: | ||
| print("incorrect") | ||
|
Comment on lines
+27
to
+39
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. Когда |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,32 @@ | ||
| from src.bin_search import binSearch | ||
| from contextlib import nullcontext as does_not_raise | ||
|
|
||
| import pytest | ||
|
|
||
| def test_middle(): | ||
| assert binSearch([1, 2, 3, 4, 5], 4) == 3 | ||
| from src.bin_search import bin_search | ||
|
|
||
|
|
||
| def test_start(): | ||
| assert binSearch([1, 2, 3, 4], 2) == 1 | ||
| class TestBin: | ||
| @pytest.mark.parametrize( | ||
| "array, digit, expected_index, expectation", | ||
| [ | ||
| ([1, 2, 3, 4, 5], 3, 2, does_not_raise()), | ||
| ([1, 2, 3, 4], 2, 1, does_not_raise()), | ||
| ([1, 2, 3, 4], 3, 2, does_not_raise()), | ||
| ([1], 1, 0, does_not_raise()), | ||
| ([1, 2], 1, 0, does_not_raise()), | ||
| ([1, 2], 2, 1, does_not_raise()), | ||
| ], | ||
| ) | ||
| def test_middle(self, array, digit, expected_index, expectation): | ||
| with expectation: | ||
| assert bin_search(array, digit) == expected_index | ||
|
|
||
| def test_start(self): | ||
| assert bin_search([1, 2, 3, 4], 2) == 1 | ||
|
|
||
| def test_not_in_list(): | ||
| assert binSearch([1, 2, 3, 4], 5) == -1 | ||
| def test_empty_list(self): | ||
| assert bin_search([], 1) == -1 | ||
|
|
||
| def test_incorrect_index(self): | ||
| assert bin_search([1, 2], 3) == -1 | ||
| assert bin_search([1, 2, 3, 4], 5) == -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| from src.checksum import modulo11Checksum | ||
| from src.checksum import modulo11_checksum | ||
|
|
||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-8") | ||
| assert modulo11_checksum("0-8044-2957-X") | ||
| assert modulo11_checksum("080442957X") | ||
|
|
||
|
|
||
| def test_bad(): | ||
| assert not modulo11Checksum("2-266-11156-3") | ||
| assert not modulo11_checksum("2-266-11156-3") | ||
| assert not modulo11_checksum("2-266-11156-8") | ||
| assert not modulo11_checksum("2266111568") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Рекомендация: при неверной длине строки (или других ошибках) лучше выбрасывать исключение, чтобы различать некорректный формат входных данных и просто невалидную контрольную сумму.
Тогда в вызывающем коде нужно будет добавить блок try-except.