Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e813d3f
add directory and empty pyfiles
bulychevaoa Jul 26, 2023
3df627b
Update README.md
lspvtv Jul 26, 2023
8bacb3d
add code in Rectangle.py and ,ake tests for it
bulychevaoa Jul 26, 2023
81f8b19
update rectangle test
bulychevaoa Jul 30, 2023
0e84b6d
final update rectangle test
bulychevaoa Jul 30, 2023
5ea4a9a
update square test
bulychevaoa Jul 30, 2023
a0b9477
some correction test
bulychevaoa Jul 30, 2023
c92c728
work version square and rectangle test, some correction in Square class
bulychevaoa Aug 2, 2023
cebfa28
work version triangle test, new code in Triangle class
bulychevaoa Aug 2, 2023
5289cc4
work version circle test, new code in Circle class
bulychevaoa Aug 2, 2023
7bcb552
remove cached files
bulychevaoa Aug 2, 2023
6d69c26
remove cached files
bulychevaoa Aug 2, 2023
466677b
some correction
bulychevaoa Aug 3, 2023
9b981fe
some correction
bulychevaoa Aug 5, 2023
3c38c52
some correction
bulychevaoa Aug 5, 2023
4d3a457
some correction
bulychevaoa Aug 5, 2023
c590013
some change
bulychevaoa Aug 5, 2023
47406ab
some change
bulychevaoa Aug 6, 2023
e6e9bad
correct values for tests sum_area
bulychevaoa Aug 6, 2023
877973f
added validation
bulychevaoa Aug 6, 2023
ecc7ac2
correct validation.py
bulychevaoa Aug 11, 2023
f470e1d
correction circle
bulychevaoa Aug 11, 2023
0b4e068
correction rectangle
bulychevaoa Aug 11, 2023
a848edc
correction square
bulychevaoa Aug 11, 2023
211dcf4
correction triangle
bulychevaoa Aug 11, 2023
616f09a
change *kwargs to *args, correction inheritance
bulychevaoa Aug 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# file: ~/.gitignore_global
.DS_Store
.idea
*/venv/*
*/__pycache__/*
*/bin/*
*/lib/*
tests/lib64
tests/pyvenv.cfg
requirements.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Hello world
This is repository for OTUS course.
# FiguresTests
This is the second task from OTUS course.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest
flake8 == 6.1.0
isort
pip
23 changes: 23 additions & 0 deletions src/Circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import math
from src.validation import validation
from src.Figure import Figure


class Circle(Figure):
def __init__(self, coord_x, coord_y, radius):
super().__init__()
self.coord_x = coord_x
self.coord_y = coord_y
self.radius = radius
self.name = 'Circle'
validation(self.coord_x, self.coord_y, self.radius)

def get_area(self):
area = round(math.pi * self.radius ** 2, 2)
validation(area)
return area

def get_length(self):
length = round(2 * math.pi * self.radius, 2)
validation(length)
return length
13 changes: 13 additions & 0 deletions src/Figure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from abc import ABC, abstractmethod


class Figure(ABC):

@abstractmethod
def get_area(self):
pass

def sum_area(self, other_figure):
if isinstance(other_figure, Figure):
return self.get_area() + other_figure.get_area()
raise ValueError(f'Object {other_figure} is not figure')
21 changes: 21 additions & 0 deletions src/Rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from src.validation import validation
from src.Figure import Figure


class Rectangle(Figure):
def __init__(self, side_a, side_b):
super().__init__()
self.side_a = side_a
self.side_b = side_b
self.name = 'Rectangle'
validation(self.side_a, self.side_b)

def get_area(self):
area = self.side_a * self.side_b
validation(area)
return area

def get_perimetr(self):
perimetr = 2 * (self.side_a + self.side_b)
validation(perimetr)
return perimetr
8 changes: 8 additions & 0 deletions src/Square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from src.Rectangle import Rectangle


class Square(Rectangle):
def __init__(self, side_a):
super().__init__(side_a, side_a)
self.side_a = side_a
self.name = 'Square'
31 changes: 31 additions & 0 deletions src/Triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math
from math import sin
from src.validation import validation
from src.Figure import Figure


class Triangle(Figure):
def __init__(self, side_a, side_b, side_c, angle_a, angle_b, angle_c): # side a opposite angle a
super().__init__()
if angle_a + angle_b + angle_c != 180:
raise ValueError("This triangle does not exist")
if (angle_a >= 180 or angle_a <= 0) or (angle_b >= 180 or angle_b <= 0) or (angle_c >= 180 or angle_c <= 0):
raise ValueError("This triangle does not exist")
self.side_a = side_a
self.side_b = side_b
self.side_c = side_c
self.angle_a = angle_a
self.angle_b = angle_b
self.angle_c = angle_c
self.name = 'Triangle'
validation(self.side_a, self.side_b, self.side_c, self.angle_a, self.angle_b, self.angle_c)

def get_area(self):
area = round(0.5 * self.side_a * self.side_c * (sin(math.radians(self.angle_b)) * 180 / math.pi), 2)
validation(area)
return area

def get_perimetr(self):
perimetr = round(self.side_a + self.side_b + self.side_c, 2)
validation(perimetr)
return perimetr
8 changes: 8 additions & 0 deletions src/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def validation(*args):
for item in args:
if type(item) == str:
raise ValueError("TypeError")
if item <= 0:
raise ValueError("Can not create")
if item > 10 ** 64:
raise ValueError("It is too large, stack overflow")
50 changes: 50 additions & 0 deletions test/test_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
from src.Circle import Circle


@pytest.mark.parametrize('coord_x, coord_y, radius, area, length',
[
(1, 2, 5, 78.54, 31.42),
(1, 2, 5, 78.54, 31.42),
(1, 2, 5, 78.54, 31.42),
(1, 2, 5, 78.54, 31.42),
(0.1, 0.5, 5, 78.54, 31.42)
])
def test_correct_circle(coord_x, coord_y, radius, area, length):
r = Circle(coord_x, coord_y, radius)
assert r.name == 'Circle'
assert round(r.get_area(), 2) == area
assert round(r.get_length(), 2) == length


@pytest.mark.parametrize('coord_x, coord_y, radius',
[
(0, 0, 0),
(0, 0, -5),
('2', '3', 10),
(0, 0, '10'),
(0, 0, 10 ** 65)
])
def test_circle_creation_error(coord_x, coord_y, radius):
with pytest.raises(ValueError):
Circle(coord_x, coord_y, radius)


@pytest.mark.parametrize('coord_x, coord_y, radius, area, length',
[
(1, 2, 50 * 10 ** 33, 25 * 10 ** 67, 31 * 10 ** 63)
])
def test_get_circle_area_error(coord_x, coord_y, radius, area, length):
r = Circle(coord_x, coord_y, radius)
with pytest.raises(ValueError):
assert round(r.get_area(), 2) == area


@pytest.mark.parametrize('coord_x, coord_y, radius, area, length',
[
(1, 2, 50 * 10 ** 62, 25 * 10 ** 126, 31 * 10 ** 64)
])
def test_get_circle_length_error(coord_x, coord_y, radius, area, length):
r = Circle(coord_x, coord_y, radius)
with pytest.raises(ValueError):
assert round(r.get_length(), 2) == length
53 changes: 53 additions & 0 deletions test/test_rectangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import pytest
from src.Rectangle import Rectangle


@pytest.mark.parametrize('side_a, side_b, perimetr, area',
[
(4, 6, 20, 24),
(1 * 10 ** 31, 9 * 10 ** 31, 2 * 10 ** 32, 9 * 10 ** 62),
(0.1, 0.3, 0.8, 0.03),
(1 / 6, 5 / 6, 2, 5 / 36)
])
def test_correct_rectangle(side_a, side_b, perimetr, area):
r = Rectangle(side_a, side_b)
assert r.name == 'Rectangle'
assert r.get_area() == area
assert r.get_perimetr() == perimetr


@pytest.mark.parametrize('side_a, side_b, perimetr, area',
[
(-4, 5, 2, -20),
(0, 20, 40, 0),
(0, 0, 0, 0),
(-2, -3, -10, -6),
(-0.1, -0.3, -0.8, -0.03),
(-1 / 6, -5 / 6, -2, -5 / 36),
(10 ** 65, 10 ** 27, 11 * 10 ** 26, 10 ** 52),
('5', '6', '22', '30')
])
def test_rectangle_creation_error(side_a, side_b, perimetr, area):
with pytest.raises(ValueError):
Rectangle(side_a, side_b)


@pytest.mark.parametrize('side_a, side_b, perimetr, area',
[
(1 * 10 ** 32, 9 * 10 ** 32, 2 * 10 ** 33, 9 * 10 ** 64)

])
def test_get_rectangle_area_error(side_a, side_b, perimetr, area):
r = Rectangle(side_a, side_b)
with pytest.raises(ValueError):
assert r.get_area() == area


@pytest.mark.parametrize('side_a, side_b, perimetr, area',
[
(1 * 10 ** 63, 9 * 10 ** 63, 10 ** 64, 9 * 10 ** 126)
])
def test_get_rectangle_perimetr_error(side_a, side_b, perimetr, area):
r = Rectangle(side_a, side_b)
with pytest.raises(ValueError):
assert r.get_perimetr() == perimetr
50 changes: 50 additions & 0 deletions test/test_square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest
from src.Square import Square


@pytest.mark.parametrize('side_a, perimetr, area',
[
(5, 20, 25),
(10 ** 31, 4 * 10 ** 31, 10 ** 62),
(0.1, 0.4, 0.010000000000000002),
(1 / 6, 2 / 3, 1 / 36)
])
def test_correct_Square(side_a, perimetr, area):
r = Square(side_a)
assert r.name == 'Square'
assert r.get_area() == area
assert r.get_perimetr() == perimetr


@pytest.mark.parametrize('side_a, perimetr, area',
[
(-3, -12, 9),
(0, 0, 0),
(-0.3, -1.2, 0.09),
(-1 / 6, -2 / 3, 1 / 36),
(10 ** 65, 4 * 10 ** 65, 10 ** 130),
("5", 20, 15)
])
def test_Square_creation_error(side_a, perimetr, area):
with pytest.raises(ValueError):
Square(side_a)


@pytest.mark.parametrize('side_a, area',
[
(10 ** 33, 10 ** 66)
])
def test_get_square_area_error(side_a, area):
r = Square(side_a)
with pytest.raises(ValueError):
assert r.get_area() == area


@pytest.mark.parametrize('side_a, perimetr',
[
(3 * 10 ** 63, 9 * 10 ** 64)
])
def test_get_square_perimetr_error(side_a, perimetr):
r = Square(side_a)
with pytest.raises(ValueError):
assert r.get_perimetr() == perimetr
42 changes: 42 additions & 0 deletions test/test_sum_area_figures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
from src.Figure import Figure
from src.Rectangle import Rectangle
from src.Square import Square
from src.Triangle import Triangle
from src.Circle import Circle


def test_sum_area_rectangle_square():
value1 = Rectangle(2, 3)
value2 = Square(5)
assert value1.sum_area(value2) == 31


def test_sum_area_rectangle_triangle():
value1 = Rectangle(2, 3)
value2 = Triangle(5, 3, 2, 100, 20, 60)
assert value1.sum_area(value2) == 103.98


def test_sum_area_rectangle_circle():
value1 = Rectangle(2, 3)
value2 = Circle(5, 3, 5)
assert value1.sum_area(value2) == 84.54


def test_sum_area_square_triangle():
value1 = Square(2)
value2 = Triangle(5, 3, 2, 100, 20, 60)
assert value1.sum_area(value2) == 101.98


def test_sum_area_square_circle():
value1 = Square(2)
value2 = Circle(5, 3, 2)
assert value1.sum_area(value2) == 16.57


def test_sum_area_triangle_circle():
value1 = Triangle(5, 3, 2, 100, 20, 60)
value2 = Circle(5, 3, 2)
assert round(value1.sum_area(value2), 2) == 110.55
54 changes: 54 additions & 0 deletions test/test_triangle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
from src.Triangle import Triangle


@pytest.mark.parametrize('side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr',
[
(10, 10, 10, 60, 60, 60, 2480.98, 30),
(7, 7, 5, 69.075, 69.075, 41.85, 936.55, 19),
(5, 7, 3, 38.21, 120, 21.79, 372.15, 15),
(8, 8.94, 4, 63.435, 90, 26.565, 916.73, 20.94),
(9, 2, 10, 54.9, 10.48, 114.62, 468.97, 21)
])
def test_correct_triangle(side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr):
r = Triangle(side_a, side_b, side_c, angle_a, angle_b, angle_c)
assert r.name == 'Triangle'
assert r.get_area() == area
assert r.get_perimetr() == perimetr


@pytest.mark.parametrize('side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr',
[
(-4, -5, -7, 40, 50, 90, 13, 15),
(4, 5, 7, -40, -50, -90, 13, 15),
(0, 20, 0, 40, 30, 110, 0, 0),
(13, 20, 23, 80, 0, 110, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0),
(10 ** 65, 10 ** 65, 10 ** 65, 110, 40, 30, 40, 50),
('10', '10', '10', 60, 60, 60, '2480.98', '30'),
(10, 10, 10, '60', '60', '60', '2480.98', '30')
])
def test_triangle_creation_error(side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr):
with pytest.raises(ValueError):
Triangle(side_a, side_b, side_c, angle_a, angle_b, angle_c)


@pytest.mark.parametrize('side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr',
[
(1 * 10 ** 33, 9 * 10 ** 35, 10 ** 31, 10, 80, 90, 8 * 10 ** 72, 9 * 10 ** 63)
])
def test_get_triangle_area_error(side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr):
r = Triangle(side_a, side_b, side_c, angle_a, angle_b, angle_c)

with pytest.raises(ValueError):
r.get_area() == area


@pytest.mark.parametrize('side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr',
[
(1 * 10 ** 63, 9 * 10 ** 63, 10 ** 63, 10, 80, 90, 8 * 10 ** 62, 9 * 10 ** 125)
])
def test_get_triangle_perimetr_error(side_a, side_b, side_c, angle_a, angle_b, angle_c, area, perimetr):
r = Triangle(side_a, side_b, side_c, angle_a, angle_b, angle_c)
with pytest.raises(ValueError):
r.get_perimetr() == perimetr
4 changes: 0 additions & 4 deletions venv/.gitignore

This file was deleted.

Loading