diff --git a/Tennis/python/tennis.py b/Tennis/python/tennis.py index 83a14c6d..7a4a3408 100644 --- a/Tennis/python/tennis.py +++ b/Tennis/python/tennis.py @@ -173,4 +173,6 @@ class TennisGameDefactored3: return "Deuce" s = self.p1N if self.p1 > self.p2 else self.p2N return "Advantage " + s if ((self.p1-self.p2)*(self.p1-self.p2) == 1) else "Win for " + s -TennisGame = TennisGameDefactored3 + +# NOTE: You must change this to point at the one of the three examples that you're working on! +TennisGame = TennisGameDefactored1 diff --git a/Tennis/python/tennis_test.py b/Tennis/python/tennis_test.py index 450b14b0..bfc64aba 100644 --- a/Tennis/python/tennis_test.py +++ b/Tennis/python/tennis_test.py @@ -1,16 +1,11 @@ import pytest from tennis import TennisGame -from tennis_unittest import test_cases +from tennis_unittest import test_cases, play_game class TestTennis: @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) 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) + game = play_game(p1Points, p2Points, p1Name, p2Name) assert score == game.score() - diff --git a/Tennis/python/tennis_unittest.py b/Tennis/python/tennis_unittest.py index f2eca430..3b181df5 100644 --- a/Tennis/python/tennis_unittest.py +++ b/Tennis/python/tennis_unittest.py @@ -1,4 +1,5 @@ import unittest +from itertools import izip_longest from tennis import TennisGame @@ -49,16 +50,21 @@ test_cases = [ ] +def play_game(p1Points, p2Points, p1Name, p2Name): + game = TennisGame(p1Name, p2Name) + for p1, p2 in izip_longest(range(p1Points), range(p2Points)): + if p1 is not None: + game.won_point(p1Name) + if p2 is not None: + game.won_point(p2Name) + return game + class TestTennis(unittest.TestCase): 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) + game = play_game(p1Points, p2Points, p1Name, p2Name) self.assertEquals(score, game.score()) if __name__ == "__main__":