Ejemplo n.º 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)]
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 8
0
def hand17():
    return Hands(['QH', 'QS', '6C', '6S', '9H'])
Ejemplo n.º 9
0
def hand16():
    return Hands(['QH', '7S', '7C', '6S', 'QH'])
Ejemplo n.º 10
0
def hand15():
    return Hands(['JH', '2S', '6C', 'JS', '2H'])
Ejemplo n.º 11
0
def hand1():
    return Hands(['KD', 'QD', '7S', '4S', '3H'])
Ejemplo n.º 12
0
def hand20():
    return Hands(['8D', 'QD', 'AS', '2S', '3H'])
Ejemplo n.º 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'
Ejemplo n.º 14
0
def hand7():
    return Hands(['6S', '6H', '6D', 'KC', 'KH'])
Ejemplo n.º 15
0
def hand8():
    return Hands(['5S', '5H', '5D', '5C', '2D'])
Ejemplo n.º 16
0
def hand5():
    return Hands(['8H', '9S', 'TC', '6S', '7H'])
Ejemplo n.º 17
0
def hand6():
    return Hands(['JD', '9D', '8D', '4D', '3D'])
Ejemplo n.º 18
0
def hand4():
    return Hands(['QC', 'QS', 'QH', 'AH', 'JS'])
Ejemplo n.º 19
0
def hand3():
    return Hands(['QH', 'QS', '6C', '6S', '2H'])
Ejemplo n.º 20
0
def hand2():
    return Hands(['TS', 'TH', '8S', '7H', 'QC'])
Ejemplo n.º 21
0
def hand21():
    return Hands(['8D', 'TD', 'JD', '4D', '2D'])
Ejemplo n.º 22
0
def hand22():
    return Hands(['7S', '7H', '7D', 'AC', 'AH'])
Ejemplo n.º 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)
Ejemplo n.º 24
0
def hand12():
    return Hands(['AS', 'TH', '8S', 'AD', '4C'])
Ejemplo n.º 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
Ejemplo n.º 26
0
def hand13():
    return Hands(['5S', 'TH', '8S', '5H', '4C'])
Ejemplo n.º 27
0
def hand18():
    return Hands(['8H', '9S', 'TC', 'JS', '7H'])
Ejemplo n.º 28
0
def hand14():
    return Hands(['5D', 'TH', '8S', 'AH', 'TC'])
Ejemplo n.º 29
0
def hand9():
    return Hands(['7C', '8C', '9C', 'TC', 'JC'])
Ejemplo n.º 30
0
def hand23():
    return Hands(['2C', '3C', '6C', '4C', '5C'])