Ejemplo n.º 1
0
class RackerTest(unittest.TestCase):
    def setUp(self):
        self.racket = Racket(constants.SCREEN_MARGIN, constants.SCREEN_MARGIN)

    def test_update_position(self):
        """Tests the position update in the regular way"""
        self.racket.update_position(1)
        self.assertEqual(constants.SCREEN_MARGIN + 4, self.racket.position["y"])

    def test_update_position_with_acceleration(self):
        """Tests the position update with an acceleration factor"""
        self.racket.update_position(1, 30)
        self.assertEqual(constants.SCREEN_MARGIN + 4, self.racket.position["y"])
        self.assertEqual(self.racket.acceleration, 4)

    def test_update_position_with_deceleration(self):
        """Tests the position update with a deceleration factor"""
        self.racket.update_position(1, -22)
        self.assertEqual(constants.SCREEN_MARGIN + 3, self.racket.position["y"])
        self.assertEqual(self.racket.acceleration, 3)

    def test_limit_top(self):
        """Test that the racket cannot go beyond top limit"""
        self.racket.update_position(-3)
        self.assertEqual(constants.SCREEN_MARGIN, self.racket.position["y"])

    def test_limit_bottom(self):
        """Test that the racket cannot go beyond top limit"""
        position = constants.SCREEN_HEIGHT
        position -= constants.SCREEN_MARGIN
        position -= self.racket.dimension["height"]
        self.racket.update_position(position + 1)
        self.assertEqual(position, self.racket.position["y"])