def test_table_is_valid(): wh = Wheel() with pytest.raises(InvalidBetException) as e_info: tt = Table(100, 5) # should violate the min bet amount and throw exception bt = Bet(1, wh.get_outcome('Even')) tt.place_bet(bt) with pytest.raises(InvalidBetException) as e_info: tt = Table(10, 5) bt = Bet(5, wh.get_outcome('Even')) tt.place_bet(bt) bt = Bet(5, wh.get_outcome('Even')) tt.place_bet(bt) # should exceed table limit and throw exception bt = Bet(5, wh.get_outcome('Even')) tt.place_bet(bt) # def test_table_iter(): # tt = Table(100, 5) # print(tt.__iter__().isinstance(Iterator))
class TestWheel: def setup_method(self): self.wheel = Wheel(1) def test_initialize(self): assert len(self.wheel.bins) == 38 for b in self.wheel.bins: assert len(b) > 0 assert len(b) < 20 def test_add_bin(self): b1 = Bin([Outcome("0", 35)]) self.wheel.add_bin(10, b1) assert self.wheel.get(10) == b1 def test_next(self): r = random.Random() r.setstate(self.wheel.rng.getstate()) b1 = Bin([Outcome("Red", 5)]) b2 = Bin([Outcome("0", 35), Outcome("Black", 5)]) self.wheel.add_bin(r.randint(0, 38), b1) self.wheel.add_bin(r.randint(0, 38), b2) assert self.wheel.next() == b1 assert self.wheel.next() == b2 assert self.wheel.next() != b2 def test_add_outcome(self): o1 = Outcome("test", 35) self.wheel.add_outcome(4, o1) assert o1 in self.wheel.get(4) def test_get_bin(self): b1 = Bin([Outcome("Red", 5)]) self.wheel.add_bin(3, b1) assert self.wheel.get(3) == b1 def test_get_outcome(self): o1 = Outcome("0", 35) self.wheel.add_outcome(4, o1) assert self.wheel.get_outcome("0") == o1 assert self.wheel.get_outcome("gibberish") == None def test_get_bin_iterator(self): iterator = self.wheel.get_all_bins() for i in range(37): bin_iter = next(iterator) assert isinstance(bin_iter, Bin) == True assert self.wheel.get_outcome( "{}".format(i)) in bin_iter.get_outcome_iterator() assert self.wheel.get_outcome("00") in next(iterator)
def test_table_iter_bets(): tt = Table(100, 5) test_bets = [] wh = Wheel() bt = Bet(10, wh.get_outcome('Even')) test_bets.append(bt) bt = Bet(5, wh.get_outcome('Even')) test_bets.append(bt) for test_bt, bt in zip(test_bets, tt): assert test_bt == bt
class TestEuroBinBuilder(unittest.TestCase): def setUp(self): self.wheel = Wheel(rules="european") def test_straight_bets(self): self.assertIsInstance(self.wheel.get_outcome("0"), PrisonOutcome) def test_five_bets(self): self.assertIsNone(self.wheel.get_outcome("00-0-1-2-3")) def test_four_bets(self): self.assertIsNotNone(self.wheel.get_outcome("0-1-2-3"))
def test_get_outcome(): wheel = Wheel() bb = BinBuilder() bb.generate_even_money_bets(wheel) bb.generate_column_bets(wheel) assert Outcome('High', 1) == wheel.get_outcome('High') assert Outcome('Low', 1) == wheel.get_outcome('Low') assert Outcome('Red', 1) == wheel.get_outcome('Red') assert Outcome('Black', 1) == wheel.get_outcome('Black') assert Outcome('Column 1', 1) == wheel.get_outcome('Column 1') assert Outcome('Column 2', 1) == wheel.get_outcome('Column 2') assert Outcome('Column 3', 1) == wheel.get_outcome('Column 3')
def test_sevenreds_counter(self): '''Checks that SevenReds red counter increments correctly.''' simulation = Wheel(1) simulator = self.sb.get_simulator("sevenreds") game = simulator.game red_streak = 0 red = simulation.get_outcome("red") for _ in range(10): winners = simulation.next() if red in winners: red_streak += 1 else: red_streak = 0 game.cycle(simulator.player) assert simulator.player.red_count == red_streak
def test_sevenreds_bet(self): '''Check that SevenReds bets after there are 7 consecutive reds.''' simulation = Wheel(1) simulator = self.sb.get_simulator("sevenreds") game = simulator.game simulator.player.set_rounds(simulator.init_duration) simulator.player.set_stake(simulator.init_stake) red_streak = 0 red = simulation.get_outcome("red") for _ in range(simulator.player.rounds): _, num_bets = game.cycle(simulator.player) assert (red_streak >= 7) == bool(num_bets) winners = simulation.next() if red in winners: red_streak += 1 else: red_streak = 0
def test_martingale_bet(self): '''Test Martingale's bets update correctly.''' simulator = self.sb.get_simulator("martingale") m = simulator.player lose_streak = 0 simulation = Wheel(1) m.set_stake(100) m.set_rounds(5) for _ in range(5): m.place_bets() assert m.table.bets[0].amount == 2**lose_streak won = simulation.get_outcome("black") in simulation.next() if won: lose_streak = 0 m.win(m.table.bets[0]) else: lose_streak += 1 m.lose(m.table.bets[0]) m.table.clear_bets()
def test_bet(): wheel = Wheel() bin_builder = BinBuilder() bin_builder.build_even_money_bets(wheel, Outcome) b = Bet(588, wheel.get_outcome('Red')) assert 588 == b.win_amount()
def test_table_place_bet(): tt = Table(100, 5) wh = Wheel() bt = Bet(10, wh.get_outcome('Even')) assert True == tt.place_bet(bt)