Esempio n. 1
0
 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
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
def test_add_outcome():
    wheel = Wheel()

    wheel.add_outcome(0, Outcome(f'0', 35))
    wheel.add_outcome(0, Outcome(f'0', 35))

    assert Outcome(f'0', 35) in wheel.get(0)
    assert 1 == len(wheel.get(0))

    wheel.add_outcome(0, Outcome(f'street', 11))
    assert Outcome(f'street', 11) in wheel.get(0)
    assert 2 == len(wheel.get(0))
Esempio n. 5
0
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"))
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
    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)
Esempio n. 9
0
    def test_BinBuilder(self):

        nonrandom = NonRandom()
        nonrandom.set_seed(1)

        wheel_one = Wheel(nonrandom)

        BB = BinBuilder()
        BB.build_bins(wheel_one)

        # maybe delete since it isn't asked for
        strait = BB.strait_bets()
        split = BB.split_bets()
        street = BB.street_bet()
        corner = BB.corner_bet()
        five = BB.five_bet()
        line = BB.line_bet()
        dozen = BB.dozen_bet()
        column = BB.column_bet()
        even = BB.even_money_bet()

        all_bin_methods_results = [
            strait, split, street, corner, five, line, dozen, column, even
        ]
        len_all_outcomes = sum(list(len(i) for i in all_bin_methods_results))
Esempio n. 10
0
def test_street_bets():
    wheel = Wheel()
    bb = BinBuilder()

    bb.generate_street_bets(wheel)
    for i, bin in enumerate(wheel.bins):
        if i == 0 or i == 37:
            assert 0 == len(bin)
        else:
            assert 1 == len(bin)

    for i in range(1, 36, 3):
        out = Outcome(f'{i} {i + 1} {i + 2}', 11)
        assert out in wheel.get(i)
        assert out in wheel.get(i + 1)
        assert out in wheel.get(i + 2)
Esempio n. 11
0
 def setUp(self):
     self.nonrandom = NonRandom()
     self.nonrandom.set_seed(1)  # red
     wheel = Wheel(self.nonrandom)
     self.table = Table(limit=100)
     bin_builder = BinBuilder()
     bin_builder.build_bins(wheel)
     self.game = RouletteGame(wheel, self.table)
Esempio n. 12
0
 def setUp(self):
     # wheel -- returns bin 2
     self.nonrandom = NonRandom()
     self.nonrandom.set_seed(2)  # black
     wheel = Wheel(self.nonrandom)
     self.table = Table(limit=100)
     bin_builder = BinBuilder()
     bin_builder.build_bins(wheel)
     self.game = RouletteGame(wheel, self.table)
Esempio n. 13
0
    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
Esempio n. 14
0
 def setup_method(self):
     wheel = Wheel(1)
     table = Table(100,wheel)
     martingale = Martingale(table)
     game = Game(table)
     
     assert martingale.rounds == None
     assert martingale.stake == None
     
     self.simulator = Simulator(game, martingale)
Esempio n. 15
0
def test_bin_staight_bets():
    wheel = Wheel()
    bb = BinBuilder()

    bb.generate_straight_bets(wheel)

    for i, bin in enumerate(wheel.bins):
        assert 1 == len(bin)
        nm = f'{i}' if i < 37 else '00'
        assert Outcome(nm, 35) in bin
Esempio n. 16
0
def test_generate_doze_bets():
    wheel = Wheel()
    bb = BinBuilder()
    bb.generate_dozen_bets(wheel)

    for i, bin in enumerate(wheel.bins):
        if i == 0 or i == 37:
            assert 0 == len(bin)
        else:
            out = Outcome(f'Dozen {math.ceil(i/12)}', 2)
            assert out in bin
Esempio n. 17
0
    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
Esempio n. 18
0
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))
Esempio n. 19
0
    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)
Esempio n. 20
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()
Esempio n. 21
0
def test_column_bets():
    wheel = Wheel()
    bb = BinBuilder()
    bb.generate_column_bets(wheel)

    col_one = Outcome(f'Column 1', 2)
    col_two = Outcome(f'Column 2', 2)
    col_thr = Outcome(f'Column 3', 2)
    outcomes = {1: col_one, 2: col_two, 0: col_thr}

    for i, bin in enumerate(wheel.bins):
        if i == 0 or i == 37:
            assert 0 == len(bin)
        else:
            out = outcomes[i % 3]
            assert out in bin
Esempio n. 22
0
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')
Esempio n. 23
0
def test_corner_bets():
    wheel = Wheel()
    bb = BinBuilder()
    bb.generate_corner_bets(wheel)

    for r in range(0, 11):
        n = 3 * r + 1
        outcome = Outcome(f'{n} {n+1} {n+3} {n+4}', 8)
        assert outcome in wheel.get(n)
        assert outcome in wheel.get(n + 1)
        assert outcome in wheel.get(n + 3)
        assert outcome in wheel.get(n + 4)

        n += 1
        outcome = Outcome(f'{n} {n + 1} {n + 3} {n + 4}', 8)
        assert outcome in wheel.get(n)
        assert outcome in wheel.get(n + 1)
        assert outcome in wheel.get(n + 3)
        assert outcome in wheel.get(n + 4)
Esempio n. 24
0
def test_line_bets():
    wheel = Wheel()
    bb = BinBuilder()
    bb.generate_line_bets(wheel)
    for r in range(0, 11):
        n = 3 * r + 1
        line_out = Outcome(f'{n} {n + 1} {n + 2} {n + 3} {n + 4} {n + 5}', 5)
        assert line_out in wheel.get(n)
        assert line_out in wheel.get(n + 1)
        assert line_out in wheel.get(n + 2)
        assert line_out in wheel.get(n + 3)
        assert line_out in wheel.get(n + 4)
        assert line_out in wheel.get(n + 5)
