def test_add_to_poker_hand():
    try:
        a_hand = PokerHand()
        a_hand.add_card(Card('S', 11))
        a_hand.add_card(Card('S', 10))
        assert_equals("Making sure that PokerHand object has add_card method.",
                      True,
                      type(a_hand) is PokerHand)
    except:
        fail_on_error("Trying to create a PokerHand object and add cards to it.",
                      sys.exc_info())
def test_create_stud_poker_hand():
    try:
        community = CommunityCardSet()
        for s, v in [('H', 2), ('H', 14), ('D', 11), ('S', 8), ('C', 8)]:
            community.add(Card(s, v))
        a_hand = StudPokerHand(community)
        assert_equals("Created a new StudPokerHand object.", True,
                      type(a_hand) is StudPokerHand)
    except:
        fail_on_error("Trying to create a StudPokerHand object.",
                      sys.exc_info())
def test_str():
    try:
        a_hand = PokerHand()
        a_hand.add_card(Card('S', 11))
        a_hand.add_card(Card('S', 10))
        a_hand_string = str(a_hand)
        assert_in("Added card 'S11'. String representation of hand should contain 'Jack of Spades'.",
                  "Jack of Spades",
                  a_hand_string)
        assert_in("Added card 'S10'. String representation of hand should contain '10 of Spades'.",
                  "10 of Spades",
                  a_hand_string)
    except:
        fail_on_error("Runtime error when calling __str__ of PokerHand object.", sys.exc_info())
def test_create_community_cards():
    try:
        community = CommunityCardSet()
        for s, v in [('H', 2), ('H', 14), ('D', 11), ('S', 8), ('C', 8)]:
            community.add(Card(s, v))
        community_cards_string = str(community)
        for s, v in [('H', 2), ('H', 14), ('D', 11), ('S', 8), ('C', 8)]:
            msg = "The community set's string representation should contain the string " \
                  + "representation of the card " + str((s, v))
            assert_in(msg, str(Card(s, v)), community_cards_string)
    except:
        fail_on_error(
            "Trying to create a community card set and adding cards to it.",
            sys.exc_info())
def test_add_to_stud_poker_hand():
    try:
        community = CommunityCardSet()
        for s, v in [('H', 2), ('H', 14), ('D', 11), ('S', 8), ('C', 8)]:
            community.add(Card(s, v))
        a_hand = StudPokerHand(community)
        a_hand.add_card(Card('S', 11))
        a_hand.add_card(Card('S', 10))
        assert_equals(
            "Making sure that StudPokerHand object has add_card method.", True,
            type(a_hand) is StudPokerHand)
    except:
        fail_on_error(
            "Trying to create a StudPokerHand object and add cards to it.",
            sys.exc_info())
def test_compare_to_safe(msg, cards_a, cards_b, expected):
    try:
        hand_a = PokerHand()
        for s, v in cards_a:
            hand_a.add_card(Card(s, v))
        hand_b = PokerHand()
        for s, v in cards_b:
            hand_b.add_card(Card(s, v))
        msg += "\nA: {}\nB: {}".format(str(cards_a), str(cards_b))
        if expected > 0:
            assert_equals(msg, True, hand_a.compare_to(hand_b) > 0)
        elif expected < 0:
            assert_equals(msg, True, hand_a.compare_to(hand_b) < 0)
        else:
            assert_equals(msg, 0, hand_a.compare_to(hand_b))
    except:
        fail_on_error(msg, sys.exc_info())
def test_compare_to_safe(msg, community_cards, hole_cards_a, hole_cards_b,
                         expected):
    try:
        community = CommunityCardSet()
        for s, v in community_cards:
            community.add(Card(s, v))
        hand_a = StudPokerHand(community)
        for s, v in hole_cards_a:
            hand_a.add_card(Card(s, v))
        hand_b = StudPokerHand(community)
        for s, v in hole_cards_b:
            hand_b.add_card(Card(s, v))
        msg += "\nA: {}\nB: {}".format(str(hole_cards_a), str(hole_cards_b))
        if expected > 0:
            assert_equals(msg, True, hand_a.compare_to(hand_b) > 0)
        elif expected < 0:
            assert_equals(msg, True, hand_a.compare_to(hand_b) < 0)
        else:
            assert_equals(msg, 0, hand_a.compare_to(hand_b))
    except:
        fail_on_error(msg, sys.exc_info())
def test_create_poker_hand():
    try:
        a_hand = PokerHand()
        assert_equals("Created a new PokerHand object.", True, type(a_hand) is PokerHand)
    except:
        fail_on_error("Trying to create a PokerHand object.", sys.exc_info())