Example #1
0
def test_getValue():
	"""
	Ensure we're getting values the way we think we are
	"""
	
	# Create a hand
	h = Hand()
	
	# Add a card
	c1 = Card("A","Club")
	h.addCard(c1)
	
	# Check the hand values
	val = h.getValue()
	assert len(val) == 2
	assert val[0] == 1
	assert val[1] == 11
	
	# Add another card
	c2 = Card("Q","Club")
	h.addCard(c2)
	
	# Check hand value
	val = h.getValue()
	assert len(val) == 2
	assert val[0] == 11
	assert val[1] == 21
	
	# One more card
	c3 = Card("5","Spade")
	h.addCard(c3)
	
	# Check it
	val = h.getValue()
	assert len(val) == 1
	assert val[0] == 16
Example #2
0
def test_getValue():
    """
	Ensure we're getting values the way we think we are
	"""

    # Create a hand
    h = Hand()

    # Add a card
    c1 = Card("A", "Club")
    h.addCard(c1)

    # Check the hand values
    val = h.getValue()
    assert len(val) == 2
    assert val[0] == 1
    assert val[1] == 11

    # Add another card
    c2 = Card("Q", "Club")
    h.addCard(c2)

    # Check hand value
    val = h.getValue()
    assert len(val) == 2
    assert val[0] == 11
    assert val[1] == 21

    # One more card
    c3 = Card("5", "Spade")
    h.addCard(c3)

    # Check it
    val = h.getValue()
    assert len(val) == 1
    assert val[0] == 16
Example #3
0
def test_facilitatePlayerHand(monkeypatch):
    """
	Test facilitatePlayerHand method
	"""
    # Create the UI
    ui = UI()

    # Get our rule set
    houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN")

    # Set up the dealer
    dealer = Dealer(houseRules=houseRules, ui=ui)

    #############
    # Hit/Stand #
    #############

    player = Player(money=100, name="Tim")
    hand = Hand(Card("2", "Club"), Card("4", "Club"))
    player.addHand(hand)

    # A little complicated player interaction here..
    def playerAction(x, y):
        global count
        # Player will hit then stand
        if count == 0:
            count += 1
            return "hit"
        else:
            return "stand"

    global count
    count = 0
    monkeypatch.setattr(player, "selectHandAction", playerAction)
    # Screw the UI here..
    monkeypatch.setattr(dealer.ui, "drawTable", lambda: None)

    dealer.facilitatePlayerHand(player, hand)

    # We should have 3 cards at this time
    assert len(hand.getCards()) == 3

    ##########
    # Double #
    ##########

    player = Player(money=100, name="Tim")
    hand = Hand(Card("2", "Club"), Card("4", "Club"))
    player.addHand(hand)

    # Double will need a bet
    player.placeBet(20)

    monkeypatch.setattr(player, "selectHandAction", lambda x, y: "double")

    dealer.facilitatePlayerHand(player, hand)

    # We should have 3 cards at this time
    assert len(hand.getCards()) == 3

    ###########################
    # Double not enough money #
    ###########################

    player = Player(money=100, name="Tim")
    hand = Hand(Card("2", "Club"), Card("4", "Club"))
    player.addHand(hand)

    # Double will need a bet
    player.placeBet(60)

    monkeypatch.setattr(player, "selectHandAction", lambda x, y: "double")

    with pytest.raises(Exception):
        dealer.facilitatePlayerHand(player, hand)

    # We should have 2 cards at this time
    assert len(hand.getCards()) == 2

    #######################
    # Split Unimplemented #
    #######################

    player = Player(money=100, name="Tim")
    hand = Hand(Card("A", "Club"), Card("A", "Spade"))
    player.addHand(hand)

    # Double will need a bet
    player.placeBet(40)

    monkeypatch.setattr(player, "selectHandAction", lambda x, y: "split")

    with pytest.raises(Exception):
        dealer.facilitatePlayerHand(player, hand)

    # We should have 2 cards at this time
    assert len(hand.getCards()) == 2

    ###############
    # Busted Hand #
    ###############

    player = Player(money=100, name="Tim")
    hand = Hand(Card("A", "Club"), Card("K", "Spade"))
    hand.addCard(Card("Q", "Spade"))
    player.addHand(hand)

    # Double will need a bet
    player.placeBet(40)

    monkeypatch.setattr(player, "selectHandAction", lambda x, y: "hit")

    dealer.facilitatePlayerHand(player, hand)

    # We should be busted here
    assert len(hand.getValue()) == 0
Example #4
0
def test_facilitatePlayerHand(monkeypatch):
	"""
	Test facilitatePlayerHand method
	"""
	# Create the UI
	ui = UI()

	# Get our rule set
	houseRules = ui.selectHouseRules("Mystic Lake -- Shakopee, MN")

	# Set up the dealer
	dealer = Dealer(houseRules=houseRules,ui=ui)
	
	#############
	# Hit/Stand #
	#############
	
	player = Player(money=100,name="Tim")
	hand = Hand(Card("2","Club"),Card("4","Club"))
	player.addHand(hand)
	
	# A little complicated player interaction here..
	def playerAction(x,y):
		global count
		# Player will hit then stand
		if count == 0:
			count += 1
			return "hit"
		else:
			return "stand"
	global count
	count = 0
	monkeypatch.setattr(player,"selectHandAction",playerAction)
	# Screw the UI here..
	monkeypatch.setattr(dealer.ui,"drawTable",lambda : None )
	
	dealer.facilitatePlayerHand(player,hand)
	
	# We should have 3 cards at this time
	assert len(hand.getCards()) == 3
	
	##########
	# Double #
	##########
	
	player = Player(money=100,name="Tim")
	hand = Hand(Card("2","Club"),Card("4","Club"))
	player.addHand(hand)
	
	# Double will need a bet
	player.placeBet(20)
	
	monkeypatch.setattr(player,"selectHandAction",lambda x,y : "double")
	
	dealer.facilitatePlayerHand(player,hand)

	# We should have 3 cards at this time
	assert len(hand.getCards()) == 3
	
	###########################
	# Double not enough money #
	###########################

	player = Player(money=100,name="Tim")
	hand = Hand(Card("2","Club"),Card("4","Club"))
	player.addHand(hand)

	# Double will need a bet
	player.placeBet(60)

	monkeypatch.setattr(player,"selectHandAction",lambda x,y : "double")
	
	with pytest.raises(Exception):
		dealer.facilitatePlayerHand(player,hand)

	# We should have 2 cards at this time
	assert len(hand.getCards()) == 2

	
	#######################
	# Split Unimplemented #
	#######################

	player = Player(money=100,name="Tim")
	hand = Hand(Card("A","Club"),Card("A","Spade"))
	player.addHand(hand)

	# Double will need a bet
	player.placeBet(40)

	monkeypatch.setattr(player,"selectHandAction",lambda x,y : "split")

	with pytest.raises(Exception):
		dealer.facilitatePlayerHand(player,hand)

	# We should have 2 cards at this time
	assert len(hand.getCards()) == 2

	###############
	# Busted Hand #
	###############

	player = Player(money=100,name="Tim")
	hand = Hand(Card("A","Club"),Card("K","Spade"))
	hand.addCard(Card("Q","Spade"))
	player.addHand(hand)

	# Double will need a bet
	player.placeBet(40)

	monkeypatch.setattr(player,"selectHandAction",lambda x,y : "hit")

	dealer.facilitatePlayerHand(player,hand)

	# We should be busted here
	assert len(hand.getValue()) == 0