Esempio n. 25
0
def test_even_money_bets():
    wheel = Wheel()
    bb = BinBuilder()
    bb.generate_even_money_bets(wheel)
    # Red-Black
    reds = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36}
    blacks = set(range(1, 37)) - reds
    red_out = Outcome('Red', 1)
    black_out = Outcome('Black', 1)

    # Even-Odd
    even_out = Outcome('Even', 1)
    odd_out = Outcome('Odd', 1)

    # Hi - Lo
    hi_out = Outcome('High', 1)
    lo_out = Outcome('Low', 1)

    for i, bin in enumerate(wheel.bins):
        if i == 0 or i == 37:
            assert 0 == len(bin)
        elif i < 19:
            assert lo_out in bin
        else:
            assert hi_out in bin

        if i == 0 or i == 37:
            assert 0 == len(bin)
        elif i % 2 == 0:
            assert even_out in bin
        else:
            assert odd_out in bin

        if i == 0 or i == 37:
            assert 0 == len(bin)
        elif i in reds:
            assert red_out in bin
        else:
            assert black_out in bin
Esempio n. 26
0
 def setup_method(self, method):
     wheel = Wheel()
     self.table = Table(100, wheel)
Esempio n. 27
0
 def setup_method(self):
     self.wheel = Wheel(1)
Esempio n. 28
0
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)
Esempio n. 29
0
def test_table_place_bet():
    tt = Table(100, 5)
    wh = Wheel()
    bt = Bet(10, wh.get_outcome('Even'))
    assert True == tt.place_bet(bt)
def test_bin_builder():
    wheel = Wheel()
    bin_builder = BinBuilder()
    #straightbet test
    bin_builder.build_straight_bet(wheel, Outcome)
    assert Outcome('0', 35) in wheel.get_bin(0)
    assert Outcome('00', 35) in wheel.get_bin(37)
    assert Outcome('1', 35) in wheel.get_bin(1)
    assert Outcome('36', 35) in wheel.get_bin(36)

    #splitbet test
    wheel = Wheel()
    bin_builder.build_split_bet(wheel, Outcome)
    assert Outcome('1-2', 17) in wheel.get_bin(1)
    assert Outcome('1-4', 17) in wheel.get_bin(1)
    assert Outcome('33-36', 17) in wheel.get_bin(36)
    assert Outcome('35-36', 17) in wheel.get_bin(36)

    #streetbet
    wheel = Wheel()
    bin_builder.build_street_bet(wheel, Outcome)
    assert Outcome('1-2-3', 11) in wheel.get_bin(1)
    assert Outcome('34-35-36', 11) in wheel.get_bin(36)

    #Cornerbet
    wheel = Wheel()
    bin_builder.build_corner_bets(wheel, Outcome)
    assert Outcome('1-2-4-5', 8) in wheel.get_bin(1)
    assert Outcome('4-5-7-8', 8) in wheel.get_bin(4)
    assert Outcome('5-6-8-9', 8) in wheel.get_bin(5)

    #linebet
    wheel = Wheel()
    bin_builder.build_line_bets(wheel, Outcome)
    assert Outcome('1-2-3-4-5-6', 5) in wheel.get_bin(1)
    assert 1 == len(wheel.get_bin(1))
    assert Outcome('1-2-3-4-5-6', 5) in wheel.get_bin(4)
    assert Outcome('4-5-6-7-8-9', 5) in wheel.get_bin(4)

    # dozen bet
    wheel = Wheel()
    bin_builder.build_dozen_bets(wheel, Outcome)
    assert Outcome('1-dozen', 2) in wheel.get_bin(1)
    assert Outcome('2-dozen', 2) in wheel.get_bin(17)
    assert Outcome('3-dozen', 2) in wheel.get_bin(36)

    #column bet
    wheel = Wheel()
    bin_builder.build_column_bets(wheel, Outcome)
    assert Outcome('1-column', 2) in wheel.get_bin(1)
    assert Outcome('2-column', 2) in wheel.get_bin(17)
    assert Outcome('3-column', 2) in wheel.get_bin(36)

    #evenbet
    wheel = Wheel()
    bin_builder.build_even_money_bets(wheel, Outcome)
    assert Outcome('Red', 1) in wheel.get_bin(1)
    assert Outcome('Low', 1) in wheel.get_bin(1)
    assert Outcome('Odd', 1) in wheel.get_bin(1)
    assert Outcome('Black', 1) in wheel.get_bin(17)
    assert Outcome('Low', 1) in wheel.get_bin(17)
    assert Outcome('Odd', 1) in wheel.get_bin(17)
    assert Outcome('Black', 1) in wheel.get_bin(17)
    assert Outcome('Red', 1) in wheel.get_bin(18)
    assert Outcome('Even', 1) in wheel.get_bin(18)
    assert Outcome('Low', 1) in wheel.get_bin(18)
    assert Outcome('Red', 1) in wheel.get_bin(36)
    assert Outcome('Even', 1) in wheel.get_bin(36)
    assert Outcome('High', 1) in wheel.get_bin(36)

    #fivebet
    wheel = Wheel()
    bin_builder.build_five_bet(wheel, Outcome)
    assert Outcome('00-0-1-2-3', 6) in wheel.get_bin(0)
    assert Outcome('00-0-1-2-3', 6) in wheel.get_bin(37)
def test_wheel_sequence():
    wheel = Wheel()
    wheel.add_outcome(8, {Outcome("test", 1)})
    wheel.randgenerator.seed(1)
    assert Outcome("test", 1) in wheel.choose()
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()