-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_model.py
92 lines (73 loc) · 2.77 KB
/
test_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import pytest
from shapes import *
def test_model():
circle = Circle(radius=5)
assert circle.name == "Circle"
assert circle.area == 78.53981633974483
assert circle.perimeter == 31.41592653589793
square = Square(a=7.3)
assert square.name == "Square"
assert square.area == 53.29
assert square.perimeter == 29.2
rect = Rectangle(a=5, b=6.5)
assert rect.name == "Rectangle"
assert rect.area == 32.5
triangle = Triangle(a=5, b=6, c=7)
assert triangle.name == "Triangle"
assert triangle.area == 14.696938456699069
assert triangle.perimeter == 18
trapezoid = Trapezoid(a=5, b=10, height=6)
assert trapezoid.name == "Trapezoid"
assert trapezoid.area == 45
assert trapezoid.perimeter == 99.5
rhombus = Rhombus(a=10, height=5)
assert rhombus.name == "Rhombus"
assert rhombus.area == 50
rhombus = Rhombus.from_side_and_angle(side=10, angle=30)
assert rhombus.area == 49.99999999999999
sphere = Sphere(radius=5)
assert sphere.name == "Sphere"
assert sphere.area == 314.1592653589793
assert sphere.volume == 523.5987755982989
cube = Cube(a=5)
assert cube.name == "Cube"
assert cube.area == 150
assert cube.volume == 125
cuboid = Cuboid(width=5, length=10, height=15)
assert cuboid.name == "Cuboid"
assert cuboid.area == 550
assert cuboid.volume == 750
pyramid = Pyramid(a=5, height=10)
assert pyramid.name == "Pyramid"
assert pyramid.area == 128.07764064044153
assert pyramid.volume == 83.33333333333333
cylinder = Cylinder(radius=5, height=10)
assert cylinder.name == "Cylinder"
assert cylinder.area == 471.23889803846896
assert cylinder.volume == 785.3981633974483
cone = Cone(radius=5, height=10)
assert cone.name == "Cone"
assert cone.area == 254.160184615763
assert cone.volume == 261.79938779914943
def test_triangle_median():
triangle = Triangle(a=20, b=30, c=40)
assert round(triangle.get_median(side_index=1), 2) == 33.91
assert round(triangle.get_median(side_index=2), 2) == 27.84
assert round(triangle.get_median(side_index=3), 2) == 15.81
def test_invalid_params():
with pytest.raises(ValueError):
Triangle(a=1, b=2, c=3)
with pytest.raises(ValueError):
Circle(radius=-5)
with pytest.raises(ValueError):
Cone(radius=5, height=-10)
with pytest.raises(ValueError):
Rhombus.from_side_and_angle(side=10, angle=0)
with pytest.raises(ValueError):
Rhombus.from_side_and_angle(side=10, angle=-10)
with pytest.raises(ValueError):
Rhombus.from_side_and_angle(side=10, angle=190)
with pytest.raises(ValueError):
Rhombus(a=10, height=15)
with pytest.raises(ValueError):
Triangle(a=20, b=30, c=40).get_median(side_index=4)