def test_radius_changes_logged(self): circle = Circle(2) self.assertEqual(circle.radius_changes, [2]) circle.radius = 3 self.assertEqual(circle.radius_changes, [2, 3]) circle.diameter = 3 self.assertEqual(circle.radius_changes, [2, 3, 1.5])
def test_change_radius(): c = Circle(4) assert c.diameter == 8 c.radius = 5 assert c.radius == 5 assert c.diameter == 10
def test_equality(self): circleA = Circle(2) circleB = Circle(2) circleC = Circle(1) self.assertTrue(circleA == circleB) self.assertTrue(circleB != circleC != circleA) self.assertFalse(circleA != circleB) self.assertFalse(circleA == circleC) self.assertFalse(circleB == circleC) circleC.radius = 2 self.assertTrue(circleA == circleB == circleC) self.assertFalse(circleB != circleC) self.assertFalse(circleA != circleC)
def test_no_negative_radius(self): circle = Circle(2) with self.assertRaises(ValueError) as context: circle.radius = -10 self.assertEqual(str(context.exception), "Radius cannot be negative")
def test_diameter_changes(self): circle = Circle(2) self.assertEqual(circle.diameter, 4) circle.radius = 3 self.assertEqual(circle.diameter, 6)