Esempio n. 1
0
 def test_update_score(self):
     player = DummyPlayer(1)
     player.hand.draw_card(Card("A", "♠"))
     player.hand.draw_card(Card("A", "♥"))
     player.hand.draw_card(Card("2", "♥"))
     player.hand.draw_card(Card("3", "♥"))
     player.update_score()
     assert player.game_score == 1
Esempio n. 2
0
 def test_eq(self):
     card1 = Card("A", "♥")
     card2 = Card("A", "♥")
     card3 = Card("2", "♥")
     card4 = Card("2", "♣")
     assert card1 == card2
     assert not card1 == card3
     assert not card3 == card4
Esempio n. 3
0
 def test_get_score(self):
     hand = Hand()
     hand.hand = [
         Card(x, y) for x, y in [("7", "♠"), ("7", "♥"), ("8", "♦")]
     ]
     assert isinstance(hand.get_score(), int)
     assert hand.get_score() == 22
Esempio n. 4
0
 def test_rank(self):
     rank = Rank()
     values = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q',
               'K')
     suits = (u"♠", u"♥", u"♦", u"♣")
     assert rank.ranked_cards == [
         Card(value, suit) for suit in suits for value in values
     ]
Esempio n. 5
0
 def test_set_hand(self):
     hand1 = Hand()
     hand1.hand = [
         Card(x, y)
         for x, y in [("A", "♥"), ("2", "♥"), ("3",
                                               "♥"), ("T",
                                                      "♥"), ("J",
                                                             "♥"), ("Q",
                                                                    "♥")]
     ]
     hand2 = Hand()
     hand2.set_hand(hand1.hand)
     assert hand1.hand == hand2.hand
Esempio n. 6
0
 def test_get_key(self):
     test_hand = Hand()
     test_hand.hand = [
         Card(x, y)
         for x, y in [("A",
                       "♥"), ("2",
                              "♥"), ("3",
                                     "♥"), ("4",
                                            "♥"), ("T",
                                                   "♥"), ("J",
                                                          "♥"), ("Q", "♥")]
     ]
     key_string = ',  '.join(
         ["%s" % Colour.green(str((i + 1))) for i in range(7)])
     assert test_hand.get_key() == key_string
Esempio n. 7
0
 def test_sort_hand_by_suit_and_rank(self):
     sort = Sort()
     values = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q',
               'K')
     suits = ("♠", "♥", "♦", "♣")
     hand = [
         Card(values[0], suits[0]),
         Card(values[1], suits[1]),
         Card(values[2], suits[1]),
         Card(values[11], suits[1]),
         Card(values[2], suits[2]),
         Card(values[7], suits[2]),
         Card(values[10], suits[3]),
         Card(values[12], suits[3])
     ]
     hand_copy = hand[:]
     shuffle(sort.sort_hand_by_suit_and_rank(hand_copy))
     assert hand == sort.sort_hand_by_suit_and_rank(hand_copy)
Esempio n. 8
0
 def test_red_card_no_unicode(self, mocker):
     mocker.patch('rummy.deck.card.UNICODE_SUPPORT', False)
     card = Card("A", "♥")
     assert card.red_card() == "A♥"
Esempio n. 9
0
 def test_spade_glyph(self):
     card = Card("A", "♠")
     assert 'A♠' == card.get_card_colour()
Esempio n. 10
0
 def test_club_glyph(self):
     card = Card("K", "♣")
     assert 'K♣' == card.get_card_colour()
Esempio n. 11
0
 def test_heart_glyph(self):
     card = Card("T", "♥")
     assert 'T\x1b[0;31m♥\x1b[0m' == card.get_card_colour()
Esempio n. 12
0
 def test_diamond_glyph(self):
     card = Card("8", "♦")
     assert '8\x1b[0;31m♦\x1b[0m' == card.get_card_colour()
Esempio n. 13
0
 def test_red_card_plain_text(self):
     card = Card("A", "H")
     assert 'A\x1b[0;31m♥\x1b[0m' == card.get_card_colour()
Esempio n. 14
0
 def test_get_rank_key_ace(self):
     rank = Rank()
     assert 0 == rank.get_rank_key(Card('A', '♦'))
Esempio n. 15
0
 def test_get_suit_and_rank_key_king_of_clubs(self):
     rank = Rank()
     assert (3, 12) == rank.get_suit_and_rank_key(Card('K', '♣'))
Esempio n. 16
0
 def test_draw_card(self):
     hand = Hand()
     hand.draw_card(Card("A", "♥"))
     assert re.match(r'A.*?♥', str(hand))
Esempio n. 17
0
 def test_get_suit_and_rank_key_seven_of_diamonds(self):
     rank = Rank()
     assert (2, 6) == rank.get_suit_and_rank_key(Card('7', '♦'))
Esempio n. 18
0
 def test_get_hand(self):
     player = DummyPlayer(1)
     assert type(player.get_hand()) is Hand
     assert not player.get_hand().hand
     player.hand.draw_card((Card("A", "S")))
     assert player.get_hand().hand == [Card("A", "S")]
Esempio n. 19
0
 def test_get_rank_key_seven(self):
     rank = Rank()
     assert 6 == rank.get_rank_key(Card('7', '♦'))
Esempio n. 20
0
 def test_str(self):
     card = Card("A", "♥")
     assert str(card) == "A♥"
     card = Card("2", "C")
     assert str(card) == "2♣"
Esempio n. 21
0
 def test_suit_plain(self):
     card = Card("A", "H")
     assert card.suit == "♥"
Esempio n. 22
0
 def test_get_card_colour(self):
     card1 = Card("A", "H")
     card2 = Card("3", "S")
     assert 'A\x1b[0;31m♥\x1b[0m' == card1.get_card_colour()
     assert '3♠' == card2.get_card_colour()
Esempio n. 23
0
 def test_get_rank_key_ten(self):
     rank = Rank()
     assert 9 == rank.get_rank_key(Card('T', '♦'))
Esempio n. 24
0
 def test_value_ace(self):
     card = Card("A", "♥")
     assert "A" == card.value
Esempio n. 25
0
 def test_value_number(self):
     card = Card("7", "♥")
     assert "7" == card.value
Esempio n. 26
0
 def __init__(self):
     self.ranked_cards = [
         Card(value, suit) for suit in Suits.get()
         for value in FaceValues.get()
     ]
Esempio n. 27
0
 def test_get_suit_and_rank_key_ace_of_spades(self):
     rank = Rank()
     assert (0, 0) == rank.get_suit_and_rank_key(Card('A', '♠'))