def play_game(p1Points, p2Points, p1Name, p2Name):
    game = TennisGame(p1Name, p2Name)
    for i in range(max(p1Points, p2Points)):
        if i < p1Points:
            game.won_point(p1Name)
        if i < p2Points:
            game.won_point(p2Name)
    return game
Exemplo n.º 2
0
 def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name):
     game = TennisGame(p1Name, p2Name)
     for i in range(p1Points):
         game.won_point(p1Name)
     for i in range(p2Points):
         game.won_point(p2Name)
     assert score == game.score()
Exemplo n.º 3
0
 def test_Score(self):
     for testcase in test_cases:
         (p1Points, p2Points, score, p1Name, p2Name) = testcase
         game = TennisGame(p1Name, p2Name)
         for i in range(p1Points):
             game.won_point(p1Name)
         for i in range(p2Points):
             game.won_point(p2Name)
         self.assertEquals(score, game.score())
Exemplo n.º 4
0
 def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name):
     game = TennisGame(p1Name, p2Name)
     for i in range(p1Points):
         game.won_point(p1Name)
     for i in range(p2Points):
         game.won_point(p2Name)
     assert score == game.score()
Exemplo n.º 5
0
def play_game(p1Points, p2Points, p1Name, p2Name):
    game = TennisGame(p1Name, p2Name)
    for i in range(max(p1Points, p2Points)):
        if i < p1Points:
            game.won_point(p1Name)
        if i < p2Points:
            game.won_point(p2Name)
    return game
 def test_Score(self):
     for testcase in test_cases:
         (p1Points, p2Points, score, p1Name, p2Name) = testcase
         game = TennisGame(p1Name, p2Name)
         for i in range(p1Points):
             game.won_point(p1Name)
         for i in range(p2Points):
             game.won_point(p2Name)
         self.assertEquals(score, game.score())
Exemplo n.º 7
0
class TestTennisGame(TestCase):
    def setUp(self):
        self.game = TennisGame()

    def test_something(self):
        initial_score = self.game.score
        self.assertEqual("Love all", initial_score)

    def test_score_is_15_0_when_p1_scored_once(self):
        self._create_score(1, 0)
        self.assertEqual("Fifteen Love", self.game.score)

    def test_score_is_15_15_when_both_scored_once(self):
        self._create_score(1, 1)
        self.assertEqual("Fifteen all", self.game.score)

    def test_score_is_0_15_when_p2_scored_once(self):
        self._create_score(0, 1)
        self.assertEqual("Love Fifteen", self.game.score)

    def test_score_is_0_30_when_p2_scored_twice(self):
        self._create_score(0, 2)
        self.assertEqual("Love Thirty", self.game.score)

    def test_score_is_30_0_when_p1_scored_twice(self):
        self._create_score(2, 0)
        self.assertEqual("Thirty Love", self.game.score)

    def test_score_is_30_15_when_p1_scored_twice_and_p1_scored_once(self):
        self._create_score(2, 1)
        self.assertEqual("Thirty Fifteen", self.game.score)

    def test_score_is_40_15_when_p1_scored_three_times_and_p2_scored_once(
            self):
        self._create_score(3, 1)
        self.assertEqual("Forty Fifteen", self.game.score)

    def test_game_for_p1_when_scored_four_times(self):
        self._create_score(4, 0)
        self.assertEqual("Game for P1", self.game.score)

    def test_game_for_p2_when_scored_four_times(self):
        self._create_score(0, 4)
        self.assertEqual("Game for P2", self.game.score)

    def test_deuce(self):
        self._create_score(4, 4)
        self.assertEqual("Deuce", self.game.score)

    def test_deuce_when_both_scored_seven_times(self):
        self._create_score(7, 7)
        self.assertEqual("Deuce", self.game.score)

    def test_advantage_p1_when_score_5_4(self):
        self._create_score(5, 4)
        self.assertEqual("Advantage P1", self.game.score)

    def test_advantage_p1_when_score_12_11(self):
        self._create_score(12, 11)
        self.assertEqual("Advantage P1", self.game.score)

    def test_advantage_p2_when_score_4_5(self):
        self._create_score(4, 5)
        self.assertEqual("Advantage P2", self.game.score)

    def test_advantage_p2_when_score_11_12(self):
        self._create_score(11, 12)
        self.assertEqual("Advantage P2", self.game.score)

    def test_game_for_p1_after_deuce(self):
        self._create_score(6, 4)
        self.assertEqual("Game for P1", self.game.score)

    def test_game_for_p2_after_deuce(self):
        self._create_score(4, 6)
        self.assertEqual("Game for P2", self.game.score)

    def test_game_for_p1_when_score_24_22(self):
        self._create_score(24, 22)
        self.assertEqual("Game for P1", self.game.score)

    def _create_score(self, player_one_score, player_two_score):
        for _ in range(player_one_score):
            self.game.player_one_scored()

        for _ in range(player_two_score):
            self.game.player_two_scored()
