def test_collision_effect(self): po = PhysicsObject(50, 50, 1, 50, [(25, 75), (25, 75)]) for i in range(0, 1000): po._vel = Vector(random.randint(0, self.MAX_RANDOM_VELOCITY), random.randint(0, self.MAX_RANDOM_VELOCITY)) expected_velocity = po._vel * PhysicsObject.COEFFICIENT_OF_BORDER_COLLISION po.collision_effect() self.assertTrue(abs(po._vel.x - expected_velocity.x) < 0.1 and abs(po._vel.y - expected_velocity.y) < 0.1)
def test_friction(self): po = PhysicsObject(50, 50, 1, 50, [(25, 75), (25, 75)]) for i in range(0, 1000): po._vel = Vector(random.randint(0, self.MAX_RANDOM_VELOCITY), random.randint(0, self.MAX_RANDOM_VELOCITY)) expected_velocity = po._vel * PhysicsObject.COEFFICIENT_OF_FRICTION \ if po._vel > PhysicsObject.STOPPING_VELOCITY else 0 po.friction() self.assertTrue(abs(po._vel.x - expected_velocity.x) < 0.1 and abs(po._vel.y - expected_velocity.y) < 0.1)