def test_hand_win_ties(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 100) p1.hand_value = 12 p2.hand_value = 11 p3.hand_value = 12 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] p1.bid = 30 p2.bid = 70 p3.bid = 50 p4.bid = 70 p5.bid = 60 test_board = Board(players, 10) test_board.pot = sum([player.bid for player in players]) test_board.assign_hand_win(players) self.assertEqual(test_board.pot, 0) for player in players: self.assertEqual(player.bid, 0) self.assertEqual(p1.money, 100+60/3+30) self.assertEqual(p5.money, 100+60/3+40/2+20/1+60) self.assertEqual(p3.money, 100+60/3+40/2+50) self.assertEqual(p4.money, 100+10)
def test_hand_win_ties_uneven_split(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 100) p1.hand_value = 12 p2.hand_value = 11 p3.hand_value = 12 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] p1.bid = 31 p2.bid = 70 p3.bid = 50 p4.bid = 70 p5.bid = 60 test_board = Board(players, 10) test_board.pot = sum([player.bid for player in players]) test_board.assign_hand_win(players) self.assertEqual(test_board.pot, 0) for player in players: self.assertEqual(player.bid, 0) for player in players: print(player.money,player.name) self.assertEqual(p1.money, 100+21+31) self.assertEqual(p3.money, 100+21+19+50) self.assertEqual(p5.money, 100+20+19+20+60)
def test_distribute_hand_ties_two(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 100) p1.bid = 30 p2.bid = 60 p3.bid = 60 p4.bid = 60 p5.bid = 60 p1.hand_value = 12 p2.hand_value = 8.1 p3.hand_value = 8.2 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] test_board = Board(players,10) test_board.pot = sum([player.bid for player in players]) ranked_players = test_board.sort_player_rankings(players) test_board.distribute_tie_winnings(ranked_players[0]) self.assertEqual(p2.bid, 0) self.assertEqual(p3.bid, 0) self.assertEqual(p4.bid, 0) self.assertEqual(p1.bid, 0) self.assertEqual(p5.bid, 0) self.assertEqual(p1.money, 30+45+100) self.assertEqual(p5.money, 60+45+90+100) self.assertEqual(p2.money, 100) self.assertEqual(p3.money, 100) self.assertEqual(p4.money, 100) self.assertEqual(test_board.pot,0)
def test_partial_bids(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 120) p1.bid = 10 p2.bid = 20 p3.bid = 30 players = [p1,p2,p3,p4,p5] test_board = Board(players,10) test_board.pot = 60 test_board.return_partial_bid([p1,p2,p3]) self.assertEqual(p1.bid,0) self.assertEqual(p2.bid,10) self.assertEqual(p3.bid,20) self.assertEqual(test_board.pot,30) test_board.return_partial_bid([p1,p2,p3]) self.assertEqual(p1.bid,0) self.assertEqual(p2.bid,0) self.assertEqual(p3.bid,10) self.assertEqual(test_board.pot,10) test_board.return_partial_bid([p1,p2,p3]) self.assertEqual(p1.bid,0) self.assertEqual(p2.bid,0) self.assertEqual(p3.bid,0) self.assertEqual(test_board.pot,0)
def test_hand_win_multiple_winners(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 120) p1.hand_value = 10 p2.hand_value = 8.1 p3.hand_value = 8.2 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] p1.bid = 60 p2.bid = 20 p3.bid = 40 p4.bid = 35 p5.bid = 30 test_board = Board(players, 10) test_board.pot = sum([player.bid for player in players]) test_board.assign_hand_win(players) self.assertEqual(p5.money, 260) self.assertEqual(p4.money, 115) self.assertEqual(p1.money, 130) self.assertEqual(p3.money, 100) self.assertEqual(p2.money, 100) self.assertEqual(test_board.pot, 0) for player in players: self.assertEqual(player.bid, 0)
def test_hand_win(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 100) p1.hand_value = 10 p2.hand_value = 8.1 p3.hand_value = 8.2 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] for player in players: player.bid = 10 test_board = Board(players, 10) test_board.pot = 50 test_board.assign_hand_win(players) self.assertEqual(p5.money, 150) self.assertEqual(test_board.pot, 0) for player in test_board.players: self.assertEqual(player.bid, 0)
def test_hand_win_first_player_not_highest_bid(self): p1 = Player('p1',100) p2 = Player('p2', 100) p3 = Player('p3', 100) p4 = Player('p4', 100) p5 = Player('p5', 100) p1.hand_value = 10 p2.hand_value = 8.1 p3.hand_value = 8.2 p4.hand_value = 11 p5.hand_value = 12 players = [p1,p2,p3,p4,p5] for player in players[:4]: player.bid = 10 p5.bid = 5 for player in players: player_is_in_hand = True test_board = Board(players, 10) test_board.pot = 45 test_board.assign_hand_win(players) self.assertEqual(p5.money, 125) self.assertEqual(test_board.pot, 0) for player in test_board.players: self.assertEqual(player.bid, 0)