Exemplo n.º 8
0
def when_score_is_forty_love_and_p1_score_then_game_is_over_test():
  tennis = TennisGame(Score.FORTY, Score.LOVE)
  tennis.score_player(1)
  assert tennis.is_over 
Exemplo n.º 9
0
def when_score_is_thirty_love_and_p1_score_then_game_is_not_over_test():
  tennis = TennisGame(Score.THIRTY, Score.LOVE)
  tennis.score_player(1)
  assert not tennis.is_over
Exemplo n.º 10
0
def when_score_is_forty_all_and_p1_score_then_game_is_not_over_test():
  tennis = TennisGame(Score.FORTY, Score.FORTY)
  tennis.score_player(1)
  assert not tennis.is_over
Exemplo n.º 11
0
def when_score_is_love_all_and_p1_score_then_score_is_fifteen_love_test():
  tennis = TennisGame()
  tennis.score_player(1)
  assert tennis.score == (Score.FIFTEEN, Score.LOVE)
Exemplo n.º 12
0
def when_score_is_love_forty_and_p2_score_then_game_is_over_test():
  tennis = TennisGame(Score.LOVE, Score.FORTY)
  tennis.score_player(2)
  assert tennis.is_over
Exemplo n.º 13
0
def when_score_is_love_all_and_p1_score_then_game_is_not_over_test():
  tennis = TennisGame()
  tennis.score_player(1)
  assert not tennis.is_over
Exemplo n.º 14
0
def when_score_is_love_all_and_p1_score_then_game_is_not_over_test():
    tennis = TennisGame()
    tennis.score_player(1)
    assert not tennis.is_over
Exemplo n.º 15
0
 def setUp(self):
     self.game = TennisGame()
Exemplo n.º 16
0
def when_score_is_love_forty_and_p2_score_then_game_is_over_test():
    tennis = TennisGame(Score.LOVE, Score.FORTY)
    tennis.score_player(2)
    assert tennis.is_over
Exemplo n.º 17
0
def when_score_is_love_all_and_p1_score_then_score_is_fifteen_love_test():
    tennis = TennisGame()
    tennis.score_player(1)
    assert tennis.score == (Score.FIFTEEN, Score.LOVE)
Exemplo n.º 18
0
def when_score_is_forty_love_and_p1_score_then_game_is_over_test():
    tennis = TennisGame(Score.FORTY, Score.LOVE)
    tennis.score_player(1)
    assert tennis.is_over
Exemplo n.º 19
0
def when_score_is_love_all_then_game_is_not_over_test():
    tennis = TennisGame()
    assert not tennis.is_over
Exemplo n.º 20
0
def when_score_is_thirty_love_and_p1_score_then_game_is_not_over_test():
    tennis = TennisGame(Score.THIRTY, Score.LOVE)
    tennis.score_player(1)
    assert not tennis.is_over
Exemplo n.º 21
0
def when_score_is_forty_all_and_p1_score_then_game_is_not_over_test():
    tennis = TennisGame(Score.FORTY, Score.FORTY)
    tennis.score_player(1)
    assert not tennis.is_over