예제 #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_have_virtual_shape(self):
        self.experiment.CreateAntShapeType("body")
        self.experiment.CreateAntShapeType("antenna")
        a = self.experiment.CreateAnt()
        self.assertEqual(len(a.Capsules), 0)
        c1 = m.Capsule((0, 0), (1, 1), 1, 1)
        c2 = m.Capsule((0, 0), (-1, -1), 1, 1)
        with self.assertRaises(ValueError):
            a.AddCapsule(42, c1)
        a.AddCapsule(1, c1)
        a.AddCapsule(1, c2)
        a.AddCapsule(2, c1)

        self.assertEqual(len(a.Capsules), 3)
        self.assertEqual(a.Capsules[0][1], c1)
        self.assertEqual(a.Capsules[1][1], c2)
        self.assertEqual(a.Capsules[2][1], c1)

        with self.assertRaises(IndexError):
            a.DeleteCapsule(42)

        a.DeleteCapsule(1)
        self.assertEqual(len(a.Capsules), 2)
        self.assertEqual(a.Capsules[0][1], c1)
        self.assertEqual(a.Capsules[1][1], c1)

        a.ClearCapsules()
        self.assertEqual(len(a.Capsules), 0)
예제 #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_ant_shape_type_manipulation(self):
        bodyID = self.experiment.CreateAntShapeType("body")
        headID = self.experiment.CreateAntShapeType("head")
        self.assertTrue(bodyID in self.experiment.AntShapeTypeNames)
        self.assertTrue(headID in self.experiment.AntShapeTypeNames)
        self.assertEqual(self.experiment.AntShapeTypeNames[bodyID], "body")
        self.assertEqual(self.experiment.AntShapeTypeNames[headID], "head")

        with self.assertRaises(IndexError):
            self.experiment.SetAntShapeTypeName(42, "foo")

        self.experiment.SetAntShapeTypeName(bodyID, "foo")

        with self.assertRaises(IndexError):
            self.experiment.DeleteAntShapeType(42)

        a = self.experiment.CreateAnt()
        a.AddCapsule(bodyID, m.Capsule([0, 0], [1, 1], 1, 1))

        with self.assertRaises(RuntimeError):
            self.experiment.DeleteAntShapeType(bodyID)

        self.experiment.DeleteAntShapeType(headID)
예제 #9
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)