示例#1
0
def hand_fixture():
    deck = Deck()
    p1 = player_fixture(0)
    p2 = player_fixture(1)
    p3 = player_fixture(2)
    p4 = player_fixture(3)
    return Hand(players=[p1, p2, p3, p4], deal_style=[3, 2, 3, 2], deck=deck)
示例#2
0
def test_cards_dealt_properly(random_game_start):
    game = random_game_start
    # cards not initially dealt to players
    the_hand = game.hands[0]
    game_cards = [the_hand.top_card] + the_hand.deck.cards
    fresh_deck = Deck()
    assert [len(x.cards) == 5 for x in game.players]
    assert len(game_cards) == 4
    assert isinstance(the_hand.top_card, Card)
    lst_player_cards = []
    for x in game.players:
        for y in x.cards:
            lst_player_cards.append(y)
    # make sure all cards accounted for
    assert not [
        x for x in lst_player_cards + game_cards if x not in fresh_deck.cards
    ]
    assert not [
        x for x in fresh_deck.cards if x not in lst_player_cards + game_cards
    ]
示例#3
0
def test_trick_with_trump_led(hand_fixture):
t = Trick()
d = Deck()
p0 = Player(name='matthew', player_id=0)
p1 = Player(name='sean', player_id=1)
p2 = Player(name='sean', player_id=2)
p3 = Player(name='sean', player_id=3)
h = Hand(players=[p0, p1, p2, p3], deal_style=[3, 2, 3, 2], deck=d)
t.add_card(player=p0, card=p0.cards[0], hand=h)
t.add_card(player=p1, card=p1.cards[0], hand=h)
t.add_card(player=p2, card=p2.cards[0], hand=h)
t.add_card(player=p3, card=p3.cards[0], hand=h)

    t.add_card()
    t.cards = [Card("10", "S"), Card("10", "H"), Card("10", "D"), Card("10", "C")]
    t.led_suit = "S"
    t.led_rank = "10"
    t.players = [Player(name="Player {}".format(x), player_id=x) for x in [3, 0, 1, 2]]
    hand_fixture.set_trump("H")
    rez = t.score(hand=hand_fixture)
    print(rez)
示例#4
0
def test_get_card_ranks_by_trump_and_led_bower_led_pass():
    low_rank = 9
    d = Deck(low_rank=low_rank)

    card = Card("J", "C")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠"]

    card = Card("J", "S")
    rez = d.get_card_ranks_by_trump_and_led("C", card)
    assert [repr(x) for x in rez] == ["J♣", "J♠", "A♣", "K♣", "Q♣", "10♣", "9♣"]

    card = Card("J", "D")
    rez = d.get_card_ranks_by_trump_and_led("H", card)
    assert [repr(x) for x in rez] == ["J♥", "J♦", "A♥", "K♥", "Q♥", "10♥", "9♥"]

    card = Card("J", "H")
    rez = d.get_card_ranks_by_trump_and_led("D", card)
    assert [repr(x) for x in rez] == ["J♦", "J♥", "A♦", "K♦", "Q♦", "10♦", "9♦"]
示例#5
0
def test_get_card_ranks_by_trump_and_led_non_bower_led_pass():
    low_rank = 9
    d = Deck(low_rank=low_rank)
    card = Card("A", "S")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠"]

    # when non-bower suit is led, J should be in the rankings
    # for the non-trump and non-bower suit

    card = Card("A", "D")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♦", "K♦", "Q♦", "J♦", "10♦", "9♦"]

    card = Card("A", "H")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♥", "K♥", "Q♥", "J♥", "10♥", "9♥"]

    card = Card("A", "C")
    rez = d.get_card_ranks_by_trump_and_led("S", card)
    assert [repr(x) for x in rez] == ["J♠", "J♣", "A♠", "K♠", "Q♠", "10♠", "9♠",
                   "A♣", "K♣", "Q♣", "10♣", "9♣"]
示例#6
0
 def new_hand(self):
     deck = Deck(low_rank=self.low_rank)
     self.rotate_dealer()
     self.hands.append(Hand(players=self.players,
                            deal_style=self.deal_style,
                            deck=deck))
示例#7
0
def test_get_card_ranks_by_trump_and_led_no_trump():
    trump = None
    d = Deck(low_rank=9)
    rez = d.get_card_ranks_by_trump_and_led(trump, led_card=Card("9", "C"))
    print(rez)
示例#8
0
def test_get_non_trump_led_suit_ranks_non_bowers_same_suit_pass(suit):
    d = Deck(low_rank=9)
    s = Suit()
    symbol = s.symbols[suit]
    rez = d.get_non_trump_led_suit_ranks(trump=suit, led_suit=suit)
    assert [repr(x) for x in rez] == [x + symbol for x in ["A", "K", "Q", "10", "9"]]
示例#9
0
def test_get_non_trump_led_suit_ranks_non_bowers_different_suits_pass(trump, led, symbol):
    d = Deck(low_rank=9)
    rez = d.get_non_trump_led_suit_ranks(trump=trump, led_suit=led)
    assert [repr(x) for x in rez] == [x + symbol for x in ["A", "K", "Q", "J", "10", "9"]]
示例#10
0
def test_init_deck_low_rank_too_low_fail():
    with pytest.raises(IllegalArgumentError):
        d = Deck(low_rank=4)
示例#11
0
def test_init_deck_low_rank_ok_pass(rank, suit):
    d = Deck(low_rank=rank)
    test_card = Card(card_rank=rank, card_suit=suit)
    assert test_card in d.cards