コード例 #1
0
def test_serialize_hand():
    hand = Hand(
        [Card('2', 'c'),
         Card('3', 'h'),
         Card('4', 's'),
         Card('Q', 'h')])
    assert Hand.deserialize(hand.serialize()) == hand
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
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()
コード例 #5
0
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')
コード例 #6
0
ファイル: fake.py プロジェクト: agentbond007/lonely-hearts
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(','))])
コード例 #7
0
ファイル: fake.py プロジェクト: agentbond007/lonely-hearts
def hand(cards='Ah,7d,6h,2s'):
    return Hand([Card.deserialize(c) for c in cards.split(',')])
コード例 #8
0
ファイル: fake.py プロジェクト: agentbond007/lonely-hearts
def cards(cards='Ah,7d,6h,2s'):
    return [Card.deserialize(c) for c in cards.split(',')]
コード例 #9
0
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
コード例 #10
0
def test_card_serialize():
    card = Card('A', 'h')
    assert 'Ah' == card.serialize()
    assert card == Card.deserialize('Ah')