Skip to content

Commit ff95a29

Browse files
committed
Add test class for Rings.
1 parent 012f17f commit ff95a29

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/shapes/test_circles.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,39 @@ def test_is_circle(self, shape):
7171
shape.cy + shape.r * np.sin(angles),
7272
):
7373
assert pytest.approx(shape.distance(x, y)) == 0
74+
75+
76+
class TestRings(CirclesModuleTestBase):
77+
"""Test the Rings class."""
78+
79+
shape_name = 'rings'
80+
distance_test_cases = [[(20, 50), 3.16987], [(10, 25), 9.08004]]
81+
repr_regex = (
82+
r'^<Rings>\n'
83+
r' circles=\n'
84+
r' <Circle cx=(\d+\.*\d*) cy=(\d+\.*\d*) r=(\d+\.*\d*)>\n'
85+
r' <Circle cx=(\d+\.*\d*) cy=(\d+\.*\d*) r=(\d+\.*\d*)>'
86+
)
87+
88+
@pytest.mark.parametrize('num_rings', [3, 5])
89+
def test_init(self, shape_factory, num_rings):
90+
"""Test that the Rings contains multiple concentric circles."""
91+
shape = shape_factory.generate_shape(self.shape_name, num_rings=num_rings)
92+
93+
assert len(shape.circles) == num_rings
94+
assert all(
95+
getattr(circle, center_coord) == getattr(shape.circles[0], center_coord)
96+
for circle in shape.circles[1:]
97+
for center_coord in ['cx', 'cy']
98+
)
99+
assert len({circle.r for circle in shape.circles}) == num_rings
100+
101+
@pytest.mark.parametrize('num_rings', ['3', -5, 1, True])
102+
def test_num_rings_is_valid(self, shape_factory, num_rings):
103+
"""Test that num_rings input validation is working."""
104+
if isinstance(num_rings, int):
105+
with pytest.raises(ValueError, match='num_rings must be greater than 1'):
106+
_ = shape_factory.generate_shape(self.shape_name, num_rings=num_rings)
107+
else:
108+
with pytest.raises(TypeError, match='num_rings must be an integer'):
109+
_ = shape_factory.generate_shape(self.shape_name, num_rings=num_rings)

0 commit comments

Comments
 (0)