diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml new file mode 100644 index 0000000000..e0410890c6 --- /dev/null +++ b/.github/workflows/CICD.yml @@ -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" diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000000..e0410890c6 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -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" diff --git a/__pycache__/circle.cpython-311.pyc b/__pycache__/circle.cpython-311.pyc new file mode 100644 index 0000000000..0f238684ef Binary files /dev/null and b/__pycache__/circle.cpython-311.pyc differ diff --git a/__pycache__/circle.cpython-312.pyc b/__pycache__/circle.cpython-312.pyc new file mode 100644 index 0000000000..7f65a6a700 Binary files /dev/null and b/__pycache__/circle.cpython-312.pyc differ diff --git a/__pycache__/rectangle.cpython-311.pyc b/__pycache__/rectangle.cpython-311.pyc new file mode 100644 index 0000000000..5a477e2a2d Binary files /dev/null and b/__pycache__/rectangle.cpython-311.pyc differ diff --git a/__pycache__/rectangle.cpython-312.pyc b/__pycache__/rectangle.cpython-312.pyc new file mode 100644 index 0000000000..a8431b744d Binary files /dev/null and b/__pycache__/rectangle.cpython-312.pyc differ diff --git a/__pycache__/square.cpython-311.pyc b/__pycache__/square.cpython-311.pyc new file mode 100644 index 0000000000..de5a8b7724 Binary files /dev/null and b/__pycache__/square.cpython-311.pyc differ diff --git a/__pycache__/square.cpython-312.pyc b/__pycache__/square.cpython-312.pyc new file mode 100644 index 0000000000..69ed463389 Binary files /dev/null and b/__pycache__/square.cpython-312.pyc differ diff --git a/__pycache__/test_circle.cpython-311.pyc b/__pycache__/test_circle.cpython-311.pyc new file mode 100644 index 0000000000..ebd2b3d2ee Binary files /dev/null and b/__pycache__/test_circle.cpython-311.pyc differ diff --git a/__pycache__/test_rectangle.cpython-311.pyc b/__pycache__/test_rectangle.cpython-311.pyc new file mode 100644 index 0000000000..6331326a81 Binary files /dev/null and b/__pycache__/test_rectangle.cpython-311.pyc differ diff --git a/__pycache__/test_square.cpython-311.pyc b/__pycache__/test_square.cpython-311.pyc new file mode 100644 index 0000000000..f30cda54c8 Binary files /dev/null and b/__pycache__/test_square.cpython-311.pyc differ diff --git a/__pycache__/test_triangle.cpython-311.pyc b/__pycache__/test_triangle.cpython-311.pyc new file mode 100644 index 0000000000..221e6f87e2 Binary files /dev/null and b/__pycache__/test_triangle.cpython-311.pyc differ diff --git a/__pycache__/triangle.cpython-311.pyc b/__pycache__/triangle.cpython-311.pyc new file mode 100644 index 0000000000..d95a2f90dd Binary files /dev/null and b/__pycache__/triangle.cpython-311.pyc differ diff --git a/__pycache__/triangle.cpython-312.pyc b/__pycache__/triangle.cpython-312.pyc new file mode 100644 index 0000000000..39fabfd878 Binary files /dev/null and b/__pycache__/triangle.cpython-312.pyc differ diff --git a/circle.py b/circle.py index c3eb8647c9..0f4db943a8 100644 --- a/circle.py +++ b/circle.py @@ -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 \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 63f8727939..d2775e1287 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,3 +1,8 @@ +# Общее описание решений +- Сделал git clone своего репозитория +- открыл папку geometric_lib через терминал +- Описал решение фаилов rectangle.py и triangle.py на Pycharm +- Сделал git commit каждому файлу # Math formulas ## Area - Circle: S = πR² @@ -7,4 +12,103 @@ ## Perimeter - Circle: P = 2πR - Rectangle: P = 2a + 2b -- Square: P = 4a \ No newline at end of file +- 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 + Date: Fri Oct 4 13:25:18 2024 +0300 + + adding comment to circle.py +``` +2. **commit** 5e97c4b409bd2462994af4cb4195f48091d2fc43 +``` + Author: Nguyen Van Chinh + Date: Fri Oct 4 13:24:19 2024 +0300 + + adding comment to square.py +``` +3. **commit** c771d335aa477310db4d053780ad2ec484808148 +``` + Author: Nguyen Van Chinh + Date: Fri Oct 4 13:23:03 2024 +0300 + + adding comment to triangle.py +``` +4. **commit** 35b21816d0bcdd156bd79b185342f6c9315790e2 +``` +Author: Nguyen Van Chinh 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) \ No newline at end of file diff --git a/square.py b/square.py index 0f98724205..c1150f0175 100644 --- a/square.py +++ b/square.py @@ -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 diff --git a/tests/__pycache__/test_circle.cpython-311.pyc b/tests/__pycache__/test_circle.cpython-311.pyc new file mode 100644 index 0000000000..bdf8f14cf4 Binary files /dev/null and b/tests/__pycache__/test_circle.cpython-311.pyc differ diff --git a/tests/__pycache__/test_rectangle.cpython-311.pyc b/tests/__pycache__/test_rectangle.cpython-311.pyc new file mode 100644 index 0000000000..e3d9718065 Binary files /dev/null and b/tests/__pycache__/test_rectangle.cpython-311.pyc differ diff --git a/tests/__pycache__/test_square.cpython-311.pyc b/tests/__pycache__/test_square.cpython-311.pyc new file mode 100644 index 0000000000..4f41272d63 Binary files /dev/null and b/tests/__pycache__/test_square.cpython-311.pyc differ diff --git a/tests/__pycache__/test_triangle.cpython-311.pyc b/tests/__pycache__/test_triangle.cpython-311.pyc new file mode 100644 index 0000000000..eb8b4c13af Binary files /dev/null and b/tests/__pycache__/test_triangle.cpython-311.pyc differ diff --git a/tests/test_circle.py b/tests/test_circle.py new file mode 100644 index 0000000000..53f157e71e --- /dev/null +++ b/tests/test_circle.py @@ -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() \ No newline at end of file diff --git a/tests/test_rectangle.py b/tests/test_rectangle.py new file mode 100644 index 0000000000..9fdd9fef4d --- /dev/null +++ b/tests/test_rectangle.py @@ -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() + + + \ No newline at end of file diff --git a/tests/test_square.py b/tests/test_square.py new file mode 100644 index 0000000000..65b802137c --- /dev/null +++ b/tests/test_square.py @@ -0,0 +1,34 @@ +import unittest +from square import area_square +from square import perimeter_square + +class SquareTestCase(unittest.TestCase): + # Проверяет, когда сторона равна 0 + def test_0_mul(self): + result = area_square(0) + self.assertEqual(result, 0) + # Проверяет, когда сторона равна 10 + def test_1_mul(self): + result = area_square(10) + self.assertEqual(result, 100) + # Проверяет, когда сторона равна 7,5 + def test_2_mul(self): + result = area_square(7.5) + self.assertEqual(result, 56.25) + # Проверяет, когда сторона равна 56,25 + def test_3_mul(self): + result = perimeter_square(0) + self.assertEqual(result, 0) + # Проверяет, когда сторона равна 10 + def test_4_mul(self): + result = perimeter_square(10) + self.assertEqual(result, 40) + # Проверяет, когда сторона равна 17,25 + def test_5_mul(self): + result = perimeter_square(17.25) + self.assertEqual(result, 69) + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/tests/test_triangle.py b/tests/test_triangle.py new file mode 100644 index 0000000000..1e4b9ef8df --- /dev/null +++ b/tests/test_triangle.py @@ -0,0 +1,32 @@ +import unittest +from triangle import area_triangle +from triangle import perimeter_triangle + +class TriangleTestCase(unittest.TestCase): + # Проверяет, когда стороны равны 7,8, + def test_0_mul(self): + result = area_triangle(7, 8) + self.assertEqual(result, 28) + # Проверяет, когда стороны равны 10,5 + def test_1_mul(self): + result = area_triangle(10, 5) + self.assertEqual(result, 25) + # Проверяет, когда стороны равны 7.5 3.5 + def test_2_mul(self): + result = area_triangle(7.5, 3.5) + self.assertEqual(result, 13.125) + # Проверяет, когда стороны равны 0 0 0 + def test_3_mul(self): + result = perimeter_triangle(0, 0,0) + self.assertEqual(result, 0) + # Проверяет, когда стороны равны 10, 4, 8 + def test_4_mul(self): + result = perimeter_triangle(10, 4, 8) + self.assertEqual(result, 22) + # Проверяет, когда стороны равны 34.23, 42.34, 23.43 + def test_5_mul(self): + result = perimeter_triangle(34.23, 42.34, 23.43) + self.assertEqual(result, 100) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/triangle.py b/triangle.py new file mode 100644 index 0000000000..106bdff621 --- /dev/null +++ b/triangle.py @@ -0,0 +1,24 @@ +def area_triangle(a, h): + ''' + Принимает сторону треугольника a и высоту h, опирающуюся на сторону a, + возвращает площадь треугольника + Example: + + in : `10 5 ` + out : `25 ` + ''' + if not isinstance(a, (int, float)) or not isinstance(h, (int, float)) or a < 0 or h < 0 or a > 10**10 or h > 10**10: + return "Incorrect input" + return a * h / 2 + +def perimeter_triangle(a, b, c): + '''Принимает стороны треугольника a,b,c, возвращает его периметр + Example: + + in : + `3 3 4 ` + out : ` 10` + ''' + if not isinstance(a, (int, float)) or not isinstance(b, (int, float)) or not isinstance(c, (int, float)) or a < 0 or b < 0 or c < 0 or a > 10**10 or b > 10**10 or c > 10**10: + return "Incorrect input" + return a + b + c \ No newline at end of file