Ejemplo n.º 1
0
 def setUp(self):
     self.table = Table(50,100,2,10,100,1000)
     self.player_0 = Player('ue', 1000, self.table)
     self.player_1 = Player('usman', 1000, self.table)
     self.player_2 = Player('ehtesham', 1000, self.table)
     self.player_3 = Player('gul', 1000, self.table)
     self.table.players = [self.player_0 ,self.player_1, self.player_2, self.player_3]
Ejemplo n.º 2
0
 def setUp(self):
     self.player = Player('usman', 1000, None)
     self.table = Table(50, 100, 2, 10, 100, 1000)
     self.table.add_player('bob', 1000)
     self.table.add_player('jane', 1000)
     self.table.add_player('dylan', 1000)
     self.table.add_player('john', 1000)
     self.table.start_game()
Ejemplo n.º 3
0
class PlayerTestCase(unittest.TestCase):
    ''' 
    Tests for the Player class
    '''
    def setUp(self):
        self.player = Player('usman', 1000, None)
        self.table = Table(50,100,2,10,100,1000)
        self.table.add_player('bob',1000)
        self.table.add_player('jane',1000)
        self.table.add_player('dylan',1000)
        self.table.add_player('john',1000)
        self.table.start_game()

    def test_player_initialization(self):
    	self.assertEqual([self.player.player_name, self.player.chips], ['usman', 1000])
    
    def test_player_check(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].check()
        self.assertEqual(self.table.players[1].chips, 900)


    def test_player_call(self):
        self.table.players[1].call()
        self.assertEqual(self.table.players[1].chips, 900)


    def test_player_fold(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].fold()
        self.assertTrue(self.table.players[1].folded)

    def test_player_bet(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        current_chips = self.table.players[1].chips
        self.table.players[1].bet(50)
        self.assertEqual(self.table.players[1].chips + 50, current_chips)

    def test_player_go_all_in(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].go_all_in()
        self.assertEqual(self.table.players[1].chips, 0)

    def tearDown(self):
        pass
Ejemplo n.º 4
0
class PlayerTestCase(unittest.TestCase):
    ''' 
    Tests for the Player class
    '''
    def setUp(self):
        self.player = Player('usman', 1000, None)
        self.table = Table(50, 100, 2, 10, 100, 1000)
        self.table.add_player('bob', 1000)
        self.table.add_player('jane', 1000)
        self.table.add_player('dylan', 1000)
        self.table.add_player('john', 1000)
        self.table.start_game()

    def test_player_initialization(self):
        self.assertEqual([self.player.player_name, self.player.chips],
                         ['usman', 1000])

    def test_player_check(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].check()
        self.assertEqual(self.table.players[1].chips, 900)

    def test_player_call(self):
        self.table.players[1].call()
        self.assertEqual(self.table.players[1].chips, 900)

    def test_player_fold(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].fold()
        self.assertTrue(self.table.players[1].folded)

    def test_player_bet(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        current_chips = self.table.players[1].chips
        self.table.players[1].bet(50)
        self.assertEqual(self.table.players[1].chips + 50, current_chips)

    def test_player_go_all_in(self):
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        self.table.players[1].go_all_in()
        self.assertEqual(self.table.players[1].chips, 0)

    def tearDown(self):
        pass
Ejemplo n.º 5
0
 def setUp(self):
     self.player = Player('usman', 1000, None)
     self.table = Table(50,100,2,10,100,1000)
     self.table.add_player('bob',1000)
     self.table.add_player('jane',1000)
     self.table.add_player('dylan',1000)
     self.table.add_player('john',1000)
     self.table.start_game()
Ejemplo n.º 6
0
 def setUp(self):
     self.table = Table(50, 100, 2, 10, 100, 1000)
Ejemplo n.º 7
0
class TableTestCase(unittest.TestCase):
    ''' 
    Tests for the Table class
    '''
    def setUp(self):
        self.table = Table(50, 100, 2, 10, 100, 1000)

    def test_table_initialization(self):
    	self.assertEqual([self.table.small_blind, self.table.big_blind, self.table.min_players,
    	self.table.max_players, self.table.min_buy_in, self.table.max_buy_in], [50, 100, 2, 10, 100, 1000])
    
    def test_table_add_player(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.assertEqual(self.table.players_to_add, [Player('usman', 1000, self.table), Player('ehtesham', 1000, self.table)])

    # def test_table_remove_player(self):
    #     self.table.add_player('usman', 1000)
    #     self.table.add_player('ehtesham', 1000)
    #     self.table.add_player('gul', 1000)
    #     self.table.start_game()
    #     self.table.remove_player('ehtesham')
        
    def test_table_start_game(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.start_game()
        self.assertEqual(self.table.current_player, 0)


    def test_table_new_round(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.game = Game(self.table.small_blind, self.table.big_blind)
        self.table.new_round()
        self.assertEqual(self.table.current_player, 0)

    def test_table_init_new_round(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.start_game()
        self.table.init_new_round()
        self.assertEqual(self.table.dealer, 1)


    def tearDown(self):
        pass
Ejemplo n.º 8
0
class UtilsTestCase(unittest.TestCase):
    ''' 
    Tests for the utils module
    '''
    def setUp(self):
        self.table = Table(50,100,2,10,100,1000)
        self.player_0 = Player('ue', 1000, self.table)
        self.player_1 = Player('usman', 1000, self.table)
        self.player_2 = Player('ehtesham', 1000, self.table)
        self.player_3 = Player('gul', 1000, self.table)
        self.table.players = [self.player_0 ,self.player_1, self.player_2, self.player_3]

    def test_get_max_bet(self):
    	self.assertEqual(utils.get_max_bet([100, 20,15,101, 30, 19]), 101)

    def test_rank_kickers(self):
    	self.assertEqual(utils.rank_kickers('AAAA', 4), 0.8192)

    def test_rank_comparator(self):
        self.assertEqual(utils.rank_comparator(10, 23), 13)

    def test_get_player_index(self):
    	index = utils.get_player_index(Player('ehtesham', 1000, self.table))
        self.assertEqual(index, 2)

    def test_check_for_winner(self):
        self.table.start_game()
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()

        rank_players = []
        for index, player in enumerate(self.table.players):
            cards = self.table.players[index].cards + self.table.game.board
            hand = Hand(cards)
            self.table.players[index].hand = utils.rank_hand(hand)
            rank_players.append((self.table.players[index].hand.rank, player.player_name))
        
        winner = max(rank_players)[1]
        utils.check_for_winner(self.table)

        self.assertEqual(self.table.game_winners[0]['player_name'], winner)
        
    def test_check_for_end_of_round(self):
        self.table.start_game()
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()

        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        
        self.table.players[1].call()
        self.table.players[2].call()
        self.table.players[3].call()
        self.table.players[0].call()
        
        self.assertTrue(utils.check_for_end_of_round(self.table))

    def test_check_for_all_in_players(self):
        self.table.start_game()
        self.table.players[1].go_all_in()
        self.table.players[2].go_all_in()
        winners = [0,2,1,3]
        self.assertEqual(utils.check_for_all_in_players(self.table, winners), [2,1])

    def test_check_for_bankrupt(self):
        self.table.start_game()
        players = set([player.player_name for player in self.table.players])
        self.table.players[1].go_all_in()
        self.table.players[2].go_all_in()
        utils.check_for_bankrupt(self.table)
        players_bankrupt =  players - set([player.player_name for player in self.table.players])
        self.assertEqual(players_bankrupt, set(['usman', 'ehtesham']) )

    def tearDown(self):
        pass
Ejemplo n.º 9
0
 def setUp(self):
     self.table = Table(50, 100, 2, 10, 100, 1000)
Ejemplo n.º 10
0
class TableTestCase(unittest.TestCase):
    ''' 
    Tests for the Table class
    '''
    def setUp(self):
        self.table = Table(50, 100, 2, 10, 100, 1000)

    def test_table_initialization(self):
        self.assertEqual([
            self.table.small_blind, self.table.big_blind,
            self.table.min_players, self.table.max_players,
            self.table.min_buy_in, self.table.max_buy_in
        ], [50, 100, 2, 10, 100, 1000])

    def test_table_add_player(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.assertEqual(self.table.players_to_add, [
            Player('usman', 1000, self.table),
            Player('ehtesham', 1000, self.table)
        ])

    # def test_table_remove_player(self):
    #     self.table.add_player('usman', 1000)
    #     self.table.add_player('ehtesham', 1000)
    #     self.table.add_player('gul', 1000)
    #     self.table.start_game()
    #     self.table.remove_player('ehtesham')

    def test_table_start_game(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.start_game()
        self.assertEqual(self.table.current_player, 0)

    def test_table_new_round(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.game = Game(self.table.small_blind, self.table.big_blind)
        self.table.new_round()
        self.assertEqual(self.table.current_player, 0)

    def test_table_init_new_round(self):
        self.table.add_player('usman', 1000)
        self.table.add_player('ehtesham', 1000)
        self.table.add_player('gul', 1000)
        self.table.start_game()
        self.table.init_new_round()
        self.assertEqual(self.table.dealer, 1)

    def tearDown(self):
        pass