stash.add_card arguments reordered

This commit is contained in:
Jakub Senderák
2020-03-27 15:17:58 +01:00
parent 38bf52c867
commit 5098a1aa9a
2 changed files with 26 additions and 26 deletions
+3 -3
View File
@@ -94,7 +94,7 @@ class Series():
pass
class Round():
def __init__(self, round_number: int, first_player: int, cards: [], shuffler = shuffle):
def __init__(self, round_number: int, first_player: int, cards: []=cards, shuffler = shuffle):
# vyrob kopku pre toto kolo a priprav prazdne objekty
if not 0 <= round_number < 8:
raise BridzikException('Round number has to be between 0 and 7.')
@@ -140,7 +140,7 @@ class Round():
raise BridzikException('Musi zahrat farbu.')
self.player_cards[player] = [c for c in self.player_cards[player] if c != card]
self.get_last_stash().add_card(card, player)
self.get_last_stash().add_card(player, card)
if self.get_last_stash().is_completed() and not self.is_completed():
self.start_new_stash()
@@ -201,7 +201,7 @@ class Stash():
self._cards = {}
self.first_player = first_player
def add_card(self, card: Card, player: int):
def add_card(self, player: int, card: Card):
if player not in [0, 1, 2, 3]:
raise BridzikException('Cislo hraca musi byt 0, 1, 2 alebo 3.')
if player in self._cards:
+23 -23
View File
@@ -6,11 +6,11 @@ class StashCase(unittest.TestCase):
def test_first_card(self):
heart_7 = Card(Card_colors['HEARTS'], Card_values['C7'])
s = Stash(3)
s.add_card(heart_7, 3)
s.add_card(3, heart_7)
self.assertEqual(s.get_first_card(), heart_7)
heart_8 = Card(Card_colors['HEARTS'], Card_values['C8'])
s.add_card(heart_8, 1)
s.add_card(1, heart_8)
self.assertNotEqual(s.get_first_card(), heart_8)
self.assertEqual(s.get_first_card(), heart_7)
@@ -22,13 +22,13 @@ class StashCase(unittest.TestCase):
acorns_10 = Card(Card_colors['ACORNS'], Card_values['C10'])
s = Stash(1)
s.add_card(heart_7, 1)
s.add_card(1, heart_7)
self.assertEqual(s._cards[1], heart_7)
s.add_card(leaves_7, 2)
s.add_card(2, leaves_7)
self.assertEqual(s._cards[2], leaves_7)
s.add_card(leaves_ace, 3)
s.add_card(3, leaves_ace)
self.assertEqual(s._cards[3], leaves_ace)
s.add_card(bells_10, 0)
s.add_card(0, bells_10)
self.assertEqual(s._cards[0], bells_10)
self.assertRaises(BridzikException, s.add_card, card=bells_10, player=4)
@@ -44,7 +44,7 @@ class StashCase(unittest.TestCase):
c1 = [leaves_7, heart_7, acorns_ace, bells_10]
s1 = Stash(0)
for i in range(4):
s1.add_card(c1[i], i)
s1.add_card(i, c1[i])
self.assertEqual(s1.get_winner(), 1)
# highest color takes the stash
@@ -53,14 +53,14 @@ class StashCase(unittest.TestCase):
c2 = [leaves_8, leaves_7, acorns_ace, leaves_lower]
s2 = Stash(0)
for i in range(4):
s2.add_card(c2[i], i)
s2.add_card(i, c2[i])
self.assertEqual(s2.get_winner(), 3)
# no matching color and no heart in stash
c3 = [bells_10, leaves_lower, acorns_ace, leaves_8]
s3 = Stash(0)
for i in range(4):
s3.add_card(c3[i], i)
s3.add_card(i, c3[i])
self.assertEqual(s3.get_winner(), 0)
# highest heart takes the stash
@@ -68,7 +68,7 @@ class StashCase(unittest.TestCase):
c4 = [leaves_8, leaves_lower, heart_7, heart_upper]
s4 = Stash(0)
for i in range(4):
s4.add_card(c4[i], i)
s4.add_card(i, c4[i])
self.assertEqual(s4.get_winner(), 3)
# test exceptions
@@ -82,13 +82,13 @@ class StashCase(unittest.TestCase):
bells_10 = Card(Card_colors['BELLS'], Card_values['C10'])
s = Stash(0)
self.assertEqual(s.get_cards(), {})
s.add_card(heart_7, 2)
s.add_card(2, heart_7)
self.assertEqual(s.get_cards(), {2: heart_7})
s.add_card(leaves_7, 3)
s.add_card(3, leaves_7)
self.assertEqual(s.get_cards(), {2: heart_7, 3: leaves_7})
s.add_card(acorns_ace, 0)
s.add_card(0, acorns_ace)
self.assertEqual(s.get_cards(), {2: heart_7, 3: leaves_7, 0: acorns_ace})
s.add_card(bells_10, 1)
s.add_card(1, bells_10)
self.assertEqual(s.get_cards(), {2: heart_7, 3: leaves_7, 0: acorns_ace, 1: bells_10})
def test_is_complete(self):
@@ -100,7 +100,7 @@ class StashCase(unittest.TestCase):
c = [heart_7, leaves_7, acorns_ace, bells_10]
for i in range(4):
self.assertFalse(s.is_completed())
s.add_card(c[0], i)
s.add_card(i, c[0])
self.assertTrue(s.is_completed())
def test_get_active_player(self):
@@ -111,19 +111,19 @@ class StashCase(unittest.TestCase):
s = Stash(1)
self.assertEqual(s.get_active_player(), 1)
s.add_card(heart_7, 1)
s.add_card(1, heart_7)
self.assertEqual(s.get_active_player(), 2)
s.add_card(leaves_7, 2)
s.add_card(2, leaves_7)
self.assertEqual(s.get_active_player(), 3)
s.add_card(leaves_ace, 3)
s.add_card(3, leaves_ace)
self.assertEqual(s.get_active_player(), 0)
s.add_card(bells_10, 0)
s.add_card(0, bells_10)
self.assertRaises(BridzikException, s.get_active_player)
class RoundCase(unittest.TestCase):
def test_add_player_guess(self):
r = Round(0, 1, cards)
r = Round(0, 1)
self.assertRaises(BridzikException, r.add_player_guess, player=2, guess=0)
@@ -145,7 +145,7 @@ class RoundCase(unittest.TestCase):
self.assertEqual(r.stashes[0].first_player, 0)
def test_get_highest_guessing_player(self):
r1 = Round(0, 0, cards)
r1 = Round(0, 0)
r1.add_player_guess(0, 2)
r1.add_player_guess(1, 1)
r1.add_player_guess(2, 3)
@@ -153,7 +153,7 @@ class RoundCase(unittest.TestCase):
r1.add_player_guess(3, 4)
self.assertEqual(r1.get_highest_guessing_player(), 3)
r2 = Round(0, 2, cards)
r2 = Round(0, 2)
r2.add_player_guess(2, 5)
r2.add_player_guess(3, 0)
r2.add_player_guess(0, 1)
@@ -161,7 +161,7 @@ class RoundCase(unittest.TestCase):
self.assertEqual(r2.get_highest_guessing_player(), 2)
def test_get_active_player(self):
r = Round(6, 1, cards)
r = Round(6, 1)
self.assertEqual(r.get_active_player(), 1)
r.add_player_guess(1, 1)
self.assertEqual(r.get_active_player(), 2)