Coverage for test\test_pot.py: 100%
40 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-18 00:10 +0000
1from decimal import Decimal
2from Hand import Pot
5"""
6Main functionalities:
7The Pot class represents a pot in a poker game. It keeps track of the players who are still in the pot, the amount of money each player has committed to the pot, the common money in the pot, the antes, the total amount of money in the pot, and the side pots. It also provides methods for adding and removing players, adding money to the pot, and calculating the total amount of money in the pot.
9"""
12class TestPot:
13 # Tests that calling end() updates the total, returned, and pots attributes with the correct values.
14 # def test_end(self):
15 # pot = Pot()
16 # pot.committed = {'player1': Decimal(10), 'player2': Decimal(20)}
17 # pot.common = {'player1': Decimal(5), 'player2': Decimal(0)}
18 # pot.stp = Decimal(0)
19 # pot.contenders = {'player1', 'player2'}
20 # pot.handid = 12345
22 # pot.end()
24 # assert pot.total == Decimal(25)
25 # assert pot.returned == {'player2': Decimal(10)}
26 # assert pot.pots == [(Decimal(20), {'player1', 'player2'})]
28 # Tests that adding money to the pot updates the committed dictionary and adds the player to the contenders set.
29 def test_addMoney(self):
30 pot = Pot()
31 pot.addPlayer("player1")
32 pot.addPlayer("player2")
34 pot.addMoney("player1", Decimal(10))
35 pot.addMoney("player2", Decimal(20))
37 assert pot.committed == {"player1": Decimal(10), "player2": Decimal(20)}
38 assert pot.contenders == {"player1", "player2"}
40 # Tests that removing a player from the pot deletes their entries from the committed, common, and antes dictionaries.
41 def test_removePlayer(self):
42 pot = Pot()
43 pot.addPlayer("player1")
44 pot.addPlayer("player2")
46 pot.removePlayer("player1")
48 assert "player1" not in pot.committed
49 assert "player1" not in pot.common
50 assert "player1" not in pot.antes
52 # Tests that marking the total at a street updates the streettotals dictionary with the correct value.
53 def test_markTotal(self):
54 pot = Pot()
55 pot.addPlayer("player1")
56 pot.addPlayer("player2")
57 pot.committed = {"player1": Decimal(10), "player2": Decimal(20)}
58 pot.common = {"player1": Decimal(5), "player2": Decimal(0)}
59 pot.stp = Decimal(0)
61 pot.markTotal("flop")
63 assert pot.streettotals == {"flop": Decimal(35)}
65 # Tests that getting the total at a street returns the correct value from the streettotals dictionary.
66 def test_getTotalAtStreet(self):
67 pot = Pot()
68 pot.streettotals = {"flop": Decimal(35), "turn": Decimal(50)}
70 assert pot.getTotalAtStreet("flop") == Decimal(35)
71 assert pot.getTotalAtStreet("turn") == Decimal(50)
72 assert pot.getTotalAtStreet("river") == 0
74 # Tests that adding a fold for a player removes them from the contenders set.
75 def test_addFold(self):
76 pot = Pot()
77 pot.contenders = {"player1", "player2", "player3"}
79 pot.addFold("player2")
81 assert pot.contenders == {"player1", "player3"}