예제 #1
0
 def test_is_subscribable(self):
     p = m.ShapeList([m.Circle(), m.Capsule()])
     self.assertEqual(len(p), 2)
     npt.assert_almost_equal(p[0].Center, [0, 0])
     npt.assert_almost_equal(p[1].C2, [1, 1])
     p[0] = m.Capsule()
     npt.assert_almost_equal(p[0].C2, [1, 1])
예제 #2
0
 def test_initialization(self):
     p = m.ShapeList()
     self.assertEqual(len(p), 0)
     p = m.ShapeList([m.Circle()])
     self.assertEqual(len(p), 1)
     with self.assertRaises(RuntimeError):
         p = m.ShapeList([1, 2, 3])
예제 #3
0
 def setUp(self):
     self.circle = m.Circle(Center=[0, 0], Radius=1.0)
     self.capsule = m.Capsule(C1=[0, 0], C2=[1, 1], R1=1.0, R2=1.0)
     self.polygon = m.Polygon(Vertices=[
         [1, 1],
         [-1, 1],
         [-1, -1],
         [1, -1],
     ])
예제 #4
0
 def test_is_popable(self):
     p = m.ShapeList([m.Circle(), m.Capsule(), m.Polygon()])
     self.assertEqual(type(p.pop()), m.Polygon)
     self.assertEqual(len(p), 2)
     self.assertEqual(type(p.pop(1)), m.Capsule)
     self.assertEqual(len(p), 1)
     self.assertEqual(type(p.pop(0)), m.Circle)
     self.assertEqual(len(p), 0)
     with self.assertRaises(IndexError):
         p.pop()
예제 #5
0
 def test_is_extendable(self):
     p = m.ShapeList()
     self.assertEqual(len(p), 0)
     p.append(m.Circle())
     self.assertEqual(len(p), 1)
     p.extend([m.Capsule(), m.Polygon()])
     self.assertEqual(len(p), 3)
     npt.assert_almost_equal(p[0].Center, [0, 0])
     npt.assert_almost_equal(p[1].C2, [1, 1])
     npt.assert_almost_equal(p[2].Vertices[0], [1, 1])
예제 #6
0
 def test_zone_definition_have_a_shape(self):
     zone = self.space.CreateZone("food")
     definition = zone.AddDefinition([])
     circle = m.Circle(Center=[0, 0], Radius=1)
     capsule = m.Capsule(C1=[0, 0], C2=[1, 1], R1=1, R2=1)
     self.assertEqual(len(definition.Shapes), 0)
     definition.Shapes = [circle, capsule]
     self.assertEqual(len(definition.Shapes), 2)
     self.assertEqual(definition.Shapes[0], circle)
     self.assertEqual(definition.Shapes[1], capsule)
예제 #7
0
 def test_wrap_mutable_elements(self):
     p = m.ShapeList([m.Circle(), m.Capsule(), m.Polygon()])
     p[0].Center = [1, 2]
     p[1].C2 = [3, 4]
     p[2].Vertices[3] = [5, 6]
     npt.assert_almost_equal(p[0].Center, [1, 2])
     npt.assert_almost_equal(p[0].Radius, 1)
     npt.assert_almost_equal(p[1].C1, [0, 0])
     npt.assert_almost_equal(p[1].R1, 1)
     npt.assert_almost_equal(p[1].C2, [3, 4])
     npt.assert_almost_equal(p[1].R2, 1)
     npt.assert_almost_equal(p[2].Vertices[0], [1, 1])
     npt.assert_almost_equal(p[2].Vertices[1], [-1, 1])
     npt.assert_almost_equal(p[2].Vertices[2], [-1, -1])
     npt.assert_almost_equal(p[2].Vertices[3], [5, 6])
예제 #8
0
 def test_is_iterable(self):
     p = m.ShapeList([m.Capsule(), m.Circle(), m.Polygon()])
     for i, v in enumerate(p):
         self.assertEqual(int(v.ShapeType), i)
예제 #9
0
 def test_is_clearable(self):
     p = m.ShapeList([m.Circle()])
     self.assertEqual(len(p), 1)
     p.clear()
     self.assertEqual(len(p), 0)