Beispiel #1
0
    def test_dealer_button(self):
        """
        Give dealer button to first player or next of previous gamer

        Dealer is always awarded to the first player if the table.dealer field
        is empty or to the next player inthe table.dealer field
        """

        # 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='start')
        player1.save()
        player2 = Player(name=us2, state='start')
        player2.save()
        player3 = Player(name=us3, state='start')
        player3.save()
        player4 = Player(name=us4, state='start')
        player4.save()
        table = Table(player1=player1,
                      player2=player2,
                      player3=player3,
                      player4=player4,
                      game_state='start')

        # Act & Assertion
        table.dealer_button()
        self.assertEqual(table.dealer, player1)

        table.game_state = 'start'
        table.dealer_button()
        self.assertEqual(table.dealer, player2)

        table.game_state = 'start'
        table.dealer_button()
        self.assertEqual(table.dealer, player3)

        table.game_state = 'start'
        table.dealer_button()
        self.assertEqual(table.dealer, player4)

        table.game_state = 'start'
        table.dealer_button()
        self.assertEqual(table.dealer, player1)
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')