Exemplo n.º 1
0
class EndPhaseEngineTests(unittest.TestCase):
    def setUp(self):
        self.humanPlayer = HumanPlayer().randomName()
        self.botPlayer = Bot()
        self.engine = TestGoFishEngine(True)

    # Insert Tests Here
    def testEndPhaseCorrect(self):
        # Set a player up with a correct guess, then test and see if that guess got reset.
        # 	This needs to happen before a player takes a turn
        self.humanPlayer.setGuess(True)

        self.engine.endPhase(self.humanPlayer)

        self.assertTrue(self.humanPlayer.gotGuess() == False)

    def testEndPhaseCorrectOneTrick(self):
        # Set a player up with a correct guess and a hand that contains one trick.
        hand = [
            Card("A", "Spades"),
            Card("A", "Hearts"),
            Card("A", "Diamonds"),
            Card("A", "Clubs")
        ]

        self.humanPlayer.takeRelevantCards(hand)
        self.assertTrue(self.humanPlayer.countHand() == 4)
        self.humanPlayer.setGuess(True)
        self.assertTrue(self.humanPlayer.gotGuess() == True)

        self.engine.endPhase(self.humanPlayer)

        self.assertTrue(self.humanPlayer.gotGuess() == False)
        self.assertTrue(self.humanPlayer.countHand() == 0)
        self.assertTrue(self.humanPlayer.getTricks() == 1)
        print self.engine.getMasterTrickCount()
        self.assertTrue(self.engine.getMasterTrickCount() == 1)

    def testEndPhaseCorrectMultipleTricks(self):
        hand = spawnDupCards(["A", "J", "K", "Q"],
                             ["Diamonds", "Spades", "Hearts", "Clubs"])
        self.humanPlayer.takeRelevantCards(hand)
        self.assertTrue(self.humanPlayer.countHand() == 16)
        self.humanPlayer.setGuess(True)

        self.assertTrue(self.humanPlayer.gotGuess() == True)

        self.engine.endPhase(self.humanPlayer)

        self.assertTrue(self.humanPlayer.gotGuess() == False)
        self.assertTrue(self.humanPlayer.countHand() == 0)
        self.assertTrue(self.humanPlayer.getTricks() == 4)
        print self.engine.getMasterTrickCount()
        self.assertTrue(self.engine.getMasterTrickCount() == 4)

    def testEndPhaseCorrectEndGame(self):
        hand = spawnDupCards(["3"], ["Diamonds", "Spades", "Hearts", "Clubs"])
        self.humanPlayer.takeRelevantCards(hand)
        self.assertTrue(self.humanPlayer.countHand() == 4)
        self.humanPlayer.setGuess(True)

        self.assertTrue(self.humanPlayer.gotGuess() == True)

        self.engine.trickCount = 12
        self.assertTrue(self.engine.getMasterTrickCount() == 12)
        self.engine.setPlayers([self.humanPlayer])

        self.engine.endGameLoop(self.humanPlayer)
        self.assertTrue(self.engine.getMasterTrickCount() == 13)
        self.assertTrue(self.engine.endGame == True)

        output = sys.stdout.getvalue().strip()

        winningPhrase = """Congratulations %s, you have won the epic game of Go Fish with a trick count of %s. Make sure to tell all of your other friends (if you have any) that you won one of the most childish games in all the land!""" % (
            self.humanPlayer, 1)
        self.assertEquals(output, winningPhrase)

    def testEndPhaseIncorrectNoTricks(self):
        self.humanPlayer.takeRelevantCards([Card("A", "Spades")])
        self.engine.setPlayers([self.humanPlayer, self.botPlayer])
        self.assertTrue(self.engine.getPlayerAmount() == 2)
        self.assertTrue(self.engine._getPlayerIndex() == 0)
        self.engine.endPhase(self.humanPlayer)
        self.assertTrue(self.engine._getPlayerIndex() == 1)

    def testEndPhaseIncorrectOneTrick(self):
        hand = [
            Card("A", "Spades"),
            Card("A", "Hearts"),
            Card("A", "Diamonds"),
            Card("A", "Clubs")
        ]

        self.humanPlayer.takeRelevantCards(hand)
        self.engine.setPlayers([self.humanPlayer, self.botPlayer])
        self.assertTrue(self.humanPlayer.countHand() == 4)
        self.assertTrue(not self.humanPlayer.gotGuess())

        self.engine.endPhase(self.humanPlayer)

        self.assertTrue(not self.humanPlayer.gotGuess())
        self.assertTrue(self.humanPlayer.countHand() == 0)
        self.assertTrue(self.humanPlayer.getTricks() == 1)
        print self.engine.getMasterTrickCount()
        self.assertTrue(self.engine.getMasterTrickCount() == 1)

    def testEndPhaseIncorrectMultipleTricks(self):
        hand = spawnDupCards(["A", "J", "K", "Q"],
                             ["Diamonds", "Spades", "Hearts", "Clubs"])
        self.humanPlayer.takeRelevantCards(hand)
        self.engine.setPlayers([self.humanPlayer, self.botPlayer])
        self.assertTrue(self.humanPlayer.countHand() == 16)
        self.assertTrue(not self.humanPlayer.gotGuess())

        self.engine.endPhase(self.humanPlayer)

        self.assertTrue(not self.humanPlayer.gotGuess())
        self.assertTrue(self.humanPlayer.countHand() == 0)
        self.assertTrue(self.humanPlayer.getTricks() == 4)
        print self.engine.getMasterTrickCount()
        self.assertTrue(self.engine.getMasterTrickCount() == 4)

    def testEndPhaseIncorrectEndGame(self):
        hand = spawnDupCards(["3"], ["Diamonds", "Spades", "Hearts", "Clubs"])
        self.humanPlayer.takeRelevantCards(hand)
        self.assertTrue(self.humanPlayer.countHand() == 4)

        self.assertTrue(not self.humanPlayer.gotGuess())

        self.engine.trickCount = 12
        self.assertTrue(self.engine.getMasterTrickCount() == 12)
        self.engine.setPlayers([self.humanPlayer])

        self.engine.endGameLoop(self.humanPlayer)
        self.assertTrue(self.engine.getMasterTrickCount() == 13)
        self.assertTrue(self.engine.endGame == True)

        output = sys.stdout.getvalue().strip()

        winningPhrase = """Congratulations %s, you have won the epic game of Go Fish with a trick count of %s. Make sure to tell all of your other friends (if you have any) that you won one of the most childish games in all the land!""" % (
            self.humanPlayer, 1)
        self.assertEquals(output, winningPhrase)

    def tearDown(self):
        self.humanPlayer = None
        self.botPlayer = None
        self.engine = None