def test_Wheel(self): """ http://www.itmaybeahack.com/book/oodesign-python-2.1/html/roulette/wheel.html#the-random-bin-selection-responsibility Wheel Deliverables A class which performs a unit test of building the Wheel class. The unit test should create several instances of Outcome, two instances of Bin, and an instance of Wheel. The unit test should establish that Bins can be added to the Wheel. A Non-Random Random Number Generator class, to be used for testing. A class which tests the Wheel and NonRandom class by selecting values from a Wheel object. """ outcome_one = Outcome("Red", 1) outcome_two = Outcome("Corner", 2) outcome_three = Outcome("Black", 3) outcome_four = Outcome("Street", 4) nonrandom = NonRandom() nonrandom.set_seed(1) wheel_one = Wheel(nonrandom) wheel_one.add_outcome(1, outcome_one) wheel_one.add_outcome(2, outcome_two) wheel_one.next() self.assertTrue(wheel_one.next(), outcome_one ) # test get_outcome self.wheel_two = Wheel(nonrandom) BB = BinBuilder() BB.build_bins(self.wheel_two)
class GameTestCase(unittest.TestCase): """ This runs the game a few times for testing """ def test_game(self): log = logging.getLogger("GameTestCase.test_game") # make wheel self.nonrandom = NonRandom() self.nonrandom.set_seed(2) self.wheel = Wheel(self.nonrandom) # make BinBuilder and build bins for wheel bin_builder = BinBuilder() bin_builder.build_bins(self.wheel) # make table table = Table(limit=100) # make player _p57 = Passenger57(table=table, stake=100, rounds_to_go=100) # make game self.game = RouletteGame(self.wheel, table) # Test NonRandom self.assertEqual(id(self.wheel.next()), id(self.wheel.next())) # test game cycle with Passenger57 for i in range(4): self.game.cycle(_p57)
class GameTestCase(unittest.TestCase): """ This runs the game a few times for testing """ def test_game(self): log = logging.getLogger( "GameTestCase.test_game" ) # make wheel self.nonrandom = NonRandom() self.nonrandom.set_seed(2) self.wheel = Wheel(self.nonrandom) # make BinBuilder and build bins for wheel bin_builder = BinBuilder() bin_builder.build_bins(self.wheel) # make table table = Table(limit=100) # make player _p57 = Passenger57(table=table, stake=100, rounds_to_go=100) # make game self.game = RouletteGame(self.wheel, table) # Test NonRandom self.assertEqual(id(self.wheel.next()), id(self.wheel.next())) # test game cycle with Passenger57 for i in range(4): self.game.cycle(_p57)
def test_Wheel(self): """ http://www.itmaybeahack.com/book/oodesign-python-2.1/html/roulette/wheel.html#the-random-bin-selection-responsibility Wheel Deliverables A class which performs a unit test of building the Wheel class. The unit test should create several instances of Outcome, two instances of Bin, and an instance of Wheel. The unit test should establish that Bins can be added to the Wheel. A Non-Random Random Number Generator class, to be used for testing. A class which tests the Wheel and NonRandom class by selecting values from a Wheel object. """ outcome_one = Outcome("Red", 1) outcome_two = Outcome("Corner", 2) outcome_three = Outcome("Black", 3) outcome_four = Outcome("Street", 4) nonrandom = NonRandom() nonrandom.set_seed(1) wheel_one = Wheel(nonrandom) wheel_one.add_outcome(1, outcome_one) wheel_one.add_outcome(2, outcome_two) wheel_one.next() self.assertTrue(wheel_one.next(), outcome_one) # test get_outcome self.wheel_two = Wheel(nonrandom) BB = BinBuilder() BB.build_bins(self.wheel_two)
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_simulator_session(self): simulation_wheel = Wheel(1) simulation_table = Table(100,simulation_wheel) simulation_player = Martingale(simulation_table) simulation_player.set_rounds(self.simulator.init_duration) simulation_player.set_stake(self.simulator.init_stake) black = simulation_player.black #Martingale always bets on black simulated_stakes = [simulation_player.stake] while simulation_player.playing(): simulation_player.place_bets() outcome = simulation_wheel.next() if black in outcome: simulation_player.win(simulation_table.bets[0]) else: simulation_player.lose(simulation_table.bets[0]) simulation_table.clear_bets() simulated_stakes.append(simulation_player.stake) stakes = self.simulator.session() assert type(stakes) == list assert stakes == simulated_stakes
def test_wheel_next(): wheel = Wheel(seed=1) bb = BinBuilder() # bb.generate_straight_bets(wheel) bb.build_bins(wheel) # wheel.add_outcome(0, Outcome(f'0', 35)) ct = 10 expected_seq = [8, 36, 4, 16, 7, 31, 28, 30, 24, 13] for num in expected_seq: i, bin = wheel.next() assert num == i
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()