def test_containsRegion_Rectangular(self): """Test the containsRegion method when passed a RectangularRegion.""" unit = RectangularRegion(x1=0, y1=0, x2=10, y2=10) self.assertTrue(unit.containsRegion(unit), "it should contain itself") self.assertTrue( unit.containsRegion(RectangularRegion(x1=0, y1=0, x2=10, y2=10)), "it should contain a RectangularRegion representing the same geometric region" ) self.assertTrue( unit.containsRegion(RectangularRegion(x1=2, y1=2, x2=8, y2=8)), "it should contain a RectangularRegion inside") self.assertTrue( unit.containsRegion(RectangularRegion(x1=0, y1=4, x2=5, y2=6)), "it should contain a RectangularRegion inside, but tangent to the left edge" ) self.assertTrue( unit.containsRegion(RectangularRegion(x1=5, y1=4, x2=10, y2=6)), "it should contain a RectangularRegion inside, but tangent to the right edge" ) self.assertTrue( unit.containsRegion(RectangularRegion(x1=4, y1=0, x2=6, y2=5)), "it should contain a RectangularRegion inside, but tangent to the bottom edge" ) self.assertTrue( unit.containsRegion(RectangularRegion(x1=4, y1=5, x2=6, y2=10)), "it should contain a RectangularRegion inside, but tangent to the top edge" ) self.assertFalse( unit.containsRegion(RectangularRegion(x1=-1, y1=0, x2=5, y2=5)), "it should not contain a RectangularRegion that extends outside") self.assertFalse( unit.containsRegion(RectangularRegion(x1=-1, y1=0, x2=5, y2=5)), "it should not contain a RectangularRegion that extends outside")
def test_containsRegion_Circular(self): """Test the containsRegion method when passed a CircularRegion.""" unit = RectangularRegion(x1=0, y1=0, x2=10, y2=10) self.assertTrue(unit.containsRegion(CircularRegion(cx=5, cy=5, r=1)), "it should contain a CircularRegion inside") self.assertTrue( unit.containsRegion(CircularRegion(cx=1, cy=5, r=1)), "it should contain a CircularRegion inside, but tangent to the left edge" ) self.assertTrue( unit.containsRegion(CircularRegion(cx=9, cy=5, r=1)), "it should contain a CircularRegion inside, but tangent to the right edge" ) self.assertTrue( unit.containsRegion(CircularRegion(cx=5, cy=1, r=1)), "it should contain a CircularRegion inside, but tangent to the bottom edge" ) self.assertTrue( unit.containsRegion(CircularRegion(cx=5, cy=9, r=1)), "it should contain a CircularRegion inside, but tangent to the top edge" ) self.assertTrue( unit.containsRegion(CircularRegion(cx=5, cy=5, r=5)), "it should contain a CircularRegion inside, but tangent to all edges" ) self.assertFalse( unit.containsRegion(CircularRegion(cx=5, cy=5, r=5.1)), "it should not contain a CircularRegion that extends outside") self.assertFalse( unit.containsRegion(CircularRegion(cx=5, cy=5, r=10)), "it should not contain a CircularRegion containing this region") self.assertFalse( unit.containsRegion(CircularRegion(cx=20, cy=20, r=1)), "it should not contain a CircularRegion completely outside")
def test_containsRegion_NotRegion(self): """Test the containsRegion method when passed an unsupported type.""" unit = RectangularRegion(x1=0, y1=0, x2=10, y2=10) with self.assertRaises(ValueError): unit.containsRegion("NotARegionInstance")