mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Changed the method to use the built in pytest.mark.parametrize
This commit is contained in:
parent
c6e4fbd20b
commit
d041b1ea8b
@ -1,68 +1,54 @@
|
|||||||
|
import pytest
|
||||||
from tennis import TennisGame
|
from tennis import TennisGame
|
||||||
|
|
||||||
# test support code
|
|
||||||
def params(funcarglist):
|
|
||||||
def wrapper(function):
|
|
||||||
function.funcarglist = funcarglist
|
|
||||||
return function
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
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
|
# actual test code
|
||||||
class TestTennis:
|
class TestTennis:
|
||||||
|
|
||||||
@params([dict(p1Points=0, p2Points=0, score="Love-All"),
|
@pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(),[
|
||||||
dict(p1Points=1, p2Points=1, score="Fifteen-All"),
|
(0, 0, "Love-All", 'player1', 'player2'),
|
||||||
dict(p1Points=2, p2Points=2, score="Thirty-All"),
|
(1, 1, "Fifteen-All", 'player1', 'player2'),
|
||||||
dict(p1Points=3, p2Points=3, score="Forty-All"),
|
(2, 2, "Thirty-All", 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=4, score="Deuce"),
|
(3, 3, "Forty-All", 'player1', 'player2'),
|
||||||
|
(4, 4, "Deuce", 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=1, p2Points=0, score="Fifteen-Love"),
|
(1, 0, "Fifteen-Love", 'player1', 'player2'),
|
||||||
dict(p1Points=0, p2Points=1, score="Love-Fifteen"),
|
(0, 1, "Love-Fifteen", 'player1', 'player2'),
|
||||||
dict(p1Points=2, p2Points=0, score="Thirty-Love"),
|
(2, 0, "Thirty-Love", 'player1', 'player2'),
|
||||||
dict(p1Points=0, p2Points=2, score="Love-Thirty"),
|
(0, 2, "Love-Thirty", 'player1', 'player2'),
|
||||||
dict(p1Points=3, p2Points=0, score="Forty-Love"),
|
(3, 0, "Forty-Love", 'player1', 'player2'),
|
||||||
dict(p1Points=0, p2Points=3, score="Love-Forty"),
|
(0, 3, "Love-Forty", 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=0, score="Win for player1"),
|
(4, 0, "Win for player1", 'player1', 'player2'),
|
||||||
dict(p1Points=0, p2Points=4, score="Win for player2"),
|
(0, 4, "Win for player2", 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=2, p2Points=1, score="Thirty-Fifteen"),
|
(2, 1, "Thirty-Fifteen", 'player1', 'player2'),
|
||||||
dict(p1Points=1, p2Points=2, score="Fifteen-Thirty"),
|
(1, 2, "Fifteen-Thirty", 'player1', 'player2'),
|
||||||
dict(p1Points=3, p2Points=1, score="Forty-Fifteen"),
|
(3, 1, "Forty-Fifteen", 'player1', 'player2'),
|
||||||
dict(p1Points=1, p2Points=3, score="Fifteen-Forty"),
|
(1, 3, "Fifteen-Forty", 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=1, score="Win for player1"),
|
(4, 1, "Win for player1", 'player1', 'player2'),
|
||||||
dict(p1Points=1, p2Points=4, score="Win for player2"),
|
(1, 4, "Win for player2", 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=3, p2Points=2, score="Forty-Thirty"),
|
(3, 2, "Forty-Thirty", 'player1', 'player2'),
|
||||||
dict(p1Points=2, p2Points=3, score="Thirty-Forty"),
|
(2, 3, "Thirty-Forty", 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=2, score="Win for player1"),
|
(4, 2, "Win for player1", 'player1', 'player2'),
|
||||||
dict(p1Points=2, p2Points=4, score="Win for player2"),
|
(2, 4, "Win for player2", 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=4, p2Points=3, score="Advantage player1"),
|
(4, 3, "Advantage player1", 'player1', 'player2'),
|
||||||
dict(p1Points=3, p2Points=4, score="Advantage player2"),
|
(3, 4, "Advantage player2", 'player1', 'player2'),
|
||||||
dict(p1Points=5, p2Points=4, score="Advantage player1"),
|
(5, 4, "Advantage player1", 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=5, score="Advantage player2"),
|
(4, 5, "Advantage player2", 'player1', 'player2'),
|
||||||
dict(p1Points=15, p2Points=14, score="Advantage player1"),
|
(15, 14, "Advantage player1", 'player1', 'player2'),
|
||||||
dict(p1Points=14, p2Points=15, score="Advantage player2"),
|
(14, 15, "Advantage player2", 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=6, p2Points=4, score="Win for player1"),
|
(6, 4, 'Win for player1', 'player1', 'player2'),
|
||||||
dict(p1Points=4, p2Points=6, score="Win for player2"),
|
(4, 6, 'Win for player2', 'player1', 'player2'),
|
||||||
dict(p1Points=16, p2Points=14, score="Win for player1"),
|
(16, 14, 'Win for player1', 'player1', 'player2'),
|
||||||
dict(p1Points=14, p2Points=16, score="Win for player2"),
|
(14, 16, 'Win for player2', 'player1', 'player2'),
|
||||||
|
|
||||||
dict(p1Points=6, p2Points=4, score="Win for One", p1Name='One'),
|
(6, 4, 'Win for One', 'One', 'player2'),
|
||||||
dict(p1Points=4, p2Points=6, score="Win for Two", p2Name="Two"),
|
(4, 6, 'Win for Two', 'player1', 'Two'),
|
||||||
dict(p1Points=6, p2Points=5, score="Advantage One", p1Name='One'),
|
(6, 5, 'Advantage One', 'One', 'player2'),
|
||||||
dict(p1Points=5, p2Points=6, score="Advantage Two", p2Name="Two"),
|
(5, 6, 'Advantage Two', 'player1', 'Two')
|
||||||
])
|
])
|
||||||
def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name):
|
def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name):
|
||||||
game = TennisGame(p1Name, p2Name)
|
game = TennisGame(p1Name, p2Name)
|
||||||
for i in range(p1Points):
|
for i in range(p1Points):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user