@@ -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