Ejemplo n.º 1
0
 def setUp(self):
   self.bet = Bet(1, EvenMoney("Black"))
   self.mock_player = Mock()
   self.table = Table(0, 1)
   self.mock_wheel = Mock()
   self.mock_wheel.next.return_value = set()
   self.game = Game(self.table, self.mock_wheel)
Ejemplo n.º 2
0
 def setUp(self):
   """Setup a basic Simulator with the Martingale Player."""
   self.table = Table(0, 100)
   self.wheel = Wheel()
   self.game = Game(self.table, self.wheel)
   self.player = Martingale(self.table, self.wheel)
   self.simulator = Simulator(self.game, self.player)
Ejemplo n.º 3
0
def main(argv=None):
  """Application main function: setup a simulation, print results."""
  table = Table(1, 100)
  wheel = Wheel()
  game = Game(table, wheel)
  player = Martingale(table, wheel)
  sim = Simulator(game, player)
  sim.gather()
  print("durations", sim.durations, "\n", "maxima", sim.maxima)
Ejemplo n.º 4
0
 def test_table_isValid_total_table_limit(self):
   """Sum of all Bets should be less or equal to the Table limit."""
   table = Table(0, 10)
   # invalid Bet (total table bets more than limit)
   table.placeBet(Bet(11, EvenMoney("High")))
   self.assertRaises(InvalidBet, table.isValid)
Ejemplo n.º 5
0
class TableTest(unittest.TestCase):
  """Unit test for the Table class."""

  def setUp(self):
    self.outcome = EvenMoney("Red")
    self.table = Table(0, 10)

  def test_initialization(self):
    """The constructor should save all parameters correctly."""
    self.assertEqual(len(self.table.bets), 0)
    self.assertEqual(self.table.minimum, 0)
    self.assertEqual(self.table.limit, 10)

  def test_placeBet(self):
    """It should be possible to place a Bet on a Table."""
    bet = Bet(12, self.outcome)
    self.table.placeBet(bet)
    self.assertEqual(self.table.__iter__().__next__(), bet)

  def test_iter(self):
    """The __iter__ method should return an iterable of the Bets."""
    bets = [Bet(i+1, self.outcome) for i in range(3)]
    for bet in bets:
      self.table.placeBet(bet)
    iter_bets = self.table.__iter__()
    for bet in bets:
      self.assertEqual(iter_bets.__next__(), bet)

  #################### Table to string ###############################

  def table_with_bets(self):
    """Prepare a Table a with some Bets on it."""
    self.table.placeBet(Bet(4, Split(1, 4)))
    self.table.placeBet(Bet(6, EvenMoney("High")))
    return self.table

  def test_str(self):
    """Test the __str__ method."""
    self.assertEqual(
      self.table_with_bets().__str__(), "4 on Split 1-4 (17:1), 6 on High (1:1)")

  def test_repr(self):
    """Test the __repr__ method."""
    self.assertEqual(
      self.table_with_bets().__repr__(),
      "Table(Bet(4, Outcome('Split 1-4', 17)), Bet(6, Outcome('High', 1)))")

  ##################### Table isValid()? ##############################

  def test_table_isValid_empty_table(self):
    """An empty Table should be valid."""
    table = Table(0, 1)
    self.assertTrue(table.isValid())

  def test_table_isValid_valid_table(self):
    """A valid Table should be a valid."""
    table = Table(1, 10)
    table.placeBet(Bet(1, EvenMoney("Red")))
    table.placeBet(Bet(2, EvenMoney("Black")))
    self.assertTrue(table.isValid())

  def test_table_isValid_minimum_bet_amount(self):
    """Each Bet should be greater or equal to the Table minimum."""
    table = Table(10, 1000)
    # invalid Bet (amountBet less than Table minimum)
    table.placeBet(Bet(1, EvenMoney("Black")))
    self.assertRaises(InvalidBet, table.isValid)

  def test_table_isValid_total_table_limit(self):
    """Sum of all Bets should be less or equal to the Table limit."""
    table = Table(0, 10)
    # invalid Bet (total table bets more than limit)
    table.placeBet(Bet(11, EvenMoney("High")))
    self.assertRaises(InvalidBet, table.isValid)
Ejemplo n.º 6
0
 def test_table_isValid_minimum_bet_amount(self):
   """Each Bet should be greater or equal to the Table minimum."""
   table = Table(10, 1000)
   # invalid Bet (amountBet less than Table minimum)
   table.placeBet(Bet(1, EvenMoney("Black")))
   self.assertRaises(InvalidBet, table.isValid)
Ejemplo n.º 7
0
 def test_table_isValid_valid_table(self):
   """A valid Table should be a valid."""
   table = Table(1, 10)
   table.placeBet(Bet(1, EvenMoney("Red")))
   table.placeBet(Bet(2, EvenMoney("Black")))
   self.assertTrue(table.isValid())
Ejemplo n.º 8
0
 def test_table_isValid_empty_table(self):
   """An empty Table should be valid."""
   table = Table(0, 1)
   self.assertTrue(table.isValid())
Ejemplo n.º 9
0
 def setUp(self):
   self.outcome = EvenMoney("Red")
   self.table = Table(0, 10)
Ejemplo n.º 10
0
 def setUp(self):
     self.table = Table(0, 1)
     self.player = Player(self.table)
Ejemplo n.º 11
0
def test_not_playing_if_no_rounds_left(self, player):
    """A Player should not be playing if there are no roundsToGo left."""
    player.table = Table(0, 1)
    player.roundsToGo = 0
    self.assertFalse(player.playing())
Ejemplo n.º 12
0
def test_stake_required_to_play(self, player):
    """A Player with stake below Table minimum should not be playing."""
    player.table = Table(10, 100)
    player.stake = 9
    self.assertFalse(player.playing())