diff --git a/Tennis/python/tennis.py b/Tennis/python/tennis.py index d052593a..3f47d7f7 100644 --- a/Tennis/python/tennis.py +++ b/Tennis/python/tennis.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -class TennisGameDefactored1: +class TennisGame1: def __init__(self, player1Name, player2Name): self.player1Name = player1Name @@ -50,7 +50,7 @@ class TennisGameDefactored1: return result -class TennisGameDefactored2: +class TennisGame2: def __init__(self, player1Name, player2Name): self.player1Name = player1Name self.player2Name = player2Name @@ -150,7 +150,7 @@ class TennisGameDefactored2: def P2Score(self): self.p2points +=1 -class TennisGameDefactored3: +class TennisGame3: def __init__(self, player1Name, player2Name): self.p1N = player1Name self.p2N = player2Name @@ -173,6 +173,3 @@ 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 - -# 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 a6392b01..ccc5c099 100644 --- a/Tennis/python/tennis_test.py +++ b/Tennis/python/tennis_test.py @@ -1,13 +1,23 @@ # -*- coding: utf-8 -*- import pytest -from tennis import TennisGame +from tennis import TennisGame1, TennisGame2, TennisGame3 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 = play_game(p1Points, p2Points, p1Name, p2Name) + def test_get_score_game1(self, p1Points, p2Points, score, p1Name, p2Name): + game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name) + assert score == game.score() + + @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) + def test_get_score_game2(self, p1Points, p2Points, score, p1Name, p2Name): + game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name) + assert score == game.score() + + @pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases) + def test_get_score_game3(self, p1Points, p2Points, score, p1Name, p2Name): + game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name) assert score == game.score() diff --git a/Tennis/python/tennis_unittest.py b/Tennis/python/tennis_unittest.py index 7beb513e..91ff3fe8 100644 --- a/Tennis/python/tennis_unittest.py +++ b/Tennis/python/tennis_unittest.py @@ -2,7 +2,7 @@ import unittest -from tennis import TennisGame +from tennis import TennisGame1, TennisGame2, TennisGame3 test_cases = [ (0, 0, "Love-All", 'player1', 'player2'), @@ -51,7 +51,7 @@ test_cases = [ ] -def play_game(p1Points, p2Points, p1Name, p2Name): +def play_game(TennisGame, p1Points, p2Points, p1Name, p2Name): game = TennisGame(p1Name, p2Name) for i in range(max(p1Points, p2Points)): if i < p1Points: @@ -62,10 +62,22 @@ def play_game(p1Points, p2Points, p1Name, p2Name): class TestTennis(unittest.TestCase): - def test_Score(self): + def test_Score_Game1(self): for testcase in test_cases: (p1Points, p2Points, score, p1Name, p2Name) = testcase - game = play_game(p1Points, p2Points, p1Name, p2Name) + game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name) + self.assertEquals(score, game.score()) + + def test_Score_Game2(self): + for testcase in test_cases: + (p1Points, p2Points, score, p1Name, p2Name) = testcase + game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name) + self.assertEquals(score, game.score()) + + def test_Score_Game3(self): + for testcase in test_cases: + (p1Points, p2Points, score, p1Name, p2Name) = testcase + game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name) self.assertEquals(score, game.score()) if __name__ == "__main__":