예제 #1
0
def test_lead():
    card_list = [
        Deck.generate_card_from_index(card_index) for card_index in test_list
    ]
    hand = BridgeHand.generate_partially_played_hand(card_list)
    hand.lead(Card(Suits.DIAMONDS, Ranks.KING))
    assert not hand.contains_card(Card(Suits.DIAMONDS, Ranks.KING))
예제 #2
0
def test_lead_when_card_is_missing():
    card_list = [
        Deck.generate_card_from_index(card_index) for card_index in test_list
    ]
    hand = BridgeHand.generate_partially_played_hand(card_list)
    with pytest.raises(CardNotInHandException):
        hand.lead(Card(Suits.SPADES, Ranks.ACE))
예제 #3
0
def test_legal_cards():
    card_list = [
        Deck.generate_card_from_index(card_index) for card_index in test_list
    ]
    hand = BridgeHand.generate_partially_played_hand(card_list)
    legal = hand.legal_cards(Suits.DIAMONDS)
    assert Card(Suits.DIAMONDS, Ranks.ACE) in legal
예제 #4
0
def test_partial_hand_fill_and_contains(suit, rank, expected):
    card_list = [
        Deck.generate_card_from_index(card_index) for card_index in test_list
    ]
    hand = BridgeHand.generate_partially_played_hand(card_list)
    assert hand.contains_card(Card(suit, rank)) == expected
예제 #5
0
def test_card(suit, rank, expected_result, expected_except):
    with expected_except:
        card = Card(suit, rank)
        assert (card == seven_of_hearts) == expected_result
예제 #6
0
def test_card_str():
    card = Card(Suits.HEARTS, Ranks.SEVEN)
    assert str(card) == "SEVEN_HEARTS"
예제 #7
0
def test_card():
    card = Card(Suits.HEARTS, Ranks.SEVEN)
    assert card == seven_of_hearts
예제 #8
0
import sys

sys.path.insert(0, '../bridgebot')
sys.path.insert(0, '..')

from contextlib import contextmanager

from game.deck import Deck
from game.bridgehand import Card, BridgeHand, CardDoesntFollowSuitException, CardNotInHandException, RepeatedCardException, WrongSizeHandException

from game.card import InvalidSuitException, InvalidRankException

from game.enums import Ranks, Suits

deck = Deck()
seven_of_hearts = Card(Suits.HEARTS, Ranks.SEVEN)
eight_of_clubs = Card(Suits.CLUBS, Ranks.EIGHT)


@contextmanager
def does_not_raise():
    yield


def test_deck():
    indices = deck.get_card_indices()
    print(indices)  # Will be suppressed unless pytest is called with -s
    assert len(indices) == 52


def test_deck_shuffle():
import pytest
import sys
import os

# sys.path.insert(0, os.path.abspath('../bridgebot'))
sys.path.insert(0, os.path.abspath('..'))

from game import cardplay
from game.enums import Strains, Suits, Ranks
from game.bridgehand import Card


@pytest.mark.parametrize('played_cards, trump_strain, expected',
                         [([
                             Card(Suits.SPADES, Ranks.FOUR),
                             Card(Suits.HEARTS, Ranks.ACE),
                             Card(Suits.CLUBS, Ranks.ACE),
                             Card(Suits.DIAMONDS, Ranks.ACE)
                         ], Strains.SPADES, 0),
                          ([
                              Card(Suits.HEARTS, Ranks.ACE),
                              Card(Suits.SPADES, Ranks.FOUR),
                              Card(Suits.CLUBS, Ranks.ACE),
                              Card(Suits.DIAMONDS, Ranks.ACE)
                          ], Strains.SPADES, 1),
                          ([
                              Card(Suits.HEARTS, Ranks.ACE),
                              Card(Suits.CLUBS, Ranks.ACE),
                              Card(Suits.DIAMONDS, Ranks.ACE),
                              Card(Suits.SPADES, Ranks.FOUR)
                          ], Strains.SPADES, 3),