def test_serialize_hand(): hand = Hand( [Card('2', 'c'), Card('3', 'h'), Card('4', 's'), Card('Q', 'h')]) assert Hand.deserialize(hand.serialize()) == hand
def test_trick_leader(): trick = Trick([ (P3, Card('5', 'h')), (P2, Card('3', 'h')), (P1, Card('J', 'h')), (P4, Card('Q', 's')), ]) assert trick.leader() == P3
def test_serialize(): trick = Trick([(Player('Lauren'), Card('2', 'h')), (Player('Erin'), Card('8', 's')), (Player('Jeremy'), Card('6', 'h')), (Player('Daniel'), Card('Q', 's'))]) expected_serialized = { 'Lauren': dict(turn=0, card='2h'), 'Erin': dict(turn=1, card='8s'), 'Jeremy': dict(turn=2, card='6h'), 'Daniel': dict(turn=3, card='Qs') } assert expected_serialized == trick.serialize() deserialized = Trick.deserialize(trick.serialize()) assert deserialized == trick
def test_hand(): hand = Hand( [Card('A', 'h'), Card('7', 'd'), Card('6', 'h'), Card('2', 's')]) assert Card('7', 'd') in hand assert hand.has_suit('h') assert not hand.has_suit('c') with pytest.raises(ValueError): hand = Hand([Card('d', '6')]) assert not hand.is_only_hearts() hand = Hand([Card('A', 'h'), Card('7', 'h'), Card('2', 'h')]) assert hand.is_only_hearts()
def test_card_validate(): with pytest.raises(ValueError): Card.deserialize('Ch') with pytest.raises(ValueError): Card.deserialize('Q4') with pytest.raises(ValueError): Card.deserialize('2t')
def trick(players_list=None, cards='5h,3h,Jh,Qs'): the_players = players_list or players() return Trick([(p, Card.deserialize(c)) for (p, c) in zip(the_players, cards.split(','))])
def hand(cards='Ah,7d,6h,2s'): return Hand([Card.deserialize(c) for c in cards.split(',')])
def cards(cards='Ah,7d,6h,2s'): return [Card.deserialize(c) for c in cards.split(',')]
def test_trick_length(): trick = Trick([(P1, Card('2', 'c'))]) assert len(trick) == 1 trick.cards_played.append((P2, Card('A', 'c'))) trick.cards_played.append((P3, Card('Q', 'c'))) assert len(trick) == 3
def test_card_serialize(): card = Card('A', 'h') assert 'Ah' == card.serialize() assert card == Card.deserialize('Ah')