Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c22ad6e
Added workflow for test
verliiar Dec 3, 2024
a6d2abf
Changed python version in main.yml
verliiar Dec 3, 2024
09100eb
Add files via upload
verliiar Dec 3, 2024
c342814
Update main.yml
verliiar Dec 3, 2024
9af697e
Update main.yml
verliiar Dec 3, 2024
7d1fba2
Update main.yml
verliiar Dec 3, 2024
a763f0e
Update main.yml
verliiar Dec 3, 2024
b09f0b3
Fixed Errors in test_results.py
verliiar Dec 18, 2024
1bfd178
Update main.yml
verliiar Dec 25, 2024
6d5a922
Update main.yml
verliiar Dec 25, 2024
e0fc33c
Update main.yml
verliiar Dec 25, 2024
2634074
Update main.yml
verliiar Dec 25, 2024
2c982da
Update main.yml
verliiar Dec 25, 2024
402a632
Update test_results.py
verliiar Feb 20, 2025
27df3e4
Update test_results.py
verliiar Feb 20, 2025
f06ab6c
Create __init__.py
verliiar Feb 20, 2025
54f33d9
Update main.yml
verliiar Feb 20, 2025
161b1c8
Update main.yml
verliiar Feb 20, 2025
268036a
Update main.yml
verliiar Feb 20, 2025
c6cf0bc
Update main.yml
verliiar Feb 20, 2025
97f0a15
Update main.yml
verliiar Feb 20, 2025
e871561
Update main.yml
verliiar Feb 20, 2025
a5247d8
Update main.yml
verliiar Feb 20, 2025
d0f683e
Update circle.py
verliiar Feb 20, 2025
e18e168
Update rectangle.py
verliiar Feb 20, 2025
ce2b1c2
Update square.py
verliiar Feb 20, 2025
fad1dde
Update triangle.py
verliiar Feb 20, 2025
12b052d
Update main.yml
verliiar Feb 20, 2025
5b6dbee
Update main.yml
verliiar Feb 20, 2025
efc193a
Delete __init__.py
verliiar Feb 20, 2025
349ab5d
Create __init__.py
verliiar Feb 20, 2025
c910a50
Update main.yml
verliiar Feb 21, 2025
65b44f1
Update rectangle.py
verliiar Feb 21, 2025
de52405
Update test_results.py
verliiar Feb 21, 2025
8c6887f
Update test_results.py
verliiar Feb 21, 2025
24bffa0
Update main.yml
verliiar Feb 21, 2025
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
42 changes: 42 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Starts unittests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

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

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Add PYTHONPATH
run: echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV

- name: Install pytest
run: pip install pytest

- name: Run tests ubuntu
shell: bash
run: |
export PYTHONPATH="${{ github.workspace }}"
pytest

- name: Run tests windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$env:PYTHONPATH = "${{ github.workspace }}"
pytest
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions circle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import math


def area(r):
def area_circle(r):
return math.pi * r * r


def perimeter(r):
def perimeter_circle(r):
return 2 * math.pi * r

15 changes: 15 additions & 0 deletions rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

def area_rectangle(a, b):
if a >= 0 and b >= 0:
return a * b
return -1


def perimeter_rectangle(a, b, c, d):
if a != 0 and b != 0 and c != 0 and d != 0:
if (a == b and c == d) or (a == c and b == d) or (a == d and b == c):
return a + b + c + d
else:
return -1
else:
return 0
4 changes: 2 additions & 2 deletions square.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

def area(a):
def area_square(a):
return a * a


def perimeter(a):
def perimeter_square(a):
return 4 * a
166 changes: 166 additions & 0 deletions test_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import unittest
from math import isclose

from .rectangle import area_rectangle, perimeter_rectangle
class RectangleTestCase(unittest.TestCase):

def test_correct(self):
test_area_data = [
(2, 5, 10),
(15, 2, 30),
(6, 5, 30),
(6, 60, 360)
]
for width, height, expect in test_area_data:
with self.subTest(width=width, height=height):
self.assertEqual(area_rectangle(width, height), expect)

test_perim_data = [
(2, 2, 5, 5, 14),
(2, 5, 2, 5, 14),
(2, 5, 5, 2, 14),
(2, 5, 2, 5, 14)
]
for param_1, param_2, param_3, param_4, expect in test_perim_data:
with self.subTest(param_1=param_1, param_2=param_2, param_3=param_3, param_4=param_4):
self.assertEqual(perimeter_rectangle(param_1, param_2, param_3, param_4), expect)

