def testLimitVelocity(self): vel = (1,1) self.ship.setVel(vel) self.ship.limitVelocity() newVel = self.ship.getVel() newVelScalar = tupleLength(newVel) self.failIf(newVelScalar > Ship.SPEED_MAX) self.failIf(newVelScalar < 0) vel = (Ship.SPEED_MAX, Ship.SPEED_MAX) self.ship.setVel(vel) self.ship.limitVelocity() newVel = self.ship.getVel() newVelScalar = tupleLength(newVel) self.failUnless( abs(newVelScalar - Ship.SPEED_MAX) < 0.01)
def limitVelocity(self): shipVel = self.getVel() newVelScalar = tupleLength(shipVel) if newVelScalar > Ship.SPEED_MAX: newVelScale = Ship.SPEED_MAX / newVelScalar newVel = scaleTuple(shipVel, newVelScale) self.setVel(newVel)
def testTupleLength(self): self.failUnlessEqual( tupleLength( (3, 4) ), 5)
def testTupleLength(self): self.failUnlessEqual(tupleLength((3, 4)), 5)