Пример #1
0
 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)
Пример #2
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()))
Пример #3
0
class WorldTests(unittest.TestCase):
    def setUp(self):
        self.world = World()

    def test_particle_collision(self):
        p1 = LinearParticle(10, 10)
        p2 = LinearParticle(12, 10)
        p2.radius = p1.radius = 10

        self.world.bind(p1)
        self.world.bind(p2)
        self.world.update(0)

        self.assertEquals(p1.position.y, p2.position.y)
        self.assertEquals(p2.position.x - p1.position.x, 20)
        self.assertEquals(p1.collisions, 1)
        self.assertEquals(p2.collisions, 1)
        self.world.update(0)
        self.assertEquals(p1.collisions, 1)
        self.assertEquals(p2.collisions, 1)
Пример #4
0
 def setUp(self):
     self.world = World()