def test_to_cards():
    assert set(to_cards("T9s")) == {
        holecards("Tc 9c"),
        holecards("Td 9d"),
        holecards("Th 9h"),
        holecards("Ts 9s"),
    }
def test_has_two_overcards():
    assert has_two_overcards(holecards('Kh Ts'), flop('4c 3h 2d'))
    assert has_two_overcards(holecards('Ac Kc'),
                             flop('Tc Th 5d'))  # Even though pair on board
    assert has_two_overcards(holecards('Qd Qc'),
                             flop('Tc 4h 5d'))  # Even though it's a pair
    assert not has_two_overcards(holecards('Ac 4h'), flop('5c 5h Qd'))
    assert not has_two_overcards(holecards('Kh Ts'), flop('Qd Qc Qs'))
def test_five_cards_decorator():
    with pytest.raises(ConflictingCards):
        is_onepair(holecards('Ac Ac'), flop('Tc Th 5d'))

    with pytest.raises(ConflictingCards):
        is_3straight(holecards('Ac Tc'), flop('Tc Th 5d'))

    with pytest.raises(ConflictingCards):
        is_3flush(holecards('Ac 5d'), flop('Tc Th 5d'))

    with pytest.raises(ValueError):
        is_onepair(holecards('Ac'), flop('Tc Th 5d'))
def test_has_two_gap():
    assert has_two_gap(holecards('Ad Jd'))
    assert has_two_gap(holecards('Ad 4c'))
    assert has_two_gap(holecards('Ts 7h'))
    assert not has_two_gap(holecards('Ad Qd'))
    assert not has_two_gap(holecards('Ad 3c'))
    assert not has_two_gap(holecards('Ts 8h'))
def test_is_connected():
    assert is_connected(holecards('Ad 2c'))
    assert is_connected(holecards('Ad Kc'))
    assert is_connected(holecards('Jh Th'))
    assert not is_connected(holecards('Ad Qc'))
    assert not is_connected(holecards('4h 2h'))
    assert not is_connected(holecards('Jc 9c'))
def test_has_one_gap():
    assert has_one_gap(holecards('Ad Qd'))
    assert has_one_gap(holecards('Ad 3c'))
    assert has_one_gap(holecards('Ts 8h'))
    assert not has_one_gap(holecards('Ad Kd'))
    assert not has_one_gap(holecards('Ad 2c'))
    assert not has_one_gap(holecards('Ts 9h'))
def test_is_suited():
    assert is_suited(holecards('Ad Kd'))
    assert is_suited(holecards('Ad 2d'))
    assert is_suited(holecards('Ts 9s'))
    assert not is_suited(holecards('Ad Kc'))
    assert not is_suited(holecards('Ah 2s'))
    assert not is_suited(holecards('Tc 9h'))
def test_is_pair():
    assert is_pair(holecards('Ad Ac'))
    assert is_pair(holecards('Ts Td'))
    assert is_pair(holecards('2c 2d'))
    assert not is_pair(holecards('Ks Qs'))
    assert not is_pair(holecards('Ac 2d'))
    assert not is_pair(holecards('Td 9d'))
Example #9
0
def test_is_bluffcandidate():
    assert is_bluffcandidate(holecards('2c 3c'), flop('4c Jh Qd'))
    assert is_bluffcandidate(holecards('9h Th'), flop('3c Jh Qd'))
    assert is_bluffcandidate(holecards('Ac 3c'), flop('2c Jh Qd'))
    assert not is_bluffcandidate(holecards('2c 4h'), flop('Tc Jh Qd'))
    assert not is_bluffcandidate(holecards('2c Th'), flop('3c Jh Ad'))
    assert not is_bluffcandidate(holecards('Ac 3c'), flop('2c Jh Ad'))  # It's a pair
def test_is_onepair():
    assert is_onepair(holecards('2c 4h'),
                      flop('Tc Th 5d'),
                      exclude_board=False)
    assert is_onepair(holecards('2c Th'),
                      flop('Tc 4h 5d'),
                      exclude_board=False)
    assert is_onepair(holecards('2c 2h'), flop('Ac Kh Qd'), exclude_board=True)
    assert is_onepair(holecards('2c Qh'), flop('Ac Kh Qd'), exclude_board=True)
    assert not is_onepair(
        holecards('2c 4h'), flop('5c Jh Qd'), exclude_board=False)
    assert not is_onepair(
        holecards('4c Ah'), flop('5c 5h Qd'), exclude_board=True)
def test_is_3flush():
    assert is_3flush(holecards('2c 4h'),
                     flop('Td Jd Qd'),
                     required_holecards=0)
    assert is_3flush(holecards('2c Th'),
                     flop('3h Jh Qd'),
                     required_holecards=1)
    assert is_3flush(holecards('2d 4d'),
                     flop('5d Jh Qh'),
                     required_holecards=2)
    assert not is_3flush(
        holecards('2c 4c'), flop('Ts Jh Qd'), required_holecards=0)
    assert not is_3flush(
        holecards('2c Th'), flop('3c Jh Qd'), required_holecards=1)
    assert not is_3flush(
        holecards('2c 4c'), flop('5s Jh Qd'), required_holecards=2)
def test_is_3straight():
    assert is_3straight(holecards('2c 4h'),
                        flop('Tc Jh Qd'),
                        required_holecards=0)
    assert is_3straight(holecards('2c Th'),
                        flop('3c Jh Qd'),
                        required_holecards=1)
    assert is_3straight(holecards('2c 3h'),
                        flop('4c Jh Qd'),
                        required_holecards=2)
    assert not is_3straight(
        holecards('2c 4h'), flop('5c Jh Qd'), required_holecards=0)
    assert not is_3straight(
        holecards('2c 4h'), flop('5c Jh Qd'), required_holecards=1)
    assert not is_3straight(
        holecards('2c 4c'), flop('5c Jh Ad'), required_holecards=2)
Example #13
0
def test_get_bluffcandidates():
    assert set(get_bluffcandidates(flop('2s 4s Ac'))) == {
        holecards('Kc Qc'),
        holecards('6c 5c'),
    }

    assert set(get_bluffcandidates(flop('6s 6d Kc'))) == {
        holecards('Qd Jd'),
        holecards('Qc Jc'),
        holecards('Qs Js'),
        holecards('8s 7s'),
        holecards('8c 7c'),
        holecards('8d 7d'),
        holecards('5d 4d'),
        holecards('5c 4c'),
        holecards('5s 4s'),
        holecards('Ad Qd'),
        holecards('Ac Qc'),
        holecards('As Qs'),
    }

    # TODO: This hand exists in the bluff candidate set, but actually
    # it's an open-ended straight draw which makes it a semi-bluff.
    assert holecards('6c 5c') in set(get_bluffcandidates(flop('4s 7s Ac')))
def to_cards(text):
    return [holecards(name) for name in translate(text)]