Ejemplo n.º 1
0
	def test_entities_set(self):
		from bGrease.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)
Ejemplo n.º 2
0
	def test_remove_and_contains(self):
		from bGrease.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)
Ejemplo n.º 3
0
	def test_len(self):
		from bGrease.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)