Example #1
0
def test_rank(faces, expected):
    hand_dict = {
        "royal straight flush": 23,
        "straight flush": 22,
        "back straight": 21,
        "four card": 20,
        "full house": 19,
        "flush": 18,
        "straight": 17,
        "three card": 16,
        "two pairs": 15,
        "one pair": 14,
        '2': 1,
        '3': 2,
        '4': 3,
        '5': 4,
        '6': 5,
        '7': 6,
        '8': 7,
        '9': 8,
        'T': 9,
        'J': 10,
        'Q': 11,
        'K': 12,
        'A': 13
    }
    random.shuffle(faces)
    hand = ([c for c in faces])
    a = Hands.rank((hand))
    assert a == hand_dict[Hands.tell_hand_ranking(hand)]
Example #2
0
def test_is_flush(faces, expected):
    hand_org = [PKCard(c) for c in faces]
    random.shuffle(faces)
    hand = Hands([PKCard(c) for c in faces])
    result = hand.is_flush()
    assert result == True
    assert hand.cards == hand_org
Example #3
0
def test_is_high_card(faces, expected):
    hand_org = [PKCard(c) for c in faces]
    random.shuffle(faces)
    hand = Hands([PKCard(c) for c in faces])
    result = hand.find_a_kind()
    assert result is None
    assert hand.cards == hand_org
Example #4
0
def test_who_wins():
    hand_cases = [(faces) for faces, ranking in cases()]
    for hand in hand_cases:
        Hands.rank(hand)
    sorted_cases = sorted(hand_cases, reverse=True)
    assert sorted(sorted_cases) == sorted(hand_cases)
    print('\nHigh to low order:')
    for i, hand in enumerate(hand_cases):
        print(i, hand)
Example #5
0
def test_Hands_tell_hand_ranking():
    #Test Straight Flush
    card = ['5C','6C', '7C', '8C', '9C']
    assert (Hands(card).tell_hand_ranking() == 'straight flush')
    #Test Straight
    card = ['5C', '6H', '7C', '8C', '9S']
    assert (Hands(card).tell_hand_ranking() == 'straight')
    #Test flush
    card = ['5C', 'AC', 'QC', 'AC', 'TC']
    assert (Hands(card).tell_hand_ranking() == 'flush')
    #Test Four card
    card = ['AC', 'AH', 'AS', 'AD', '9S']
    assert (Hands(card).tell_hand_ranking() == 'four of a kind')
    #Test Full House
    card = ['2C', '2H', '2S', 'KH', 'KS']
    assert (Hands(card).tell_hand_ranking() == 'full house')
    #Test Triple
    card = ['3C', '3H', '3D', 'QH', 'JD']
    assert (Hands(card).tell_hand_ranking() == 'triple')
    #Test Two Pair
    card = ['3C', '3H', 'QD', 'QH', 'JD']
    assert (Hands(card).tell_hand_ranking() == 'two pair')
    #Test One Pair
    card = ['AC', '7H', '3D', 'JH', 'JD']
    assert (Hands(card).tell_hand_ranking() == 'one pair')
    #Test One Pair
    card = ['8C', '9H', 'AD', 'TH', 'KD']
    assert (Hands(card).tell_hand_ranking() == 'high')
Example #6
0
def test_is_flush(all_faces):
    card = []
    for i in all_faces:
        card.append(i)
    random.shuffle(card)
    my_card = card[5:]
    assert Hands.is_flush(my_card) == False
Example #7
0
def test_is_straight(faces, expected):
    hand_org = [c for c in faces]
    random.shuffle(faces)
    hand = ([c for c in faces])
    result = Hands.is_straight(hand)
    assert result == True
    assert sorted(hand) == sorted(hand_org)
Example #8
0
def hand17():
    return Hands(['QH', 'QS', '6C', '6S', '9H'])
Example #9
0
def hand16():
    return Hands(['QH', '7S', '7C', '6S', 'QH'])
Example #10
0
def hand15():
    return Hands(['JH', '2S', '6C', 'JS', '2H'])
Example #11
0
def hand1():
    return Hands(['KD', 'QD', '7S', '4S', '3H'])
Example #12
0
def hand20():
    return Hands(['8D', 'QD', 'AS', '2S', '3H'])
Example #13
0
def test_is_find_a_kind(faces, expected):
    hand_org = [c for c in faces]
    random.shuffle(faces)
    hand = ([c for c in faces])
    result = Hands.find_a_kind(hand)
    assert result == 'one pair'
Example #14
0
def hand7():
    return Hands(['6S', '6H', '6D', 'KC', 'KH'])
Example #15
0
def hand8():
    return Hands(['5S', '5H', '5D', '5C', '2D'])
Example #16
0
def hand5():
    return Hands(['8H', '9S', 'TC', '6S', '7H'])
