From 3fea8dcd2794d25b67fc722559d68d46335c3a1b Mon Sep 17 00:00:00 2001 From: Nikonov Maksim Date: Wed, 16 Oct 2024 10:08:02 +0300 Subject: [PATCH 1/7] fixed mistakes --- circle.py | 18 ++++++++++++++++++ docs/README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- square.py | 17 +++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/circle.py b/circle.py index c3eb8647c9..cee5041a24 100644 --- a/circle.py +++ b/circle.py @@ -2,9 +2,27 @@ def area(r): + ''' + Принимает радиус, возвращает площадь круга + + Параметр: + r (int): радиус + Возвращаемое значачение: + math.pi * r * r (float): площадь круга + ''' + return math.pi * r * r def perimeter(r): + ''' + Принимает радиус, возвращает периметр круга + + Параметр: + r (int): радиус + Возвращаемое значачение: + 2 * math.pi * r (float): периметр круга + ''' + return 2 * math.pi * r diff --git a/docs/README.md b/docs/README.md index 63f8727939..9831ac14a5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,4 +7,51 @@ ## Perimeter - Circle: P = 2πR - Rectangle: P = 2a + 2b -- Square: P = 4a \ No newline at end of file +- Square: P = 4a +--- +*Hash of the commit, which the following documentation was added in:* `d97081aa43ee2081ef07b2947cdf126293701c71` +# **Сircle.py description** +This file contains 2 functions `area` and `perimeter`. +## **area** +This function calculates an area of a circle of given radius. +### Parameters +**`r`** - radius of the circle of type `int` . +### Return Value +Area of the circle of type `float`. +### Examples +\(pi rounded to 3,14) +- `area(5)` --> `78,5` +- `area(6)` --> `113,04` + +## **perimeter** +This function calculates a perimeter of a circle of given radius. +### Parameters +**`r`** - radius of the circle of type `int` . +### Return Value +Perimeter of the circle of type `float`. +### Examples +\(pi rounded to 3,14) +- `perimeter(5)` --> `31,4` +- `perimeter(6)` --> `37,68` +--- +# **Square.py description** +This file contains 2 functions `area` and `perimeter`. +## **area** +This function calculates an area of a square of given length of a side. +### Parameters +**`a`** - length of a side of the square of type `int` . +### Return Value +Area of the square of tupe `int`. +### Examples +- `area(5)` --> `25` +- `area(6)` --> `36` + +## **perimeter** +This function calculates a perimeter of a square of given length of a side. +### Parameters +**`a`** - length of a side of the square of type `int` . +### Return Value +Perimeter of the square of tнpe `int`. +### Examples +- `perimeter(5)` --> `20` +- `perimeter(6)` --> `24` \ No newline at end of file diff --git a/square.py b/square.py index 0f98724205..cefc3b16c8 100644 --- a/square.py +++ b/square.py @@ -1,7 +1,24 @@ def area(a): + ''' + Принимает длину стороны квадрата, возвращает его площадь + + Параметр: + a (int): длина стороны квадрата + Возвращаемое значение: + a * a (int): площадь квадрата + ''' + return a * a def perimeter(a): + ''' + Принимает длину стороны квадрата, возвращает его периметр + + Параметр: + a (int): длина стороны квадрата + Возвращаемое значение: + 4 * a (int): периметр квадрата + ''' return 4 * a From 6b49b0e1be9d47b0eddb5549bcf2b2236957af6f Mon Sep 17 00:00:00 2001 From: Nikonov Maksim Date: Wed, 16 Oct 2024 10:51:58 +0300 Subject: [PATCH 2/7] added links in Readme --- docs/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 9831ac14a5..7b0df86697 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,8 +9,8 @@ - Rectangle: P = 2a + 2b - Square: P = 4a --- -*Hash of the commit, which the following documentation was added in:* `d97081aa43ee2081ef07b2947cdf126293701c71` -# **Сircle.py description** +*Hash of the commit, which the following documentation was added in:* `[3fea8dcd2794d25b67fc722559d68d46335c3a1b](https://github.com/MurzikKrot/geometric_lib/commit/3fea8dcd2794d25b67fc722559d68d46335c3a1b)` +# **[Сircle.py](https://github.com/MurzikKrot/geometric_lib/blob/lab_work_2_466894/circle.py) description** This file contains 2 functions `area` and `perimeter`. ## **area** This function calculates an area of a circle of given radius. @@ -34,7 +34,7 @@ Perimeter of the circle of type `float`. - `perimeter(5)` --> `31,4` - `perimeter(6)` --> `37,68` --- -# **Square.py description** +# **[Square.py](https://github.com/MurzikKrot/geometric_lib/blob/lab_work_2_466894/square.py) description** This file contains 2 functions `area` and `perimeter`. ## **area** This function calculates an area of a square of given length of a side. From 54b2f213b7838cbf6b795546432a6fce57805c95 Mon Sep 17 00:00:00 2001 From: Nikonov Maksim Date: Tue, 12 Nov 2024 14:15:34 +0300 Subject: [PATCH 3/7] examples of function calls added --- circle.py | 20 ++++++++++++++------ square.py | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/circle.py b/circle.py index cee5041a24..3e92090428 100644 --- a/circle.py +++ b/circle.py @@ -2,27 +2,35 @@ def area(r): - ''' + """ Принимает радиус, возвращает площадь круга Параметр: r (int): радиус Возвращаемое значачение: math.pi * r * r (float): площадь круга - ''' + + Примеры: + area(3) --> 9pi + area(2) --> 4pi + """ return math.pi * r * r def perimeter(r): - ''' + """ Принимает радиус, возвращает периметр круга - + Параметр: r (int): радиус - Возвращаемое значачение: + Возвращаемое значение: 2 * math.pi * r (float): периметр круга - ''' + + Примеры: + perimeter(3) --> 6pi + perimeter(2) --> 4pi + """ return 2 * math.pi * r diff --git a/square.py b/square.py index cefc3b16c8..5eef471f13 100644 --- a/square.py +++ b/square.py @@ -1,24 +1,32 @@ def area(a): - ''' + """ Принимает длину стороны квадрата, возвращает его площадь Параметр: a (int): длина стороны квадрата Возвращаемое значение: a * a (int): площадь квадрата - ''' + + Примеры: + area(3) --> 9 + area(2) --> 4 + """ return a * a def perimeter(a): - ''' + """ Принимает длину стороны квадрата, возвращает его периметр Параметр: a (int): длина стороны квадрата Возвращаемое значение: 4 * a (int): периметр квадрата - ''' + + Примеры: + perimeter(5) --> 20 + perimeter(2) --> 8 + """ return 4 * a From d5c30bf28aa30d7905538060ba9125d9766cb2be Mon Sep 17 00:00:00 2001 From: Nikonov Maksim Date: Tue, 12 Nov 2024 14:18:50 +0300 Subject: [PATCH 4/7] 2 files with docstrings added --- rectangle.py | 34 ++++++++++++++++++++++++++++++++++ triangle.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 rectangle.py create mode 100644 triangle.py diff --git a/rectangle.py b/rectangle.py new file mode 100644 index 0000000000..06dc555779 --- /dev/null +++ b/rectangle.py @@ -0,0 +1,34 @@ +def area(a, b): + """ + Принимает длину и ширину, возвращает площадь прямоугольника + + Параметры: + a (int): длина + h (int): ширина + Возвращаемое значачение: + a * h (int): площадь прямоугольника + + Примеры: + area(3, 5) --> 15 + area(1, 2) --> 2 + """ + + return a * b + + +def perimeter(a, b): + """ + Принимает длину и ширину, возвращает периметр прямоугольника + + Параметры: + a (int): длина + h (int): ширина + Возвращаемое значачение: + (a + h)*2 (int): периметр прямоугольника + + Примеры: + perimeter(3, 5) --> 16 + perimeter(1, 2) --> 6 + """ + + return (a + b)*2 diff --git a/triangle.py b/triangle.py new file mode 100644 index 0000000000..42e781e453 --- /dev/null +++ b/triangle.py @@ -0,0 +1,35 @@ +def area(a, h): + """ + Принимает длину основания и высоту, возвращает площадь треугольника + + Параметры: + a (int): длина основания + h (int): высота + Возвращаемое значачение: + a * h / 2 (float): площадь треугольника + + Примеры: + area(3, 5) --> 7.5 + area(1, 2) --> 1.0 + """ + + return a * h / 2 + + +def perimeter(a, b, c): + """ + Принимает длины 3-х сторон, возвращает периметр треугольника + + Параметры: + a (int): длина 1 стороны + b (int): длина 2 стороны + c (int): длина 3 стороны + Возвращаемое значение: + a + b + c (int): периметр треугольника + + Примеры: + perimeter(3, 5, 6) --> 14 + perimeter(1, 2, 3) --> 6 + """ + + return a + b + c From 5b3b4765924a6ce099eeacf8781e60245378b25a Mon Sep 17 00:00:00 2001 From: Nikonov Maksim Date: Wed, 20 Nov 2024 11:00:51 +0300 Subject: [PATCH 5/7] input data validation and unit tests added --- circle.py | 7 ++++++- rectangle.py | 10 ++++++++++ square.py | 9 ++++++++- testCircle.py | 20 ++++++++++++++++++++ testRectangle.py | 24 ++++++++++++++++++++++++ testSquare.py | 20 ++++++++++++++++++++ testTriangle.py | 24 ++++++++++++++++++++++++ triangle.py | 16 ++++++++++++++-- 8 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 testCircle.py create mode 100644 testRectangle.py create mode 100644 testSquare.py create mode 100644 testTriangle.py diff --git a/circle.py b/circle.py index 3e92090428..c017c319c5 100644 --- a/circle.py +++ b/circle.py @@ -15,6 +15,9 @@ def area(r): area(2) --> 4pi """ + if r <= 0: + raise ValueError("radius can't be negative or equal to zero") + return math.pi * r * r @@ -32,5 +35,7 @@ def perimeter(r): perimeter(2) --> 4pi """ - return 2 * math.pi * r + if r <= 0: + raise ValueError("radius can't be or equal to zero") + return 2 * math.pi * r diff --git a/rectangle.py b/rectangle.py index 06dc555779..d9e7073e86 100644 --- a/rectangle.py +++ b/rectangle.py @@ -13,6 +13,11 @@ def area(a, b): area(1, 2) --> 2 """ + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + elif b <= 0: + raise ValueError("width can't be negative or equal to zero") + return a * b @@ -31,4 +36,9 @@ def perimeter(a, b): perimeter(1, 2) --> 6 """ + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + elif b <= 0: + raise ValueError("width can't be negative or equal to zero") + return (a + b)*2 diff --git a/square.py b/square.py index 5eef471f13..5bcc62a0f4 100644 --- a/square.py +++ b/square.py @@ -13,6 +13,9 @@ def area(a): area(2) --> 4 """ + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + return a * a @@ -26,7 +29,11 @@ def perimeter(a): 4 * a (int): периметр квадрата Примеры: - perimeter(5) --> 20 + perimeter(3) --> 12 perimeter(2) --> 8 """ + + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + return 4 * a diff --git a/testCircle.py b/testCircle.py new file mode 100644 index 0000000000..6301f5e084 --- /dev/null +++ b/testCircle.py @@ -0,0 +1,20 @@ +import unittest +import circle + + +class TestCircle(unittest.TestCase): + def test_area(self): + self.assertAlmostEqual(circle.area(3), 28.274, 3) + self.assertAlmostEqual(circle.area(2), 12.566, 3) + + self.assertRaises(ValueError, circle.area, -5) + + def test_perimeter(self): + self.assertAlmostEqual(circle.perimeter(3), 18.850, 3) + self.assertAlmostEqual(circle.perimeter(2), 12.566, 3) + + self.assertRaises(ValueError, circle.perimeter, -5) + + +if __name__ == '__main__': + unittest.main() diff --git a/testRectangle.py b/testRectangle.py new file mode 100644 index 0000000000..38a25e4ed3 --- /dev/null +++ b/testRectangle.py @@ -0,0 +1,24 @@ +import unittest +import rectangle + + +class TestRectangle(unittest.TestCase): + def test_area(self): + self.assertEqual(rectangle.area(3, 5), 15) + self.assertEqual(rectangle.area(1, 2), 2) + + self.assertRaises(ValueError, rectangle.area, -5, 1) + self.assertRaises(ValueError, rectangle.area, 5, -1) + self.assertRaises(ValueError, rectangle.area, -5, -1) + + def test_perimeter(self): + self.assertEqual(rectangle.perimeter(3, 5), 16) + self.assertEqual(rectangle.perimeter(1, 2), 6) + + self.assertRaises(ValueError, rectangle.perimeter, -5, 1) + self.assertRaises(ValueError, rectangle.perimeter, 5, -1) + self.assertRaises(ValueError, rectangle.perimeter, -5, -1) + + +if __name__ == '__main__': + unittest.main() diff --git a/testSquare.py b/testSquare.py new file mode 100644 index 0000000000..20e0d74a4d --- /dev/null +++ b/testSquare.py @@ -0,0 +1,20 @@ +import unittest +import square + + +class Testsquare(unittest.TestCase): + def test_area(self): + self.assertEqual(square.area(3), 9) + self.assertEqual(square.area(2), 4) + + self.assertRaises(ValueError, square.area, -5) + + def test_perimeter(self): + self.assertEqual(square.perimeter(3), 12) + self.assertEqual(square.perimeter(2), 8) + + self.assertRaises(ValueError, square.perimeter, -5) + + +if __name__ == '__main__': + unittest.main() diff --git a/testTriangle.py b/testTriangle.py new file mode 100644 index 0000000000..c5f22b18c7 --- /dev/null +++ b/testTriangle.py @@ -0,0 +1,24 @@ +import unittest +import triangle + + +class TestTriangle(unittest.TestCase): + def test_area(self): + self.assertEqual(triangle.area(3, 5), 7.5) + self.assertEqual(triangle.area(1, 2), 1.0) + + self.assertRaises(ValueError, triangle.area, -5, 1) + self.assertRaises(ValueError, triangle.area, 5, -1) + self.assertRaises(ValueError, triangle.area, -5, -1) + + def test_perimeter(self): + self.assertEqual(triangle.perimeter(3, 5, 6), 14) + self.assertEqual(triangle.perimeter(1, 2, 3), 6) + + self.assertRaises(ValueError, triangle.perimeter, -5, 1, 3) + self.assertRaises(ValueError, triangle.perimeter, 5, -1, 3) + self.assertRaises(ValueError, triangle.perimeter, -5, -1, -3) + + +if __name__ == '__main__': + unittest.main() diff --git a/triangle.py b/triangle.py index 42e781e453..3d36b18c33 100644 --- a/triangle.py +++ b/triangle.py @@ -1,11 +1,11 @@ -def area(a, h): +def area(a: int, h: int): """ Принимает длину основания и высоту, возвращает площадь треугольника Параметры: a (int): длина основания h (int): высота - Возвращаемое значачение: + Возвращаемое значение: a * h / 2 (float): площадь треугольника Примеры: @@ -13,6 +13,11 @@ def area(a, h): area(1, 2) --> 1.0 """ + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + elif h <= 0: + raise ValueError("height can't be negative or equal to zero") + return a * h / 2 @@ -32,4 +37,11 @@ def perimeter(a, b, c): perimeter(1, 2, 3) --> 6 """ + if a <= 0: + raise ValueError("length can't be negative or equal to zero") + elif b <= 0: + raise ValueError("length can't be negative or equal to zero") + elif c <= 0: + raise ValueError("length can't be negative or equal to zero") + return a + b + c From ef180dd3807f88b7b114c5bbb8307fef00433a5c Mon Sep 17 00:00:00 2001 From: Nikonov Maksim <126519143+MurzikKrot@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:26:13 +0300 Subject: [PATCH 6/7] Create main.yml --- .github/workflows/main.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..896df94f25 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + push: + branches: [ "lab_work_5_466894" ] + pull_request: + branches: [ "lab_work_5_466894" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. From d9456cd87b02bc511fc6f8fedfc51ad14d83fcd3 Mon Sep 17 00:00:00 2001 From: Nikonov Maksim <126519143+MurzikKrot@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:21:42 +0300 Subject: [PATCH 7/7] unit-tests auto-running added.yml --- .github/workflows/main.yml | 49 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 896df94f25..125988a1d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,36 +1,35 @@ -# This is a basic workflow to help you get started with Actions - name: CI -# Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the "main" branch push: - branches: [ "lab_work_5_466894" ] - pull_request: - branches: [ "lab_work_5_466894" ] - - # Allows you to run this workflow manually from the Actions tab + branches-ignore: + - 'main' + - 'lab_work_2_466894' + - 'lab_work_3_466894' + - 'lab_work_4_466894' + workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest + test: + name: Run Unit Tests + runs-on: ${{ matrix.os }} - # Steps represent a sequence of tasks that will be executed as part of the job + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 + # parsing the code from the repository + - name: Checkout repository + uses: actions/checkout@v3 - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! + # python set-up + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. + # Running unit-tests + - name: Run Unit Tests + run: python -m unittest discover