class BlackjackIntegreationTests(unittest.TestCase):
    def setup(self):
        self.blackjack = Blackjack()
        self.blackjack.player = Hand()
        self.blackjack.dealer = Hand()

    def cleanup(self):
        self.blackjack = None

    # tests if bust logic works for player hand
    # if the player busts, then the game is over and the dealer wins
    # also tests if player has not busted
    def test_player_busted(self):
        self.setup()
        self.blackjack.player.add_to_hand(Card("Spades", "A"))
        self.blackjack.player.add_to_hand(Card("Hearts", "A"))
        self.assertFalse(self.blackjack.player_busted())
        self.blackjack.player.add_to_hand(Card("Hearts", "K"))
        self.blackjack.player.add_to_hand(Card("Hearts", "Q"))
        self.assertTrue(self.blackjack.player_busted())
        self.cleanup()

    # tests if bust logic works for dealer hand
    # if the dealer busts, then the game is over and the player wins
    # also tests if dealer as not busted
    def test_dealer_busted(self):
        self.setup()
        self.blackjack.dealer.add_to_hand(Card("Spades", "A"))
        self.blackjack.dealer.add_to_hand(Card("Hearts", "A"))
        self.assertFalse(self.blackjack.dealer_busted())
        self.blackjack.dealer.add_to_hand(Card("Hearts", "K"))
        self.blackjack.dealer.add_to_hand(Card("Hearts", "Q"))
        self.assertTrue(self.blackjack.dealer_busted())
        self.cleanup()

    # tests if check blackjack method properly functions
    # starts by having player test their hand, first when
    # it is not a blackjack and then when it is
    def test_check_blackjack_player(self):
        self.setup()
        self.blackjack.player.add_to_hand(Card("Spades", "A"))
        self.assertEqual((False, False), self.blackjack.check_blackjack())
        self.blackjack.player.add_to_hand(Card("Hearts", "Q"))
        self.assertEqual((True, False), self.blackjack.check_blackjack())
        self.cleanup()

    # same test except for the dealer rather than the player
    # also test if there is not a black jack
    def test_check_blackjack_dealer(self):
        self.setup()
        self.blackjack.dealer.add_to_hand(Card("Clubs", "A"))
        self.assertEqual((False, False), self.blackjack.check_blackjack())
        self.blackjack.dealer.add_to_hand(Card("Diamonds", "Q"))
        self.assertEqual((False, True), self.blackjack.check_blackjack())
        self.cleanup()