mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Fixed an issue where the tests weren't really doing a realistic game. Now the players exchange points instead of one player scoring all theirs, and the other player scoring all theirs.
This commit is contained in:
parent
5fb9f52b48
commit
52fb51eede
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
@ -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__":
|
||||
|
||||
Loading…
Reference in New Issue
Block a user