예제 #1
0
 def test_card3(self):
     card = Card("5", "s")
     assert card.get_rank() == "5"
     assert card.get_rank() != "T"
     assert card.get_rank() != "6"
     assert card.get_rank() != "s"
     assert card.get_rank() != "c"
예제 #2
0
    def test_hand_figures_out_high_card_is_best_rank(self):
        cards = [
            Card(rank='Ace', suit='Clubs'),
            Card(rank='6', suit='Spades')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'High Card'
 def test_off_suit_hand_type(self):
     from app.card import Card
     card1 = Card("A", "s")
     card2 = Card("T", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "ATo"
     assert str(hand.hand_type()) != "ATs"
예제 #4
0
 def test_queen_of_clubs(self):
     assert str(Card("Q", "c")) == "Qc"  # Both correct
     assert str(Card("Q", "c")) != "Qd"  # Rank correct, suit incorrect
     assert str(Card("Q", "c")) != "Jc"  # Rank incorrect, suit correct
     assert str(Card("Q", "c")) != "5h"  # Both incorrect
     assert str(
         Card("Q", "c")
     ) != "2d"  # Both incorrect; but both correct for card above which shouldn't be cached
 def test_suited_hand_type(self):
     from app.card import Card
     card1 = Card("8", "h")
     card2 = Card("6", "h")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "86s"
     assert str(hand.hand_type()) != "86o"
예제 #6
0
    def test_hand_recieves_and_stores_cards(self):
        cards = [
            Card(rank='Queen', suit='Hearts'),
            Card(rank='3', suit='Diamonds')
        ]

        hand = Hand(cards=cards)
        assert hand.cards == cards
예제 #7
0
def jars_test(position, jar):
    if Card.objects(card_in_jar=jar, card_active=position):

        found_active = Card.objects(card_in_jar=jar,
                                    card_active=position).get()
        return found_active
    else:
        return template_card
 def test_order_2_same_no_sort_needed(self):
     from app.card import Card
     card1 = Card("J", "h")
     card2 = Card("J", "c")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Jh" and str(oc2) == "Jc"
     assert str(oc1) != "Jc" and str(oc2) != "Jh"
 def test_order_1_num_1_bw_no_sort_needed(self):
     from app.card import Card
     card1 = Card("A", "c")
     card2 = Card("4", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ac" and str(oc2) == "4d"
     assert str(oc1) != "4d" and str(oc2) != "Ac"
 def test_order_2_bw_sort_needed(self):
     from app.card import Card
     card1 = Card("T", "d")
     card2 = Card("K", "c")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Kc" and str(oc2) == "Td"
     assert str(oc1) != "Td" and str(oc2) != "Kc"
     assert str(card1) == "Td" and str(card2) == "Kc"
 def test_order_1_num_1_bw_sort_needed(self):
     from app.card import Card
     card1 = Card("2", "h")
     card2 = Card("K", "s")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ks" and str(oc2) == "2h"
     assert str(oc1) != "2h" and str(oc2) != "Ks"
     assert str(card1) == "2h" and str(card2) == "Ks"
 def test_pair_hand_type(self):
     from app.card import Card
     card1 = Card("Q", "c")
     card2 = Card("Q", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     assert str(hand.hand_type()) == "QQ"
     assert str(hand.hand_type()) != "QQs"
     assert str(hand.hand_type()) != "QQo"
     assert str(hand.hand_type()) != "QcQd"
예제 #13
0
    def test_deck_removes_cards_from_its_collection(self):
        card1 = Card(rank='Ace', suit='Spades')
        card2 = Card(rank='4', suit='Diamonds')
        cards = [card1, card2]

        deck = Deck()
        deck.add_cards(cards)

        assert deck.remove_cards(1) == [card1]
        assert deck.cards == [card2]
예제 #14
0
    def test_desk_shuffles_cards(self, mock_shuffle):
        deck = Deck()
        cards = [
            Card(rank='7', suit='Diamonds'),
            Card(rank='3', suit='Spades')
        ]
        deck.add_cards(cards)
        deck.shuffle()

        assert mock_shuffle.called_once_with(cards)
 def test_order_2_same_sort_needed(self):
     """This really never requires a sort; however, it will still be sorted alphabetically."""
     from app.card import Card
     card1 = Card("A", "s")
     card2 = Card("A", "d")
     hand = Hand()
     hand.hole_cards = [card1, card2]
     oc1, oc2 = hand.order_hand()
     assert str(oc1) == "Ad" and str(oc2) == "As"
     assert str(oc1) != "As" and str(oc2) != "Ad"
     assert str(card1) == "As" and str(card2) == "Ad"
예제 #16
0
    def get_jar_positions(position):
        if Card.objects(card_in_jar=jar_from_url, card_active=position):

            found_active = Card.objects(card_in_jar=jar_from_url,
                                        card_active=position).get()
            return found_active

        else:
            # template card assigned at top
            # of this file for all routes to use
            return template_card
예제 #17
0
    def test_hand_figures_out_full_house_is_best_rank(self):
        cards = [
            Card(rank='3', suit='Clubs'),
            Card(rank='3', suit='Hearts'),
            Card(rank='3', suit='Diamonds'),
            Card(rank='9', suit='Spades'),
            Card(rank='9', suit='Diamonds')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Full House'
예제 #18
0
    def test_hand_figures_out_four_of_a_kind_is_best_rank(self):
        cards = [
            Card(rank='7', suit='Spades'),
            Card(rank='King', suit='Clubs'),
            Card(rank='7', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Four of a Kind'
예제 #19
0
    def test_hand_figures_out_straight_is_best_rank(self):
        cards = [
            Card(rank='3', suit='Hearts'),
            Card(rank='4', suit='Spades'),
            Card(rank='5', suit='Hearts'),
            Card(rank='6', suit='Diamonds'),
            Card(rank='7', suit='Clubs')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Straight'
예제 #20
0
    def test_hand_figures_out_two_pair_is_best_rank(self):
        cards = [
            Card(rank='Ace', suit='Spades'),
            Card(rank='9', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='Ace', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Two Pair'
예제 #21
0
    def test_hand_figures_out_single_pair_is_best_rank(self):
        cards = [
            Card(rank='Jack', suit='Spades'),
            Card(rank='4', suit='Clubs'),
            Card(rank='7', suit='Diamonds'),
            Card(rank='King', suit='Diamonds'),
            Card(rank='7', suit='Hearts')
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Pair'
예제 #22
0
 def load_cards(self, card_deck_struct, n):
     """
     Делает и описательной структуры физическую колоду
     и производит валидацию, верно ли заполнена структура
     В конце смотрит, на какое количество игроков сформировать колоду
     """
     cards = []
     for c in card_deck_struct:
         if not isinstance(c["_uuids"], list):
             raise TypeError("Type error " + c["name"])
         if len(c["_uuids"]) == 0:
             raise IndexError("Index error: " + c["name"])
         if len(c["_uuids"]) != len(c["_players"]):
             raise IndexError("Index error: len_index!=len " + c["name"])
         index = c["_uuids"][0]
         for i, subcard_index in enumerate(c["_uuids"]):
             if i + index != subcard_index:
                 raise IndexError("Skipped index: " + c["name"])
             # Карта не предусмотрена на это количество игроков
             if c["_players"][i] > n:
                 continue
             cards.append(
                 Card({
                     "uuid": subcard_index,
                     "players": c["_players"][i],
                     **{
                         k: v
                         for k, v in c.items() if k not in [
                             "_uuids", "_players"
                         ]
                     }
                 }))
     return cards
예제 #23
0
 def __init__(self):
     super().__init__([Card(x, y) for x in values for y in suits],
                      maxlen=52)
     shuffle(self)
     self.burn = []
     self.pot = 0
     self.cur_bet = 0
예제 #24
0
    def test_hand_figures_out_straight_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['2', '3', '4', '5', '6']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Straight Flush'
예제 #25
0
    def test_cards_are_sorted(self):
        ace_of_hearts = Card(rank='Ace', suit='Hearts')
        six_of_spades = Card(rank='6', suit='Spades')
        six_of_hearts = Card(rank='6', suit='Hearts')
        nine_of_diamonds = Card(rank='9', suit='Diamonds')
        ten_of_clubs = Card(rank='10', suit='Clubs')

        cards = [
            ace_of_hearts, nine_of_diamonds, six_of_spades, ten_of_clubs,
            six_of_hearts
        ]

        cards.sort()
        assert cards == [
            six_of_spades, six_of_hearts, nine_of_diamonds, ten_of_clubs,
            ace_of_hearts
        ]
예제 #26
0
    def test_hand_figures_out_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['2', '5', '8', '10', 'Ace']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Flush'
예제 #27
0
    def test_hand_figures_out_royal_flush_is_best_rank(self):
        cards = [
            Card(rank=rank, suit='Diamonds')
            for rank in ['10', 'Jack', 'Queen', 'King', 'Ace']
        ]

        hand = Hand(cards=cards)
        assert hand.best_rank() == 'Royal Flush'
예제 #28
0
파일: hand.py 프로젝트: andrewguo5/spades
 def __init__(self, card1, card2):
     if card1 > card2:
         self.card1 = card1
         self.card2 = card2
     elif card2 > card1:
         self.card1 = card2
         self.card2 = card1
     elif Card.same_suit(card1, card2):
         raise ValueError("Both cards cannot be identical: %s, %s." % (card1, card2))
     else:
         self.card1 = card1
         self.card2 = card2
예제 #29
0
 def test_card3(self):
     card = Card("3", "c")
     assert card.get_suit() == "c"
     assert card.get_suit() != "K"
     assert card.get_suit() != "9"
     assert card.get_suit() != "3"
     assert card.get_suit() != "d"
     assert card.get_suit() != "h"
     assert card.get_suit() != "s"
예제 #30
0
def test_constructors():
    a = Card(1)
    print(a)

    b = Card(5)
    print(b)

    c = a > b
    print(c)

    print(a.value_name())

    As = Card(4)
    Th = Card(52)
    print(Th)
    AT = Hand(As, Th)

    print(AT)