From 566db4bf59120d3a0571349ea7f2ea1b907d9b5e Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Thu, 23 Oct 2025 14:19:43 +0300 Subject: [PATCH 1/5] Add LiCENSE gitignore and pyversion --- .gitignore | 176 ++++++++++++++++++++++++++++++++++++++++++++++++ .python-version | 1 + LICENSE | 21 ++++++ 3 files changed, 198 insertions(+) create mode 100644 .gitignore create mode 100644 .python-version create mode 100644 LICENSE diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad4a1f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,176 @@ +# Created by https://www.toptal.com/developers/gitignore/api/python +# Edit at https://www.toptal.com/developers/gitignore?templates=python + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +# End of https://www.toptal.com/developers/gitignore/api/python diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..f779e2b --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +Python 3.13.7 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bde871e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Kalsina Yana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From f66d516f6bd51af089109a52b0229e5b8a204b05 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Thu, 23 Oct 2025 14:28:39 +0300 Subject: [PATCH 2/5] Fix tests anf ruff --- .github/workflows/ruff.yml | 12 +++++++++++- .github/workflows/tests.yml | 8 +++----- LICENSE | 2 -- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 164630d..6a92dff 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -1,8 +1,18 @@ name: Ruff on: [push, pull_request] jobs: - ruff: + built: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Install Python - uses: astral-sh/ruff-action@v3 + with: + python-version: "3.11" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + - name: Run Ruff + run: ruff check --output-format=github . + diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d09842c..a594187 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,8 +8,7 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python + - name: Install Python uses: actions/setup-python@v5 with: python-version: "3.13" @@ -19,6 +18,5 @@ jobs: python -m pip install --upgrade pip pip install pytest - - name: Run Pytest tests - run: | - pytest -v + - name: Run tests + run: PYTHONPATH=.:$PYTHONPATH pytest -v diff --git a/LICENSE b/LICENSE index bde871e..9cf1062 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,5 @@ MIT License -Copyright (c) 2025 Kalsina Yana - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights From 2122ca79ca44b78f6924de6791437b9225c4a2a9 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Thu, 23 Oct 2025 14:41:02 +0300 Subject: [PATCH 3/5] Slightly changed the algorithm so it works correctly --- src/fast_pow.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 1ba1dc1..9207d20 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -1,6 +1,7 @@ def fastPow(number, power): - result = number - while power != 1: - result *= result - power = power // 2 + result = 1 + while power != 0: + result *= number + power = power - 1 return result + From 3687ac42d12db4eea5541f90f33c1725e6250421 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Thu, 23 Oct 2025 14:53:28 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20=D0=B2=D1=8B=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_fast_pow.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/test_fast_pow.py b/test/test_fast_pow.py index 5e4aebd..593d899 100644 --- a/test/test_fast_pow.py +++ b/test/test_fast_pow.py @@ -1,4 +1,5 @@ -from src.fast_pow import fastPow +from src.fast_pow import fastPow, MyException +from pytest import raises def test_two_power_two(): @@ -7,3 +8,20 @@ def test_two_power_two(): def test_negative(): assert fastPow(-1, 4) == 1 + +def test_errors_under_zero(): + try: + fastPow(3, -1) + assert False + except MyException as e: + assert isinstance(e, MyException) + assert str(e) == "Отрицательная степень" + + +def test_errors_too_much(): + try: + fastPow(3, 10000000000000) + assert False + except MyException as e: + assert isinstance(e, MyException) + assert str(e) == "Слишком большая степень" From 5fc7ed5a0062e9e0578585ffe8f179ab27cf9764 Mon Sep 17 00:00:00 2001 From: Yana Kalsina Date: Thu, 23 Oct 2025 14:55:26 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fast_pow.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 9207d20..420b50f 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -1,7 +1,13 @@ +class MyException(Exception): + pass + def fastPow(number, power): + if power < 0: + raise MyException("Отрицательная степень") + if power > 1000000000: + raise MyException("Слишком большая степень") result = 1 while power != 0: result *= number power = power - 1 return result -