def test_accuracy_results(self):
test_area_data = [
(2.852, 5.432,15.492064),
(15.345678980, 2.45784930,37.71736633901771),
(6.000000004, 5.4387,32.6322000217548),
(6.009, 6.991, 42.008919)
]
for width, height, expect in test_area_data:
with self.subTest(width=width, height=height):
res = area_rectangle(width, height)
self.assertTrue(isclose(res, expect))

test_perim_data = [
(15.492064, 5.4387, 15.492064, 5.4387, 41.861528),
(6.000000004, 6.000000004, 6.000000004, 6.000000004, 24.000000016),
(6.009, 6.009, 6.991, 6.991, 26),
(42.008919, 37.71736633901771, 37.71736633901771, 42.008919, 159.45257067803542)
]
for param_1, param_2, param_3, param_4, expect in test_perim_data:
with self.subTest(param_1=param_1, param_2=param_2, param_3=param_3, param_4=param_4):
res = perimeter_rectangle(param_1, param_2, param_3, param_4)
self.assertTrue(isclose(res, expect))

from circle import area_circle, perimeter_circle
class CircleTestCase(unittest.TestCase):

def test_correct(self):
test_area_data = [
(5, 78.539816339744831),
(134, 56410.43768785832739),
(56, 9852.034561657591596),
(2, 12.566370614359173)
]
for radius, expect in test_area_data:
with self.subTest(radius=radius):
res = area_circle(radius)
self.assertTrue(isclose(res, expect))

test_perim_data = [
(5, 31.415926535897932),
(134, 841.946831162064588),
(56, 351.858377202056843),
(2, 12.566370614359173)
]
for radius, expect in test_perim_data:
with self.subTest(radius=radius):
res = perimeter_circle(radius)
self.assertTrue(isclose(res, expect))

from square import area_square, perimeter_square
class SquareTestCase(unittest.TestCase):
def test_correct(self):
test_area_data = [
(5, 25),
(134, 17956),
(56, 3136),
(2, 4)
]
for side, expect in test_area_data:
with self.subTest(side=side):
self.assertEqual(expect, area_square(side))

test_perim_data = [
(5, 20),
(134, 536),
(56, 224),
(2, 8)
]
for side, expect in test_perim_data:
with self.subTest(side=side):
self.assertEqual(expect, perimeter_square(side))

def test_accuracy_results(self):
test_area_data = [
(37.71736633901771, 1422.599723551666212),
(159.45257067803542, 25425.122295833874622),
(32.6322000217548, 1064.86047825981397),
(42.008919, 1764.749275548561)
]
for side, expect in test_area_data:
with self.subTest(side=side):
self.assertTrue(isclose(expect, area_square(side)))

test_perim_data = [
(37.71736633901771, 150.86946535607084),
(159.45257067803542, 637.8102827121416),
(32.6322000217548, 130.5288000870192),
(42.008919, 168.035676)
]
for side, expect in test_perim_data:
with self.subTest(side=side):
self.assertTrue(isclose(expect, perimeter_square(side)))


from triangle import area_triangle, perimeter_triangle
class TriangleTestCase(unittest.TestCase):

def test_correct(self):
test_area_data = [
(4, 5, 10),
(30, 2, 30),
(6, 8, 24),
(10, 7, 35)
]
for osn, height, expect in test_area_data:
with self.subTest(osn=osn, height=height):
self.assertEqual(area_triangle(osn, height), expect)

test_perim_data = [
(2, 8, 6, 16),
(4, 5, 6, 15),
(19, 4, 20, 43),
(8, 18, 23, 49)
]
for param_1, param_2, param_3, expect in test_perim_data:
with self.subTest(param_1=param_1, param_2=param_2, param_3=param_3):
self.assertEqual(perimeter_triangle(param_1, param_2, param_3), expect)

def test_accuracy_results(self):
test_area_data = [
(2.852, 5.432, 7.746032),
(15.345678980, 2.45784930, 18.858683169508855),
(6.000000004, 5.4387, 16.3161000108774),
(6.009, 6.991, 21.0044595)
]
for osn, height, expect in test_area_data:
with self.subTest(osn=osn, height=height):
res = area_triangle(osn, height)
self.assertTrue(isclose(res, expect))

test_perim_data = [
(15.492064, 5.4387, 11.492064, 32.422828),
(6.000000004, 3.000000004, 5.000000004, 14.000000012),
(42.008919, 37.71736633901771, 32.008919, 111.73520433901771)
]
for param_1, param_2, param_3, expect in test_perim_data:
with self.subTest(param_1=param_1, param_2=param_2, param_3=param_3):
res = perimeter_triangle(param_1, param_2, param_3)
self.assertTrue(isclose(res, expect))
5 changes: 5 additions & 0 deletions triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def area_triangle(a, h):
return a * h / 2

def perimeter_triangle(a, b, c):
return a + b + c