-
Notifications
You must be signed in to change notification settings - Fork 7k
/
Copy pathtest_servant.py
37 lines (26 loc) · 1.08 KB
/
test_servant.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
from patterns.behavioral.servant import GeometryTools, Circle, Rectangle, Position
import pytest
import math
@pytest.fixture
def circle():
return Circle(3, Position(0, 0))
@pytest.fixture
def rectangle():
return Rectangle(4, 5, Position(0, 0))
def test_calculate_area(circle, rectangle):
assert GeometryTools.calculate_area(circle) == math.pi * 3 ** 2
assert GeometryTools.calculate_area(rectangle) == 4 * 5
with pytest.raises(ValueError):
GeometryTools.calculate_area("invalid shape")
def test_calculate_perimeter(circle, rectangle):
assert GeometryTools.calculate_perimeter(circle) == 2 * math.pi * 3
assert GeometryTools.calculate_perimeter(rectangle) == 2 * (4 + 5)
with pytest.raises(ValueError):
GeometryTools.calculate_perimeter("invalid shape")
def test_move_to(circle, rectangle):
new_position = Position(1, 1)
GeometryTools.move_to(circle, new_position)
assert circle.position == new_position
new_position = Position(1, 1)
GeometryTools.move_to(rectangle, new_position)
assert rectangle.position == new_position