Skip to content

Commit

Permalink
Use fixtures for circle and rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiguelvargasf committed Apr 8, 2024
1 parent afe45a6 commit 828b967
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tests/behavioral/test_servant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@
import pytest
import math

def test_calculate_area():
circle = Circle(3, Position(0, 0))
assert GeometryTools.calculate_area(circle) == math.pi * 3 ** 2

rectangle = Rectangle(4, 5, Position(0, 0))
@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 = Circle(3, Position(0, 0))
def test_calculate_perimeter(circle, rectangle):
assert GeometryTools.calculate_perimeter(circle) == 2 * math.pi * 3

rectangle = Rectangle(4, 5, Position(0, 0))
assert GeometryTools.calculate_perimeter(rectangle) == 2 * (4 + 5)

with pytest.raises(ValueError):
GeometryTools.calculate_perimeter("invalid shape")


def test_move_to():
circle = Circle(3, Position(0, 0))
def test_move_to(circle, rectangle):
new_position = Position(1, 1)
GeometryTools.move_to(circle, new_position)
assert circle.position == new_position

rectangle = Rectangle(4, 5, Position(0, 0))
new_position = Position(1, 1)
GeometryTools.move_to(rectangle, new_position)
assert rectangle.position == new_position

0 comments on commit 828b967

Please # to comment.