Merge pull request #1 from FredrikWendt/master

added test and fix - players' names weren't used
This commit is contained in:
Emily Bache 2011-10-07 11:05:06 -07:00
commit 3ebd6a3629
2 changed files with 21 additions and 12 deletions

View File

@ -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):

View File

@ -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()