mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
run all the tests on all the versions all the time
This commit is contained in:
parent
d15c470937
commit
80cf89cef7
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
class TennisGameDefactored1:
|
class TennisGame1:
|
||||||
|
|
||||||
def __init__(self, player1Name, player2Name):
|
def __init__(self, player1Name, player2Name):
|
||||||
self.player1Name = player1Name
|
self.player1Name = player1Name
|
||||||
@ -50,7 +50,7 @@ class TennisGameDefactored1:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class TennisGameDefactored2:
|
class TennisGame2:
|
||||||
def __init__(self, player1Name, player2Name):
|
def __init__(self, player1Name, player2Name):
|
||||||
self.player1Name = player1Name
|
self.player1Name = player1Name
|
||||||
self.player2Name = player2Name
|
self.player2Name = player2Name
|
||||||
@ -150,7 +150,7 @@ class TennisGameDefactored2:
|
|||||||
def P2Score(self):
|
def P2Score(self):
|
||||||
self.p2points +=1
|
self.p2points +=1
|
||||||
|
|
||||||
class TennisGameDefactored3:
|
class TennisGame3:
|
||||||
def __init__(self, player1Name, player2Name):
|
def __init__(self, player1Name, player2Name):
|
||||||
self.p1N = player1Name
|
self.p1N = player1Name
|
||||||
self.p2N = player2Name
|
self.p2N = player2Name
|
||||||
@ -173,6 +173,3 @@ class TennisGameDefactored3:
|
|||||||
return "Deuce"
|
return "Deuce"
|
||||||
s = self.p1N if self.p1 > self.p2 else self.p2N
|
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
|
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
|
|
||||||
|
|||||||
@ -1,13 +1,23 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from tennis import TennisGame
|
from tennis import TennisGame1, TennisGame2, TennisGame3
|
||||||
|
|
||||||
from tennis_unittest import test_cases, play_game
|
from tennis_unittest import test_cases, play_game
|
||||||
|
|
||||||
class TestTennis:
|
class TestTennis:
|
||||||
|
|
||||||
@pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases)
|
@pytest.mark.parametrize('p1Points p2Points score p1Name p2Name'.split(), test_cases)
|
||||||
def test_get_score(self, p1Points, p2Points, score, p1Name, p2Name):
|
def test_get_score_game1(self, p1Points, p2Points, score, p1Name, p2Name):
|
||||||
game = play_game(p1Points, p2Points, 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()
|
assert score == game.score()
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from tennis import TennisGame
|
from tennis import TennisGame1, TennisGame2, TennisGame3
|
||||||
|
|
||||||
test_cases = [
|
test_cases = [
|
||||||
(0, 0, "Love-All", 'player1', 'player2'),
|
(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)
|
game = TennisGame(p1Name, p2Name)
|
||||||
for i in range(max(p1Points, p2Points)):
|
for i in range(max(p1Points, p2Points)):
|
||||||
if i < p1Points:
|
if i < p1Points:
|
||||||
@ -62,10 +62,22 @@ def play_game(p1Points, p2Points, p1Name, p2Name):
|
|||||||
|
|
||||||
class TestTennis(unittest.TestCase):
|
class TestTennis(unittest.TestCase):
|
||||||
|
|
||||||
def test_Score(self):
|
def test_Score_Game1(self):
|
||||||
for testcase in test_cases:
|
for testcase in test_cases:
|
||||||
(p1Points, p2Points, score, p1Name, p2Name) = testcase
|
(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())
|
self.assertEquals(score, game.score())
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user