Пример #1
0
def test_init(verbose):
    """Test initializer of blackjack objects.
    Extra info printed if `verbose` is True. """

    tester_name = inspect.stack()[0][3]
    print("Running " + tester_name + "()")

    # Small test
    c1 = c11.Card(0, 12)
    c2 = c11.Card(1, 10)
    c3 = c11.Card(2, 9)
    c4 = c11.Card(0, 1)
    start_deck = [c1, c2, c3, c4]
    if verbose:
        print("testing start deck of " + c11.cardlist_str(start_deck))

    game = blackjack.Blackjack(start_deck)
    ca.assert_equals(set([c1, c2]), set(game.playerHand))  # Sets ignore order
    ca.assert_equals([c3], game.dealerHand)
    ca.assert_equals([c4], start_deck)  # Check that cards were removed
    ca.assert_equals(start_deck, game.deck)

    # Bigger test.
    start_deck = c11.full_deck()
    if verbose:
        print("testing start deck of " + c11.cardlist_str(start_deck))
    game = blackjack.Blackjack(start_deck)
    ca.assert_true(
        set([c11.Card(0, 1), c11.Card(0, 2)]) == set(game.playerHand))
    ca.assert_equals([c11.Card(0, 3)], game.dealerHand)
    # Check card removal
    ca.assert_equals(c11.full_deck()[3:], start_deck)
    ca.assert_equals(start_deck, game.deck)

    print_done_message(verbose, tester_name)
Пример #2
0
def test_str(verbose):
    """Test __str__ function for Blackjack objects.
    Extra info printed if `verbose` is True."""

    tester_name = inspect.stack()[0][3]
    print("Running " + tester_name + "()")

    # Test cases:
    # Keys are tuples of the form (playerhand, dealerhand)
    # Values are the desired output of __str__
    test_cases = {
        ((c11.Card(alt='QH'), c11.Card(alt='TD')), (c11.Card(alt='9H'), )):
        'player: 20; dealer: 9',
        ((), (c11.Card(alt='9H'), )):
        'player: 0; dealer: 9',
        ((), (c11.Card(alt='9H'), c11.Card(alt="AH"))):
        'player: 0; dealer: 20',
        ((c11.Card(alt='9H'), c11.Card(alt="TH")), (c11.Card(alt='3S'),
                                                    c11.Card(alt='KH'),
                                                    c11.Card(alt='9C'))):
        'player: 19; dealer: 22'
    }

    game = make_dummy_game()
    for tc in test_cases:
        phand = list(tc[0])
        dhand = list(tc[1])
        if verbose:
            print('\tTesting ' + c11.cardlist_str(phand) + ' and ' +
                  c11.cardlist_str(dhand))
        answer = test_cases[tc]
        game.playerHand = phand
        game.dealerHand = dhand
        output = str(game)
        ca.assert_equals(answer, output)

    print_done_message(verbose, tester_name)
Пример #3
0
def make_dummy_game():
    """Returns a dummy blackjack game."""
    return blackjack.Blackjack(
        [c11.Card(alt='QC'),
         c11.Card(alt='TD'),
         c11.Card(alt='9H')])
Пример #4
0
# blackjack_checks.py
# L. Lee (LJL2), S. Marschner (SRM2), and W. White (WMW2)
# April 8, 2018
"""Some light checking for module blackjack"""

import cornellasserts as ca
import blackjack
import card_lab11 as c11  # Abbreviation
import sys
import inspect  # Used to get function names automatically:
# inspect.stack()[0] is the "highest" frame on the call stack

# Possible card lists and their scores.
test_cases_in_common = {
    (c11.Card(alt='AD'), ):
    11,  # A single ace
    (c11.Card(alt='2H'), c11.Card(alt='5S')):
    7,  # No face cards
    (c11.Card(alt='2C'), c11.Card(alt='AH')):
    13,  # Includes an ace
    (c11.Card(alt='KD'), c11.Card(alt='2D')):
    12,  # Includes a king
    (c11.Card(alt='QH'), c11.Card(alt='7D')):
    17,  # Includes a queen
    (c11.Card(alt='JS'), c11.Card(alt='8C')):
    18,  # Includes a jack
    (c11.Card(alt='TH'), c11.Card(alt='AC')):
    21,  # a ten and an ace
    (c11.Card(alt='AD'), c11.Card(alt='AH')):
    22,  # Two aces
    (c11.Card(alt='2C'), c11.Card(alt='3C'), c11.Card(alt='4S')):