def test_fill_deck_by_all_cards(self): """Fill table deck by all cards""" # Arrange table = Table() # Assertions & Act self.assertEqual(table.deck, None) table.fill_deck_by_all_cards() self.assertNotEqual(table.deck, None) self.assertIsInstance(table.deck, str)
def test_give_2(self): """ Give 2 cards to each active player if: - game state = give 2 - each player have None cards """ # 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='out') player4.save() table = Table(player1=player1, player2=player2, player3=player3, player4=player4, game_state='give_2') table.fill_deck_by_all_cards() # Act table.give_2() # Assertion self.assertNotIn(player1.cards, table.deck) self.assertNotIn(player2.cards, table.deck) self.assertNotIn(player3.cards, table.deck) self.assertEqual(player4.cards, None) self.assertIsInstance(player1.cards, str) self.assertIsInstance(player2.cards, str) self.assertIsInstance(player3.cards, str) self.assertEqual(table.game_state, 'give_2')
def test_give_1_again(self): """ Give 1 card to the table if: - game state = give 1 again - on table is only 4 cards """ # 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) player1.save() player2 = Player(name=us2) player2.save() player3 = Player(name=us3) player3.save() player4 = Player(name=us4) player4.save() table = Table(player1=player1, player2=player2, player3=player3, player4=player4, game_state='give_3') table.fill_deck_by_all_cards() # Act table.give_3() table.next_game_state() table.give_1() table.next_game_state() table.give_1_again() # Assertion self.assertNotIn(table.cards_on_table, table.deck) self.assertIsInstance(table.cards_on_table, str) self.assertEqual(table.game_state, 'give_1_again')
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')