-
Notifications
You must be signed in to change notification settings - Fork 0
Home work 2 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lspvtv
wants to merge
26
commits into
master
Choose a base branch
from
FiguresTests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Home work 2 #3
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 3df627b
Update README.md
lspvtv 8bacb3d
add code in Rectangle.py and ,ake tests for it
bulychevaoa 81f8b19
update rectangle test
bulychevaoa 0e84b6d
final update rectangle test
bulychevaoa 5ea4a9a
update square test
bulychevaoa a0b9477
some correction test
bulychevaoa c92c728
work version square and rectangle test, some correction in Square class
bulychevaoa cebfa28
work version triangle test, new code in Triangle class
bulychevaoa 5289cc4
work version circle test, new code in Circle class
bulychevaoa 7bcb552
remove cached files
bulychevaoa 6d69c26
remove cached files
bulychevaoa 466677b
some correction
bulychevaoa 9b981fe
some correction
bulychevaoa 3c38c52
some correction
bulychevaoa 4d3a457
some correction
bulychevaoa c590013
some change
bulychevaoa 47406ab
some change
bulychevaoa e6e9bad
correct values for tests sum_area
bulychevaoa 877973f
added validation
bulychevaoa ecc7ac2
correct validation.py
bulychevaoa f470e1d
correction circle
bulychevaoa 0b4e068
correction rectangle
bulychevaoa a848edc
correction square
bulychevaoa 211dcf4
correction triangle
bulychevaoa 616f09a
change *kwargs to *args, correction inheritance
bulychevaoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| pytest | ||
| flake8 == 6.1.0 | ||
| isort | ||
| pip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.