Beispiel #1
0
    def test_start(self):
        """
        Set 'start' state for table and available players in table
        if number of players in this table is > 1
        and state of game is 'ready'
        """

        # Arrange
        us1 = User(username='******')
        us1.save()
        us2 = User(username='******')
        us2.save()
        us3 = User(username='******')
        us3.save()
        us4 = User(username='******')
        us4.save()
        player1 = Player(name=us1, state='check')
        player1.save()
        player2 = Player(name=us2, state='pass')
        player2.save()
        player3 = Player(name=us3, state='raise')
        player3.save()
        player4 = Player(name=us4, state='out')
        player4.save()
        table = Table(player1=player1)

        # Assertions & Acts

        # Only 1 player in table (table.start() should not working)
        self.assertEqual(table.game_state, 'ready')
        table.start()
        self.assertNotEqual(table.game_state, 'start')

        # 4 players in table (table.start() should works)
        table = Table(player1=player1,
                      player2=player2,
                      player3=player3,
                      player4=player4)
        self.assertEqual(table.game_state, 'ready')
        self.assertEqual(player1.state, 'check')
        self.assertEqual(player2.state, 'pass')
        self.assertEqual(player3.state, 'raise')
        self.assertEqual(player4.state, 'out')
        table.start()
        self.assertEqual(table.game_state, 'start')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')
Beispiel #2
0
    def test_make_turn(self):
        """That function is call in every game page overload"""

        # Arrange
        us1 = User(username='******')
        us1.save()
        us2 = User(username='******')
        us2.save()
        us3 = User(username='******')
        us3.save()
        us4 = User(username='******')
        us4.save()
        player1 = Player(name=us1, state='check', money=90)
        player1.save()
        player2 = Player(name=us2, state='check', money=90)
        player2.save()
        player3 = Player(name=us3, state='check', money=90)
        player3.save()
        player4 = Player(name=us4, state='check', money=90)
        player4.save()
        table = Table(player1=player1,
                      player2=player2,
                      player3=player3,
                      player4=player4,
                      game_state='ready')

        # Acts & Assertions
        table.start()
        table.dealer_button()
        self.assertEqual(table.game_state, 'dealer')

        table.take_small_blind()
        self.assertEqual(table.game_state, 'small_blind')

        table.take_big_blind()
        self.assertEqual(table.game_state, 'big_blind')

        # All players must give to the pool the same value
        table.give_to_pool(player1, 2)
        table.give_to_pool(player2, 1)
        table.give_to_pool(player4, 2)

        table.fill_deck_by_all_cards()

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'give_2')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'give_3')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.player1.state = 'pass'
        table.make_turn()
        self.assertEqual(table.game_state, 'give_1')
        self.assertEqual(player1.state, 'pass')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'give_1_again')
        self.assertEqual(player1.state, 'pass')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.player2.state = 'pass'
        table.make_turn()
        self.assertEqual(table.game_state, 'winner')
        self.assertEqual(player1.state, 'pass')
        self.assertEqual(player2.state, 'pass')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'ready')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'small_blind')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')

        table.set_all_in_game_players_state('check')
        table.make_turn()
        self.assertEqual(table.game_state, 'big_blind')
        self.assertEqual(player1.state, 'start')
        self.assertEqual(player2.state, 'start')
        self.assertEqual(player3.state, 'start')
        self.assertEqual(player4.state, 'start')