Ejemplo n.º 1
0
 def test_Entity_world(self):
     world = ebs.World()
     world2 = ebs.World()
     ent1 = ebs.Entity(world)
     ent2 = ebs.Entity(world2)
     self.assertEqual(ent1.world, world)
     self.assertNotEqual(ent1.world, world2)
     self.assertEqual(ent2.world, world2)
     self.assertNotEqual(ent2.world, world)
     self.assertNotEqual(ent1.world, ent2.world)
Ejemplo n.º 2
0
    def test_World_delete_entities(self):
        w = ebs.World()
        e1 = ebs.Entity(w)
        e2 = ebs.Entity(w)

        self.assertEqual(len(w.entities), 2)
        w.delete_entities((e1, e2))
        self.assertEqual(len(w.entities), 0)
        # The next should have no effect
        w.delete_entities((e1, e2))
Ejemplo n.º 3
0
    def test_Entity(self):
        world = ebs.World()
        world.add_system(PositionSystem())

        e = ebs.Entity(world)
        e2 = ebs.Entity(world)
        self.assertIsInstance(e, ebs.Entity)
        self.assertIsInstance(e2, ebs.Entity)
        self.assertNotEqual(e, e2)

        p = PositionEntity(world)
        self.assertIsInstance(p, PositionEntity)
        self.assertIsInstance(p, ebs.Entity)
Ejemplo n.º 4
0
    def test_World_delete(self):
        w = ebs.World()
        e1 = ebs.Entity(w)
        e2 = ebs.Entity(w)

        self.assertEqual(len(w.entities), 2)
        w.delete(e1)
        self.assertEqual(len(w.entities), 1)
        w.delete(e2)
        self.assertEqual(len(w.entities), 0)

        # The next two should have no effect
        w.delete(e1)
        w.delete(e2)
Ejemplo n.º 5
0
    def test_Entity_delete(self):
        w = ebs.World()
        e1 = ebs.Entity(w)
        e2 = ebs.Entity(w)

        self.assertEqual(len(w.entities), 2)
        e1.delete()
        self.assertEqual(len(w.entities), 1)
        e2.delete()
        self.assertEqual(len(w.entities), 0)

        # The next two should have no effect
        e1.delete()
        e2.delete()
Ejemplo n.º 6
0
    def test_World_entities(self):
        w = ebs.World()
        self.assertEqual(len(w.entities), 0)

        for x in range(100):
            ebs.Entity(w)
        self.assertEqual(len(w.entities), 100)
Ejemplo n.º 7
0
    def test_World_add_remove_system(self):
        world = ebs.World()
        self.assertIsInstance(world, ebs.World)

        class SimpleSystem(object):
            def __init__(self):
                self.componenttypes = (Position, )

            def process(self, world, components):
                pass

        for method in (world.add_system, world.remove_system):
            for val in (None, "Test", Position, ebs.Entity(world)):
                self.assertRaises(ValueError, method, val)

        psystem = SimpleSystem()
        world.add_system(psystem)
        self.assertTrue(len(world.systems) != 0)
        self.assertTrue(psystem in world.systems)
        world.remove_system(psystem)
        self.assertTrue(len(world.systems) == 0)
        self.assertTrue(psystem not in world.systems)

        psystem = PositionSystem()
        world.add_system(psystem)
        self.assertTrue(len(world.systems) != 0)
        self.assertTrue(psystem in world.systems)

        entity = PositionEntity(world)
        self.assertIsInstance(entity.position, Position)

        world.remove_system(psystem)
        self.assertTrue(len(world.systems) == 0)
        self.assertTrue(psystem not in world.systems)

        # The data must stay intact in the world, even if the processing
        # system has been removed.
        self.assertIsInstance(entity.position, Position)
Ejemplo n.º 8
0
 def test_Entity_id(self):
     world = ebs.World()
     ent1 = ebs.Entity(world)
     ent2 = ebs.Entity(world)
     self.assertNotEqual(ent1.id, ent2.id)