示例#1
0
def cards():
    return [
        Card(value=9, suit="DIAMONDS"),
        Card(value=9, suit="CLUBS"),
        Card(value=10, suit="SPADES"),
        Card(value="K", suit="DIAMONDS"),
        Card(value="ACE", suit="HEARTS"),
    ]
示例#2
0
def test_deck_add_another_deck(deck, cards):
    """Test extracting all cards of one deck to another specified deck"""
    second_deck = Deck(
        (Card(value="ACE", suit="DIAMONDS"), Card(value="ACE", suit="SPADES")))
    expected = list(deck) + list(second_deck)
    deck.fetch_all(second_deck)
    assert second_deck.size == 7
    assert not sum([not card in expected for card in second_deck])
示例#3
0
def cards() -> List[Card]:
    """Return list of cards"""
    return [
        Card(value=9, suit="DIAMONDS"),
        Card(value=9, suit="CLUBS"),
        Card(value=10, suit="SPADES"),
        Card(value="K", suit="DIAMONDS"),
        Card(value="ACE", suit="HEARTS"),
    ]
示例#4
0
文件: main.py 项目: aviaowl/snap_game
def generate_deck(deck_number: int) -> List[Card]:
    """Method for generate requested amount of card decks
    Args:
        deck_number (int): requested amount of card
        """
    all_cards = list(product([i for i in range(2, 15)],
                             CARD_SUITS)) * deck_number
    shuffle(all_cards)
    return [Card(*card) for card in all_cards]
示例#5
0
def test_player_pile_size(player):
    """Check that pile size is changing after new cards addition"""
    assert player.pile_size == 0
    player.pile.add_card(Card(value="Q", suit="SPADES"))
    assert player.pile_size == 1
示例#6
0
def test_card_init(value: int, suit: str):
    """Test Card object initialization, all card numbers
    that greater than 10 should be converted to string"""
    card = Card(value=value, suit=suit)
    assert card.value == value
    assert card.suit == suit
示例#7
0
        ("4", "DIAMONDS"),
        ("5", "CLUBS"),
        ("J", "SPADES"),
        ("Q", "HEARTS"),
        ("K", "DIAMONDS"),
        ("ACE", "CLUBS"),
    ],
)
def test_card_init(value: int, suit: str):
    """Test Card object initialization, all card numbers
    that greater than 10 should be converted to string"""
    card = Card(value=value, suit=suit)
    assert card.value == value
    assert card.suit == suit


@pytest.mark.parametrize(
    "first_card, second_card, expected",
    [
        (Card("3", "HEARTS"), Card("2", "DIAMONDS"), False),
        (Card("3", "SPADES"), Card("13", "HEARTS"), False),
        (Card("11", "HEARTS"), Card("12", "HEARTS"), False),
        (Card("3", "HEARTS"), Card("3", "DIAMONDS"), True),
        (Card("14", "SPADES"), Card("14", "CLUBS"), True),
        (Card("3", "HEARTS"), Card("3", "HEARTS"), True),
    ],
)
def test_card_comparison(first_card: Card, second_card: Card, expected: bool):
    """Test cards comparison: cards are True if their values are equal"""
    assert (first_card == second_card) == expected
示例#8
0
def test_deck_add_card(deck):
    """Test card's addition"""
    assert deck.size == 5
    deck.add_card(Card(value="ACE", suit="CLUBS"))
    assert deck.size == 6
    assert deck.get_card() == Card(value="ACE", suit="CLUBS")