Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI - Run Unit Test

on:
push:
branches: [ "lab5" ]
pull_request:
branches: [ "lab5" ]
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- name: Check out Repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Set up Python
uses: actions/setup-python@v4.7.1
with:
python-version: 3.8

- name: Run My Step
id: myStep
run: echo "::set-output name=myOutput::some value"

- name: Set Output Variable
run: echo "myOutput=${{ steps.myStep.outputs.myOutput }}" >> $GITHUB_ENV

- name: Install Dependencies
run: |
echo "There are no dependencies!"
- name: Run Unit Tests
run: |
python -m unittest discover -s ./tests -p "test_*.py"
46 changes: 46 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI - Run Unit Test

on:
push:
branches: [ "lab5" ]
pull_request:
branches: [ "lab5" ]
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- name: Check out Repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Set up Python
uses: actions/setup-python@v4.7.1
with:
python-version: 3.8

- name: Run My Step
id: myStep
run: echo "::set-output name=myOutput::some value"

- name: Set Output Variable
run: echo "myOutput=${{ steps.myStep.outputs.myOutput }}" >> $GITHUB_ENV

- name: Install Dependencies
run: |
echo "There are no dependencies!"
- name: Run Unit Tests
run: |
python -m unittest discover -s ./tests -p "test_*.py"
Binary file added __pycache__/circle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/circle.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/rectangle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/rectangle.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/square.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/square.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/test_circle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/test_rectangle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/test_square.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/test_triangle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/triangle.cpython-311.pyc
Binary file not shown.
Binary file added __pycache__/triangle.cpython-312.pyc
Binary file not shown.
26 changes: 21 additions & 5 deletions circle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import math


def area(r):
def area_circle(r):
'''
Принимает число r-радиус окружности, возвращает её площадь

Example:
in : `10`
out :` 100`
'''
# Проверка на корректность ввода
if not isinstance(r, (int, float)) or r < 0 or r > 10**10:
return "Incorrect input"
return math.pi * r * r


def perimeter(r):
return 2 * math.pi * r
def perimeter_circle(r):
'''Принимает число r-радиус окружности, возвращает её длину
Example:

in : `10`
out :` 62,83`
'''
# Проверка на корректность ввода
if not isinstance(r, (int, float)) or r < 0 or r > 10**10:
return "Incorrect input"
return 2 * math.pi * r
106 changes: 105 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Общее описание решений
- Сделал git clone своего репозитория
- открыл папку geometric_lib через терминал
- Описал решение фаилов rectangle.py и triangle.py на Pycharm
- Сделал git commit каждому файлу
# Math formulas
## Area
- Circle: S = πR²
Expand All @@ -7,4 +12,103 @@
## Perimeter
- Circle: P = 2πR
- Rectangle: P = 2a + 2b
- Square: P = 4a
- Square: P = 4a
# Описание каждой функции с примерами вызова
## Circle:
```
import math

def area_circle(r):
'''Принимает число r-радиус окружности, возвращает её площадь'''
return math.pi * r * r


def perimeter_circle(r):
'''Принимает число r-радиус окружности, возвращает её длину'''
return 2 * math.pi * r
```

_Example:_

in : `10`
out :` 100 62,83`

## Rectangle:
```
def area_rectangle(a, b):
'''Получает на вход боковую сторону a и основание прямоугольника b, возвращает его площадь'''
return a * b

def perimeter_rectangle(a, b):
'''Получает на вход боковую сторону a и основание прямоугольника b, возвращает его периметр'''
return 2*(a + b)
```
_Example:_

in: `3 4`
out : `12 14`

## Square:
```
def area_square(a):
'''Принимает сторону квадрата a, возвращает его площадь'''
return a * a

def perimeter_square(a):
'''Принимает сторону квадрата a, возвращает его периметр'''
return 4 * a

```

_Example:_

in : `10 `
out : `100 40`

## Triangle :
```
def area_triangle(a, h):
'''
Принимает сторону треугольника a и высоту h, опирающуюся на сторону a,
возвращает площадь треугольника
'''
return a * h / 2

def perimeter_triangle(a, b, c):
'''Принимает стороны треугольника a,b,c, возвращает его периметр'''
return a + b + c
```

_Example:_

in : `10 5` `3 3 4 `
out : `25 10`

