예제 #1
0
class BetTest(unittest.TestCase):
    """Test the implementation of the class Bet."""
    def setUp(self):
        self.black_bet = Bet(
            10, Outcome(Game.BLACK_BET_NAME, Game.EVEN_MONEY_BET_ODDS))
        self.straight_bet = Bet(
            5, Outcome(Game.STRAIGHT_BET_NAME + ' 35', Game.STRAIGHT_BET_ODDS))

    def test_can_create_bet(self):
        self.assertIsNotNone(self.black_bet)

    def test_win_amount_is_correct_for_black_bet(self):
        expected = 20  # 10 * 1 + 10
        self.assertEqual(expected, self.black_bet.win_amount())

    def test_win_amount_is_correct_for_straight_bet(self):
        expected = 180  # 5 * 35 + 5
        self.assertEqual(expected, self.straight_bet.win_amount())

    def test_lose_amount_is_correct(self):
        self.assertEqual(10, self.black_bet.lose_amount())
        self.assertEqual(5, self.straight_bet.lose_amount())

    def test_string_representation(self):
        self.assertEqual("10 on Black (1:1)", str(self.black_bet))
        self.assertEqual("5 on Number 35 (35:1)", str(self.straight_bet))

    def test_repr(self):
        self.assertEqual("Bet(10, Black (1:1))", repr(self.black_bet))
        self.assertEqual("Bet(5, Number 35 (35:1))", repr(self.straight_bet))
 def test_is_valid_with_bets_exceeding_limit(self):
     bet1 = Bet(291, Outcome("Red", 1))
     bet2 = Bet(10, Outcome("Red", 1))
     self.table.place_bet(bet1)
     self.assertTrue(self.table.is_valid())
     self.table.place_bet(bet2)
     self.assertRaises(InvalidBet, self.table.is_valid)
 def test_is_valid_with_bets_below_limit(self):
     bet1 = Bet(280, Outcome("Red", 1))
     bet2 = Bet(10, Outcome("Red", 1))
     bet3 = Bet(10, Outcome("Red", 1))
     self.table.place_bet(bet1)
     self.assertTrue(self.table.is_valid())
     self.table.place_bet(bet2)
     self.assertTrue(self.table.is_valid())
     self.table.place_bet(bet3)
     self.assertTrue(self.table.is_valid())
 def test_player_stake_does_not_change_with_a_loss(self):
     # amount has already been deducted when placing the bet
     bet_amount = 100
     the_bet = Bet(bet_amount, self.wheel.get_outcome(Game.ODD_BET_NAME))
     self.assertEqual(self.player.stake, 0)
     self.player.lose(the_bet)
     self.assertEqual(self.player.stake, 0)
예제 #5
0
 def test_sevenreds_player_bet_multiplier_correctly_updates(self):
     amount = 1
     the_bet = Bet(amount, self.wheel.get_outcome(Game.BLACK_BET_NAME))
     self.the_player.lose(the_bet)
     self.assertEqual(self.the_player.bet_multiplier, 2)
     self.the_player.lose(the_bet)
     self.assertEqual(self.the_player.bet_multiplier, 4)
     self.the_player.win(the_bet)
     self.assertEqual(self.the_player.bet_multiplier, 1)
예제 #6
0
 def test_sevenreds_player_stake_is_correct_after_a_loss(self):
     for _ in range(7):
         self.the_player.winners(
             {self.wheel.get_outcome(Game.RED_BET_NAME)})
     the_bet = Bet(1, self.wheel.get_outcome(Game.BLACK_BET_NAME))
     self.assertEqual(self.the_player.stake, 0)
     self.the_player.place_bets()
     self.the_player.lose(the_bet)
     self.assertEqual(self.the_player.stake, -1)
예제 #7
0
 def setUp(self):
     self.black_bet = Bet(
         10, Outcome(Game.BLACK_BET_NAME, Game.EVEN_MONEY_BET_ODDS))
     self.straight_bet = Bet(
         5, Outcome(Game.STRAIGHT_BET_NAME + ' 35', Game.STRAIGHT_BET_ODDS))
 def place_bets(self):
     """Place bet on the table."""
     super().place_bets()
     self.stake -= self.bet_multiplier
     self.table.place_bet(Bet(self.bet_multiplier, self.black_outcome))
 def test_player_updates_stake_with_a_win(self):
     bet_amount = 100
     the_bet = Bet(bet_amount, self.wheel.get_outcome(Game.ODD_BET_NAME))
     self.assertEqual(self.player.stake, 0)
     self.player.win(the_bet)
     self.assertEqual(self.player.stake, 200)
 def place_bets(self):
     """Place a bet on Black outcome."""
     super().place_bets()
     amount = 50
     self.stake -= amount
     self.table.place_bet(Bet(amount, self.black))
 def test_martingale_player_stake_is_correct_after_a_loss(self):
     the_bet = Bet(1, self.wheel.get_outcome(Game.BLACK_BET_NAME))
     self.assertEqual(self.the_player.stake, 0)
     self.the_player.place_bets()
     self.the_player.lose(the_bet)
     self.assertEqual(self.the_player.stake, -1)
 def test_is_valid_returns_true_for_minimum_bet(self):
     at_min_bet = Bet(10, Outcome("Red", 1))
     self.table.place_bet(at_min_bet)
     self.assertTrue(self.table.is_valid())
 def test_is_valid_raises_exception_for_bet_over_max(self):
     one_bet_over_max = Bet(301, Outcome("Red", 1))
     self.table.place_bet(one_bet_over_max)
     self.assertRaises(InvalidBet, self.table.is_valid)
 def test_is_valid_raises_exception_for_bet_under_min(self):
     under_min_bet = Bet(9, Outcome("Red", 1))
     self.table.place_bet(under_min_bet)
     self.assertRaises(InvalidBet, self.table.is_valid)
 def setUp(self):
     self.table = Table()
     self.bet_split = Bet(10, Outcome("Split 1-2", 17))
     self.bet_straight = Bet(5, Outcome("Number 17", 35))
     self.bet_red = Bet(25, Outcome("Red", 1))