コード例 #1
0
def test_Deck_seed():
    # seeding deck gives same deck every time
    # (not sure if this works cross-platform)
    seeded_deck = blackjack_engine.Deck(seed=1)
    assert seeded_deck.cards[:10] == [
        'J', '10', 'Q', '10', '3', 'K', '7', 'Q', '10', '6'
    ]
    assert seeded_deck.cards[-10:] == [
        '3', '5', '3', '6', '8', '4', '5', '10', 'J', '9'
    ]
コード例 #2
0
def test_Game_full_loss_2():
    # player...
    # initial player hand [J 4], total: 14
    # initial dealer hand [A K], total: 21
    seeded_deck = blackjack_engine.Deck(seed=55832)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    print('initial player hand', game.player_hands[0])
    print('initial dealer hand', game.dealer_hand)
    assert game.is_finished == True
    # assert game.player_hands[0].cards == [] # behavior undefined ?
    assert game.dealer_hand.cards == ['A', 'K']
    assert game.result == -1
コード例 #3
0
def test_Game_full_push_1():
    # both dealt 20s, both stay, push
    # player_hands: [[J 10], total: 20]
    # dealer_hand: [Q 10], total: 20
    seeded_deck = blackjack_engine.Deck(seed=1)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    assert game.is_finished == False
    game.player_move('stay')
    assert game.is_finished == True
    assert game.player_hands[0].cards == ['J', '10']
    assert game.dealer_hand.cards == ['Q', '10']
    assert game.result == 0
コード例 #4
0
def test_Game_full_win_3():
    # player dealt blackjack, player wins
    # initial player hand [10 A], total: 21
    # initial dealer hand [J 6], total: 16
    seeded_deck = blackjack_engine.Deck(seed=63)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    print('initial player hand', game.player_hands[0])
    print('initial dealer hand', game.dealer_hand)
    assert game.is_finished == True
    print('final dealer hand: ', game.dealer_hand)
    assert game.player_hands[0].cards == ['10', 'A']
    # assert game.dealer_hand.cards == ['J', '6'] # behavior undefined?
    assert game.result == 2
コード例 #5
0
def test_Game_full_push_2():
    # player hits to 19, dealer stays, push
    # initial player hand: [3 4], total: 7
    # initial dealer hand: [10 9], total: 19
    seeded_deck = blackjack_engine.Deck(seed=2)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    game.player_move('hit')  # [[3 4 5], total: 12]
    game.player_move('hit')  # [[3 4 5 7], total: 19]
    assert game.is_finished == False
    game.player_move('stay')
    assert game.is_finished == True
    assert game.player_hands[0].cards == ['3', '4', '5', '7']
    assert game.dealer_hand.cards == ['10', '9']
    assert game.result == 0
コード例 #6
0
def test_Game_full_loss_1():
    # player hits to hard 19, dealer hits to 21, player loses
    # initial player hand: [A 3], total: 14
    # initial dealer hand: [4 7], total: 11
    seeded_deck = blackjack_engine.Deck(seed=3)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    game.player_move('hit')  # [[A 3 4], total: 18]
    game.player_move('hit')  # [[A 3 4 A], total: 19]
    game.player_move('hit')  # [[A 3 4 A K], total: 19]
    assert game.is_finished == False
    game.player_move('stay')
    assert game.is_finished == True
    assert game.player_hands[0].cards == ['A', '3', '4', 'A', 'K']
    assert game.dealer_hand.cards == ['4', '7', '10']
    assert game.result == -1
コード例 #7
0
def test_Game_full_win_1():
    # player hits on 16, wins with 21
    # initial player hand [Q 6], total: 16
    # initial dealer hand [10 K], total: 20
    seeded_deck = blackjack_engine.Deck(seed=5)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    print('initial player hand', game.player_hands[0])
    print('initial dealer hand', game.dealer_hand)
    assert game.is_finished == False
    game.player_move('hit')
    print('new player hand: ', game.player_hands)
    assert game.is_finished == True
    print('final dealer hand: ', game.dealer_hand)
    assert game.player_hands[0].cards == ['Q', '6', '5']
    assert game.dealer_hand.cards == ['10', 'K']
    assert game.result == 1
コード例 #8
0
def test_Deck_draw_card():
    my_deck = blackjack_engine.Deck()
    assert len(my_deck.cards) == 52
    card = my_deck.draw_card()
    assert card in [
        'A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'
    ]
    assert len(my_deck.cards) == 51  # 51 cards left after draw
    assert my_deck.cards.count(card) == 3  # only 3 of same card left in deck

    cards2 = my_deck.draw_card(3)
    assert len(cards2) == 3
    assert len(my_deck.cards) == 48  # cards left after second draw
    assert my_deck.cards.count(
        cards2[0]) < 4  # less than 4 of same card left in deck
    assert my_deck.cards.count(cards2[1]) < 4
    assert my_deck.cards.count(cards2[2]) < 4
コード例 #9
0
def test_Game_full_win_2():
    # player hits to hard 18, dealer hits to hard 17, player wins
    # initial player hand [Q 10], total: 20
    # initial dealer hand [A 9], total: 20
    seeded_deck = blackjack_engine.Deck(seed=7)
    game = blackjack_engine.BlackjackGame(deck=seeded_deck)
    print('initial player hand', game.player_hands[0])
    print('initial dealer hand', game.dealer_hand)
    assert game.is_finished == False
    game.player_move('hit')
    print('player hand 2: ', game.player_hands)
    game.player_move('hit')
    print('player hand 3: ', game.player_hands)
    game.player_move('stay')
    assert game.is_finished == True
    print('final dealer hand: ', game.dealer_hand)
    assert game.player_hands[0].cards == ['5', 'A', '2', 'Q']
    assert game.dealer_hand.cards == ['6', 'J', 'A']
    assert game.result == 1