# История изменения проекта с хешами комитов
1. **commit** 5e01bedbd8701b0801affa857b64b303f8105e38
```
Author: Nguyen Van Chinh <nvchinh23022004@gmail.com>
Date: Fri Oct 4 13:25:18 2024 +0300

adding comment to circle.py
```
2. **commit** 5e97c4b409bd2462994af4cb4195f48091d2fc43
```
Author: Nguyen Van Chinh <nvchinh23022004@gmail.com>
Date: Fri Oct 4 13:24:19 2024 +0300

adding comment to square.py
```
3. **commit** c771d335aa477310db4d053780ad2ec484808148
```
Author: Nguyen Van Chinh <nvchinh23022004@gmail.com>
Date: Fri Oct 4 13:23:03 2024 +0300

adding comment to triangle.py
```
4. **commit** 35b21816d0bcdd156bd79b185342f6c9315790e2
```
Author: Nguyen Van Chinh <nvchinh23022004@gmail.com›
Date: Fri Oct 4 13:22:05 2024 +0300
adding comment to rectangle. py
```
26 changes: 26 additions & 0 deletions rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def area_rectangle(a, b):
'''Получает на вход боковую сторону a и основание прямоугольника b, возвращает его площадь
Example:

in: `3 4`
out : ` 12`
'''
# Проверка на корректность ввода
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)) or a < 0 or b < 0 or a > 10**10 or b > 10**10:
return "Incorrect input"
return a * b

return a * b

def perimeter_rectangle(a, b):
'''Получает на вход боковую сторону a и основание прямоугольника b, возвращает его периметр
Example:

in: `3 4`
out : `14`

'''
# Проверка на корректность ввода
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)) or a < 0 or b < 0 or a > 10**10 or b > 10**10:
return "Incorrect input"
return 2*(a + b)
19 changes: 17 additions & 2 deletions square.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
def area_square(a):
'''Принимает сторону квадрата a, возвращает его площадь
Example:

def area(a):
in : `10 `
out : `100 `
'''
# Проверка на корректность ввода
if not isinstance(a, (int, float)) or a < 0 or a > 10**10:
return "Incorrect input"
return a * a

def perimeter_square(a):
'''Принимает сторону квадрата a, возвращает его периметр
Example:

def perimeter(a):
in : `10 `
out : ` 40`
'''
if not isinstance(a, (int, float)) or a < 0 or a > 10**10:
return "Incorrect input"
return 4 * a
Binary file added tests/__pycache__/test_circle.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_rectangle.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_square.cpython-311.pyc
Binary file not shown.
Binary file added tests/__pycache__/test_triangle.cpython-311.pyc
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/test_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import unittest
from circle import area_circle
from circle import perimeter_circle

class CircleTestCase(unittest.TestCase):
# Проверяет, когда радиус равен 0
def test_0_mul(self):
result = area_circle(0)
self.assertEqual(result, 0)
# Проверяет, когда радиус равен 10
def test_1_mul(self):
result = area_circle(10)
self.assertEqual(result, 314.1592653589793)
# Проверяет, когда радиус равен 67.636
def test_2_mul(self):
result = area_circle(67.636)
self.assertEqual(result, 14371.619275936122)
# Проверяет, когда радиус равен 5
def test_3_mul(self):
result = perimeter_circle(5)
self.assertEqual(result, 31.41592653589793 )
# Проверяет, когда радиус равен 10
def test_4_mul(self):
result = perimeter_circle(10)
self.assertEqual(result, 62.83185307179586)
# Проверяет, когда радиус равен -10
def test_5_mul(self):
result = perimeter_circle(-10)
self.assertEqual(result, "Incorrect input")

if __name__ == '__main__':
unittest.main()
35 changes: 35 additions & 0 deletions tests/test_rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from rectangle import area_rectangle
from rectangle import perimeter_rectangle

class RectangleTestCase(unittest.TestCase):
# Проверяет, когда стороны равны 0, 10
def test_0_mul(self):
result = area_rectangle(0,13)
self.assertEqual(result, 0)
# Проверяет, когда стороны равны 10, 13
def test_1_mul(self):
result = area_rectangle(10,13)
self.assertEqual(result, 130)
# Проверяет, когда стороны равны 67,5, 3,5
def test_2_mul(self):
result = area_rectangle(67.5,3.5)
self.assertEqual(result, 236.25)
# Проверяет, когда стороны равны 0,0
def test_3_mul(self):
result = perimeter_rectangle(0,0)
self.assertEqual(result, 0)
# Проверяет, когда стороны равны 10,54
def test_4_mul(self):
result = perimeter_rectangle(10,54)
self.assertEqual(result, 128)
# Проверяет, когда стороны равны -6,5
def test_5_mul(self):
result = perimeter_rectangle(-6,5)
self.assertEqual(result, "Incorrect input" )

if __name__ == '__main__':
unittest.main()



Loading