def test_game_init(): """ Tests the __init__ method for Blackjack objects """ c1 = card.Card(0, 12) c2 = card.Card(1, 10) c3 = card.Card(2, 9) c4 = card.Card(0, 1) # Initialize deck and start game. deck = [c1, c2, c3, c4] game = bjack.Blackjack(deck) introcs.assert_equals([c1, c2], game.playerHand) introcs.assert_equals([c3], game.dealerHand) introcs.assert_equals([c4], deck) # check that cards were removed deck = card.Card.deck() # non-shuffled deck game = bjack.Blackjack(deck) c1 = card.Card(0, 1) c2 = card.Card(0, 2) c3 = card.Card(0, 3) c4 = card.Card(0, 4) introcs.assert_equals([c1, c2], game.playerHand) introcs.assert_equals([c3], game.dealerHand) # check that right cards were removed introcs.assert_equals(card.Card.deck()[3:], deck) print('The blackjack __init__ tests passed')
def test_dealerBust(): """ Tests the dealerBust method for Blackjack objects """ # get dummy deck deck = [ card.Card(0, 12), card.Card(2, 9), card.Card(1, 10), ] game = bjack.Blackjack(deck) introcs.assert_true(not game.dealerBust()) game.dealerHand = [card.Card(0, 1), card.Card(1, 10)] introcs.assert_true(not game.dealerBust()) game.dealerHand = [card.Card(0, 1), card.Card(1, 10), card.Card(0, 2)] introcs.assert_true(game.dealerBust()) game.dealerHand = [card.Card(0, 10), card.Card(1, 10), card.Card(0, 1)] introcs.assert_true(game.dealerBust()) game.dealerHand = [card.Card(0, 11), card.Card(1, 10), card.Card(0, 1)] introcs.assert_true(game.dealerBust()) game.playerHand = [ card.Card(0, 11), card.Card(1, 10), card.Card(0, 1), card.Card(1, 1) ] introcs.assert_true(game.playerBust()) print('The dealerBust tests passed')
def test_playerScore(): """ Tests the playerScore method for Blackjack objects """ deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)] game = bjack.Blackjack(deck) introcs.assert_equals(20, game.playerScore()) game.playerHand = [card.Card(2, 2), card.Card(3, 1)] game.dealerHand = [card.Card(1, 13), card.Card(0, 3)] introcs.assert_equals(13, game.playerScore()) print('The playerScore tests passed')
def test_game_str(): """ Tests the __str__ function for Blackjack objects """ deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)] game = bjack.Blackjack(deck) introcs.assert_equals('player: 20; dealer: 9', str(game)) game.playerHand = [] introcs.assert_equals('player: 0; dealer: 9', str(game)) game.dealerHand.append(card.Card(2, 1)) introcs.assert_equals('player: 0; dealer: 20', str(game)) game.dealerHand.append(card.Card(2, 5)) introcs.assert_equals('player: 0; dealer: 25', str(game)) print('The blackjack __str__ tests passed')
def test_game_score(): """ Tests the _score method (which is hidden, but we access anyway) """ # need a dummy game object to call its _score function (and test it) deck = [card.Card(0, 12), card.Card(1, 10), card.Card(2, 9)] game = bjack.Blackjack(deck) introcs.assert_equals(13, game._score([card.Card(2, 2), card.Card(3, 1)])) introcs.assert_equals(13, game._score([card.Card(1, 13), card.Card(0, 3)])) introcs.assert_equals(22, game._score([card.Card(1, 1), card.Card(0, 1)])) introcs.assert_equals( 9, game._score([card.Card(1, 2), card.Card(0, 3), card.Card(3, 4)])) introcs.assert_equals(0, game._score([])) print('The blackjack _score tests passed')