예제 #1
0
def test_hand(app) -> None:
    '''Test hand.'''
    hand = Hand()
    hand.add_card(Card('A', 'S'))
    db.session.add(hand)
    db.session.commit()

    card = hand.pull_card('A', 'S')
    assert card.rank == 'A'
    assert card.suit == 'S'
예제 #2
0
파일: test_deck.py 프로젝트: kuwv/spades
def test_deck(app):
    '''Test deck.'''
    deck = Deck()
    db.session.add(deck)
    db.session.commit()

    cards = [Card(rank, suit) for rank in Card.ranks for suit in Card.suits]
    for card in cards:
        assert card in deck.cards

    for card in deck:
        assert card not in deck.cards

    db.session.delete(deck)
    db.session.commit()
예제 #3
0
def test_book(app):
    '''Test card in book.'''
    book = Book()
    db.session.add(book)

    # Add test player
    player = Player.query.filter_by(username='******').first()
    if not player:
        player = Player(username='******')
        db.session.add(player)

    # Add test card
    card = Card.query.filter(Card.rank == 'K', Card.suit == 'S').first()
    if not card:
        card = Card('K', 'S')
        db.session.add(card)
    db.session.commit()

    play = Play(
        inspect(book).identity[0],
        inspect(player).identity[0],
        inspect(card).identity[0])
    db.session.add(play)
    db.session.commit()
    book.add_play(play)
    db.session.add(book)
    db.session.commit()
    print('plays:', book.plays)
    query = db.session.query(Play, Player)\
        .filter(Book.id == Play.book_id)\
        .filter(Play.player_id == Player.id)\
        .filter(Player.username == 'test1')\
        .first()
    print('player', query)
    assert book.suit == 'S'
    assert book.high_card == card
    assert book.broken is True
예제 #4
0
파일: deck.py 프로젝트: kuwv/spades
 def __init__(self) -> None:
     '''Initialize Deck.'''
     for rank in Card.ranks:
         for suit in Card.suits:
             self.cards.append(Card(rank, suit))
예제 #5
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card_comparison_error() -> None:
    '''Test card comparison error.'''
    with pytest.raises(InvalidComparisonCardException):
        Card('T', 'H') > Card('T', 'C')
예제 #6
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card_suit_error() -> None:
    '''Test card suit error.'''
    with pytest.raises(InvalidSuitCardException):
        Card('T', 'blah')
예제 #7
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card_rank_error() -> None:
    '''Tst card rank error.'''
    with pytest.raises(InvalidRankCardException):
        Card('blah', 'H')
예제 #8
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card_greater_suit() -> None:
    '''Test card value comparison.'''
    ten_hearts = Card('T', 'H')
    jack_hearts = Card('J', 'H')
    assert jack_hearts > ten_hearts
예제 #9
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card_greater_spades() -> None:
    '''Test card value comparison.'''
    two_clubs = Card('2', 'C')
    ace_spades = Card('A', 'S')
    assert ace_spades > two_clubs
예제 #10
0
파일: test_card.py 프로젝트: kuwv/spades
def test_card() -> None:
    '''Test card object.'''
    card = Card('K', 'S')
    assert card.rank == 'K'
    assert card.suit == 'S'