Example #17
0
def hand6():
    return Hands(['JD', '9D', '8D', '4D', '3D'])
Example #18
0
def hand4():
    return Hands(['QC', 'QS', 'QH', 'AH', 'JS'])
Example #19
0
def hand3():
    return Hands(['QH', 'QS', '6C', '6S', '2H'])
Example #20
0
def hand2():
    return Hands(['TS', 'TH', '8S', '7H', 'QC'])
Example #21
0
def hand21():
    return Hands(['8D', 'TD', 'JD', '4D', '2D'])
Example #22
0
def hand22():
    return Hands(['7S', '7H', '7D', 'AC', 'AH'])
Example #23
0
def test_Hands_tell_winner():
    #Test same rank but value is different in Straight flush
    my_hand = Hands(['5C','6C', '7C', '8C', '9C'])
    your_hand = Hands(['TH','6H', '7H', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank but value is different in flush
    my_hand = Hands(['5C','6C', '7C', '8C', 'TC'])
    your_hand = Hands(['TH','AH', '7H', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank but value is different in Straight
    my_hand = Hands(['5C','6H', '7C', '8C', '9C'])
    your_hand = Hands(['TH','6H', '7D', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank but value is different in Four card
    my_hand = Hands(['5C','5S', '5D', '5H', '9C'])
    your_hand = Hands(['2C','2S', '2D', '2H', '9H'])
    assert (my_hand.tell_winner(your_hand) == True)
    #Test same rank but value is different in Full House
    my_hand = Hands(['5C','6C', '7C', '8C', '9C'])
    your_hand = Hands(['TH','6H', '7H', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank but value is different in Triple
    my_hand = Hands(['5C','5H', '5D', '8C', '9C'])
    your_hand = Hands(['TH','TS', 'TD', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank first value but second value is different in Two Pair
    my_hand = Hands(['AC','AD', '7C', '7S', '9C'])
    your_hand = Hands(['AH','AS', '2H', '2D', '9H'])
    assert (my_hand.tell_winner(your_hand) == True)
    #Test same rank, first value and second value but last value is different in Two Pair
    my_hand = Hands(['AC','AD', '7C', '7S', '9C'])
    your_hand = Hands(['AH','AS', '7H', '7D', 'TH'])
    assert (my_hand.tell_winner(your_hand) == False)
    #Test same rank, all value in Two Pair
    my_hand = Hands(['AC','AD', '7C', '7S', '9C'])
    your_hand = Hands(['AH','AS', '7H', '7D', '9H'])
    assert (my_hand.tell_winner(your_hand) == None)
    #Test same rank, value is Difference in One Pair
    my_hand = Hands(['AC','AD', 'QC', '7S', '9C'])
    your_hand = Hands(['AH','AS', '7H', '6D', '9H'])
    assert (my_hand.tell_winner(your_hand) == True)
    #Test same rank, value is Difference in One Pair
    my_hand = Hands(['AC','AD', 'QC', '7S', '9C'])
    your_hand = Hands(['AH','AS', 'QH', '6D', '9H'])
    assert (my_hand.tell_winner(your_hand) == True)
    #Test same rank in One pair
    my_hand = Hands(['AC','AD', 'QC', '7S', '9C'])
    your_hand = Hands(['AH','AS', 'QH', '7D', '9H'])
    assert (my_hand.tell_winner(your_hand) == None)
    #Straight Flush vs High Card
    my_hand = Hands(['5C','6C', '7C', '8C', '9C'])
    your_hand = Hands(['8C', '9H', 'AD', 'TH', 'KD'])
    assert (my_hand.tell_winner(your_hand) == True)
    #if same rank and value, winner is None
    my_hand = Hands(['5C','6C', '7C', '8C', '9C'])
    your_hand = Hands(['5H','6H', '7H', '8H', '9H'])
    assert (my_hand.tell_winner(your_hand) == None)
Example #24
0
def hand12():
    return Hands(['AS', 'TH', '8S', 'AD', '4C'])
Example #25
0
def test_is_flush(faces, expected):
    hand_org = [c for c in faces]
    random.shuffle(faces)
    hand = ([c for c in faces])
    result = Hands.is_flush(hand)
    assert result == True
Example #26
0
def hand13():
    return Hands(['5S', 'TH', '8S', '5H', '4C'])
Example #27
0
def hand18():
    return Hands(['8H', '9S', 'TC', 'JS', '7H'])
Example #28
0
def hand14():
    return Hands(['5D', 'TH', '8S', 'AH', 'TC'])
Example #29
0
def hand9():
    return Hands(['7C', '8C', '9C', 'TC', 'JC'])
Example #30
0
def hand23():
    return Hands(['2C', '3C', '6C', '4C', '5C'])