From 33fa98f175bd33bafa2983ee0610e634a78ba0e2 Mon Sep 17 00:00:00 2001 From: Fredrik Wendt Date: Fri, 7 Oct 2011 00:50:32 +0200 Subject: [PATCH] added test and fix - player's names weren't used --- Tennis/python/tennis.py | 16 ++++++++-------- Tennis/python/tennis_test.py | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Tennis/python/tennis.py b/Tennis/python/tennis.py index af859684..e7e33791 100644 --- a/Tennis/python/tennis.py +++ b/Tennis/python/tennis.py @@ -27,13 +27,13 @@ class TennisGameDefactored1: elif (self.p1points>=4 or self.p2points>=4): minusResult = self.p1points-self.p2points if (minusResult==1): - result ="Advantage player1" + result ="Advantage " + self.player1Name elif (minusResult ==-1): - result ="Advantage player2" + result ="Advantage " + self.player2Name elif (minusResult>=2): - result = "Win for player1" + result = "Win for " + self.player1Name else: - result ="Win for player2" + result ="Win for " + self.player2Name else: for i in range(1,3): if (i==1): @@ -124,15 +124,15 @@ class TennisGameDefactored2: result = P1res + "-" + P2res if (self.p1points > self.p2points and self.p2points >= 3): - result = "Advantage player1" + result = "Advantage " + self.player1Name if (self.p2points > self.p1points and self.p1points >= 3): - result = "Advantage player2" + result = "Advantage " + self.player2Name if (self.p1points>=4 and self.p2points>=0 and (self.p1points-self.p2points)>=2): - result = "Win for player1" + result = "Win for " + self.player1Name if (self.p2points>=4 and self.p1points>=0 and (self.p2points-self.p1points)>=2): - result = "Win for player2" + result = "Win for " + self.player2Name return result def SetP1Score(self, number): diff --git a/Tennis/python/tennis_test.py b/Tennis/python/tennis_test.py index e12198db..2c5afe81 100644 --- a/Tennis/python/tennis_test.py +++ b/Tennis/python/tennis_test.py @@ -10,6 +10,10 @@ def params(funcarglist): def pytest_generate_tests(metafunc): for funcargs in getattr(metafunc.function, 'funcarglist', ()): + if "p1Name" not in funcargs: + funcargs["p1Name"] = "player1" + if "p2Name" not in funcargs: + funcargs["p2Name"] = "player2" metafunc.addcall(funcargs=funcargs) # actual test code @@ -53,12 +57,17 @@ class TestTennis: dict(p1Points=4, p2Points=6, score="Win for player2"), dict(p1Points=16, p2Points=14, score="Win for player1"), dict(p1Points=14, p2Points=16, score="Win for player2"), + + dict(p1Points=6, p2Points=4, score="Win for One", p1Name='One'), + dict(p1Points=4, p2Points=6, score="Win for Two", p2Name="Two"), + dict(p1Points=6, p2Points=5, score="Advantage One", p1Name='One'), + dict(p1Points=5, p2Points=6, score="Advantage Two", p2Name="Two"), ]) - def test_get_score(self, p1Points, p2Points, score): - game = TennisGame("player1", "player2") + def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name): + game = TennisGame(p1Name, p2Name) for i in range(p1Points): - game.won_point("player1") + game.won_point(p1Name) for i in range(p2Points): - game.won_point("player2") + game.won_point(p2Name) assert score == game.score()