def test_payout_bonus_scenario_any_natural(self): calculator = Lucky9PayoutCalculator() dealer_up_card = Lucky9Card('spade', 10) player_cards = [Lucky9Card('club', 3), Lucky9Card('diamond', 6)] winning = calculator.calculate_bonus_winning(dealer_up_card, player_cards) self.assertEqual(5, winning)
def test_payout_bonus_scenario_suited_2_3_4(self): calculator = Lucky9PayoutCalculator() dealer_up_card = Lucky9Card('spade', 3) player_cards = [Lucky9Card('spade', 2), Lucky9Card('spade', 4)] winning = calculator.calculate_bonus_winning(dealer_up_card, player_cards) self.assertEqual(100, winning)
def test_is_lucky9(self): card1 = Lucky9Card('spade', 1) card2 = Lucky9Card('spade', 7) card3 = Lucky9Card('spade', 1) cards_in_hand = [card1, card2, card3] self.assertTrue(Lucky9Game.is_lucky9(cards_in_hand))
def test_payout_bonus_lose(self): calculator = Lucky9PayoutCalculator() dealer_up_card = Lucky9Card('spade', 2) player_cards = [Lucky9Card('spade', 3), Lucky9Card('club', 7)] winning = calculator.calculate_bonus_winning(dealer_up_card, player_cards) self.assertEqual(0, winning)
def test_is_not_lucky9_10(self): card1 = Lucky9Card('spade', 3) card2 = Lucky9Card('spade', 7) card3 = Lucky9Card('spade', 10) cards_in_hand = [card1, card2, card3] self.assertFalse(Lucky9Game.is_lucky9(cards_in_hand))
def test_payout_bonus_scenario_suited_9(self): calculator = Lucky9PayoutCalculator() dealer_up_card = Lucky9Card('club', 1) player_cards = [Lucky9Card('club', 2), Lucky9Card('club', 6)] winning = calculator.calculate_bonus_winning(dealer_up_card, player_cards) self.assertEqual(30, winning)
def test_card_value(self): for suit in valid_suits: cardc1 = Lucky9Card(suit, 1) cardc2 = Lucky9Card(suit, 9) cardc3 = Lucky9Card(suit, 10) cardc4 = Lucky9Card(suit, 13) self.assertEqual(1, cardc1.card_value()) self.assertEqual(9, cardc2.card_value()) self.assertEqual(10, cardc3.card_value()) self.assertEqual(10, cardc4.card_value())
def test_payout_bet_dealer_not_enough_cards(self): calculator = Lucky9PayoutCalculator() dealer_cards = [Lucky9Card('spade', 2)] player_cards = [ Lucky9Card('spade', 1), Lucky9Card('spade', 3), Lucky9Card('spade', 4) ] self.assertRaises(ValueError, calculator.calculate_bet_winning, dealer_cards, player_cards)
def test_lucky9_dealer(self): dealer = Lucky9Dealer() dealer.add_card(Lucky9Card('spade', 1)) self.assertIsNotNone(dealer.down_card) dealer.add_card(Lucky9Card('spade', 2)) self.assertIsNotNone(dealer.up_card) dealer.add_card(Lucky9Card('spade', 4)) self.assertRaises(ValueError, dealer.add_card, Lucky9Card('spade', 3))
def test_payout_tie_scenario_win(self): calculator = Lucky9PayoutCalculator() dealer_cards = [ Lucky9Card('spade', 1), Lucky9Card('spade', 2), Lucky9Card('spade', 3) ] player_cards = [ Lucky9Card('club', 6), Lucky9Card('diamond', 6), Lucky9Card('spade', 4) ] winning = calculator.calculate_tie_winning(dealer_cards, player_cards) self.assertEqual(7, winning)
def test_payout_bet_dealer_more_than_player(self): calculator = Lucky9PayoutCalculator() dealer_cards = [ Lucky9Card('spade', 2), Lucky9Card('club', 3), Lucky9Card('spade', 4) ] player_cards = [ Lucky9Card('club', 1), Lucky9Card('diamond', 2), Lucky9Card('club', 3) ] winning = calculator.calculate_bet_winning(dealer_cards, player_cards) self.assertEqual(0, winning)
def test_payout_bet_dealer_total_9_player_lucky_9(self): calculator = Lucky9PayoutCalculator() dealer_cards = [ Lucky9Card('club', 10), Lucky9Card('diamond', 7), Lucky9Card('club', 2) ] player_cards = [ Lucky9Card('spade', 2), Lucky9Card('club', 3), Lucky9Card('spade', 4) ] winning = calculator.calculate_bet_winning(dealer_cards, player_cards) self.assertEqual(1.5, winning)
def test_payout_bet_player_wins_natural_9_dealer_not_9(self): calculator = Lucky9PayoutCalculator() dealer_cards = [ Lucky9Card('club', 1), Lucky9Card('diamond', 2), Lucky9Card('club', 3) ] player_cards = [ Lucky9Card('spade', 10), Lucky9Card('club', 3), Lucky9Card('spade', 5) ] winning = calculator.calculate_bet_winning(dealer_cards, player_cards) self.assertEqual(1.5, winning)
def test_is_tie_with_dealer(self): game = Lucky9Game(MockShuffle()) player_card1 = Lucky9Card('spade', 2) player_card2 = Lucky9Card('spade', 7) player_card3 = Lucky9Card('spade', 10) dealer_card1 = Lucky9Card('spade', 2) dealer_card2 = Lucky9Card('spade', 7) dealer_card3 = Lucky9Card('spade', 10) player_cards_in_hand = [player_card2, player_card1, player_card3] dealer_cards_in_hand = [dealer_card1, dealer_card3, dealer_card2] game.dealer.cards_in_hand = dealer_cards_in_hand self.assertTrue(game.is_tie_with_dealer(player_cards_in_hand))
def test_card_factory_lucky9(self): lucky9_card = CardFactory.factory('lucky9', 'spade', 1) expected = Lucky9Card('spade', 1) self.assertEqual(expected.suit, lucky9_card.suit) self.assertEqual(expected.value, lucky9_card.value)
def test_to_string(self): card = Lucky9Card('spade', 1) self.assertEqual("{ suit: spade, value: 1 }", str(card))
def test_pick_card_lower_boundary(self): dealer = Lucky9Dealer() dealer.up_card = Lucky9Card('spade', 4) self.assertTrue(dealer.handle_move())
def test_pick_card_upper_boundary(self): dealer = Lucky9Dealer() dealer.up_card = Lucky9Card('spade', 6) self.assertFalse(dealer.handle_move())
def test_payout_bonus_player_not_enough_cards(self): calculator = Lucky9PayoutCalculator() dealer_up_card = Lucky9Card('spade', 1) player_cards = [Lucky9Card('spade', 2)] self.assertRaises(ValueError, calculator.calculate_bonus_winning, dealer_up_card, player_cards)
def test_payout_bonus_dealer_no_cards(self): calculator = Lucky9PayoutCalculator() dealer_up_card = None player_cards = [Lucky9Card('spade', 3), Lucky9Card('spade', 3)] self.assertRaises(ValueError, calculator.calculate_bonus_winning, dealer_up_card, player_cards)