Exemple #1
0
 def test_entities_set(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     self.assertEqual(len(c.entities), 0)
     entity1 = TestEntity()
     entity2 = TestEntity()
     entity3 = TestEntity()
     c.set(entity1)
     c.set(entity2)
     c.set(entity3)
     self.assertEqual(len(c.entities), 3)
     self.assertTrue(entity1 in c.entities)
     self.assertTrue(entity2 in c.entities)
     self.assertTrue(entity3 in c.entities)
     c.remove(entity2)
     self.assertEqual(len(c.entities), 2)
     self.assertTrue(entity1 in c.entities)
     self.assertFalse(entity2 in c.entities)
     self.assertTrue(entity3 in c.entities)
Exemple #2
0
 def test_entities_set(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     self.assertEqual(len(c.entities), 0)
     entity1 = TestEntity()
     entity2 = TestEntity()
     entity3 = TestEntity()
     c.set(entity1)
     c.set(entity2)
     c.set(entity3)
     self.assertEqual(len(c.entities), 3)
     self.assertTrue(entity1 in c.entities)
     self.assertTrue(entity2 in c.entities)
     self.assertTrue(entity3 in c.entities)
     c.remove(entity2)
     self.assertEqual(len(c.entities), 2)
     self.assertTrue(entity1 in c.entities)
     self.assertFalse(entity2 in c.entities)
     self.assertTrue(entity3 in c.entities)
Exemple #3
0
 def test_remove_and_contains(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     e1 = TestEntity()
     e2 = TestEntity()
     self.assertFalse(c.remove(e1))
     c.set(e1)
     c.set(e2)
     self.assertTrue(c.remove(e1))
     self.assertTrue(e1 in c)
     c.step(0)
     self.assertFalse(e1 in c)
     self.assertTrue(e2 in c)
     self.assertFalse(c.remove(e1))
     c.step(0)
     self.assertTrue(c.remove(e2))
     self.assertTrue(e2 in c)
     c.step(0)
     self.assertFalse(e2 in c)
     self.assertFalse(e2 in c)
Exemple #4
0
 def test_remove_and_contains(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     e1 = TestEntity()
     e2 = TestEntity()
     self.assertFalse(c.remove(e1))
     c.set(e1)
     c.set(e2)
     self.assertTrue(c.remove(e1))
     self.assertTrue(e1 in c)
     c.step(0)
     self.assertFalse(e1 in c)
     self.assertTrue(e2 in c)
     self.assertFalse(c.remove(e1))
     c.step(0)
     self.assertTrue(c.remove(e2))
     self.assertTrue(e2 in c)
     c.step(0)
     self.assertFalse(e2 in c)
     self.assertFalse(e2 in c)
Exemple #5
0
 def test_len(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     self.assertEqual(len(c), 0)
     self.assertEqual(len(c.entities), 0)
     entities = [TestEntity() for _ in range(50)]
     [c.set(e) for e in entities]
     self.assertEqual(len(c), 50)
     self.assertEqual(len(c.entities), 50)
     [c.remove(e) for e in entities[:25]]
     self.assertEqual(len(c.entities), 25)
     self.assertEqual(len(c), 50)
     c.step(0)
     self.assertEqual(len(c), 25)
     self.assertEqual(len(c.entities), 25)
Exemple #6
0
 def test_len(self):
     from grease.component import Component
     c = Component()
     c.set_world(world)
     self.assertEqual(len(c), 0)
     self.assertEqual(len(c.entities), 0)
     entities = [TestEntity() for _ in range(50)]
     [c.set(e) for e in entities]
     self.assertEqual(len(c), 50)
     self.assertEqual(len(c.entities), 50)
     [c.remove(e) for e in entities[:25]]
     self.assertEqual(len(c.entities), 25)
     self.assertEqual(len(c), 50)
     c.step(0)
     self.assertEqual(len(c), 25)
     self.assertEqual(len(c.entities), 25)