def testMemory(self): """Deleted particles are removed from the World they are bound to""" p = LinearParticle(0, 0) w = World() w.bind(p) self.assert_(w.num_particles() == 1) del p self.assert_(w.num_particles() == 0)
class WorldTest(unittest.TestCase): def setUp(self): self.world = World() def testRange(self): p = LinearParticle(1, 0) q = LinearParticle(3, 0) self.world.bind(p) self.world.bind(q) self.assert_(self.world.num_particles() == 2) v = self.world.particles_in_range(p, 1) self.assert_(len(v) == 0) v = self.world.particles_in_range(p, 2) self.assert_(len(v) == 1) self.assert_(v[0].this == q.this) # same underlying object hopefully def testObstacles(self): ls = Obstacle(Vec2d(0, 0), Vec2d(1, 2)) self.world.bind(ls) self.assert_(len(self.world.get_obstacles()))