def setup_data(mock_dynamodb):
    created_wheel = json.loads(
        wheel.create_wheel({'body': {
            'name': 'Test Wheel'
        }})['body'])

    create_participant_events = [{
        'pathParameters': {
            'wheel_id': created_wheel['id']
        },
        'body': {
            'name': name,
            'url': 'https://amazon.com'
        }
    } for name in ['Dan', 'Alexa', 'Jeff']]

    created_participants = [
        json.loads(wheel_participant.create_participant(event)['body'])
        for event in create_participant_events
    ]

    # Reloads the wheel with updated participant count
    return {
        'wheel':
        json.loads(
            wheel.get_wheel({
                'body': {},
                'pathParameters': {
                    'wheel_id': created_wheel['id']
                }
            })['body']),
        'participants':
        created_participants
    }
Пример #2
0
def run_simulation(init_duration, init_stake, samples, player):
    """ Run simulation, print the result to stdout

    """
    wheel = create_wheel()
    table = Table(wheel)
    game = RouletteGame(wheel, table)
    simulator = Simulator(game, player,
                          init_duration=init_duration, samples=samples,
                          init_stake=init_stake)
    simulator.gather()
    durations = simulator.durations
    maxima = simulator.maxima
    print(player)
    print()
    print("Durations")
    print("  min :", min(durations))
    print("  max :", max(durations))
    print("  mean: %.2f" % statistics.mean(durations))
    print("  dev : %.2f" % statistics.stdev(durations))
    print("Maxima")
    print("  min :", min(maxima))
    print("  max :", max(maxima))
    print("  mean: %.2f" % statistics.mean(maxima))
    print("  dev : %.2f" % statistics.stdev(maxima))
Пример #3
0
def create_simulator():
    rng = NonRandom([
        # 2 blacks, 2 red
        2,
        6,
        5,
        7,
        # 4 blacks
        2,
        6,
        4,
        8,
        # 4 red
        27,
        30,
        32,
        34,
    ])
    wheel = create_wheel(rng=rng)
    table = Table(wheel)
    game = RouletteGame(wheel, table)
    simulator = Simulator(game,
                          "Passenger57",
                          init_duration=4,
                          samples=3,
                          init_stake=10)
    return simulator
Пример #4
0
def test_create_wheel(mock_dynamodb, mock_wheel_table):
    event = {'body': {'name': 'Test Wheel'}}

    response = wheel.create_wheel(event)
    created_wheel = json.loads(response['body'])

    assert response['statusCode'] == 200
    assert created_wheel['name'] == event['body']['name']
    assert mock_wheel_table.get_existing_item(Key={'id': created_wheel['id']})
Пример #5
0
def test_random_player():
    wheel = create_wheel()
    rng = NonRandomOutcomeChoice(wheel)
    expected_outcomes = [wheel.get_outcome(n) for n in ["Black", "Low", "00"]]
    rng.set_outcomes(expected_outcomes)
    table = Table(wheel)
    random_player = RandomPlayer(table, rng=rng)
    bets = [random_player.next_bet() for i in range(3)]
    actual_outcomes = [b.outcome for b in bets]
    assert actual_outcomes == expected_outcomes
Пример #6
0
def test_random_player():
    wheel = create_wheel()
    rng = NonRandomOutcomeChoice(wheel)
    expected_outcomes = [wheel.get_outcome(n) for n in ["Black", "Low", "00"]]
    rng.set_outcomes(expected_outcomes)
    table = Table(wheel)
    random_player = RandomPlayer(table, rng=rng)
    bets = [random_player.next_bet() for i in range(3)]
    actual_outcomes = [b.outcome for b in bets]
    assert actual_outcomes == expected_outcomes
Пример #7
0
def test_place_bet():
    wheel = create_wheel()
    table = Table(wheel)
    zerozero = Outcome("00", 35)
    zerozero_bet = Bet(900, zerozero)
    red_bet = Bet(60, Outcome("Red", 1))
    table.place_bet(zerozero_bet)
    table.place_bet(red_bet)
    assert [x.bet_amount for x in table] == [900, 60]
    with pytest.raises(InvalidBet):
        table.place_bet(red_bet)
Пример #8
0
def test_roulette_game():
    rng = NonRandom([0, 2])
    wheel = create_wheel(rng)
    table = Table(wheel)

    player = Passenger57(table)
    player.set_stake(20)
    game = RouletteGame(wheel, table)
    game.cycle(player)
    assert player.losses == [10]
    assert player.wins == list()
    game.cycle(player)
    assert player.losses == [10]
    assert player.wins == [10]
Пример #9
0
def create_simulator():
    rng = NonRandom(
        [
        # 2 blacks, 2 red
        2, 6, 5, 7,
        # 4 blacks
        2, 6, 4, 8,
        # 4 red
        27, 30, 32, 34,
        ]
    )
    wheel = create_wheel(rng=rng)
    table = Table(wheel)
    game = RouletteGame(wheel, table)
    simulator = Simulator(game, "Passenger57",
                          init_duration=4, samples=3,
                          init_stake=10)
    return simulator
Пример #10
0
def test_invalid_create_wheel(mock_dynamodb):
    response = wheel.create_wheel({'body': {'name': ''}})

    assert response['statusCode'] == 400
    assert 'New wheels require a name that must be a string with a length of at least 1' in response[
        'body']
Пример #11
0
def create_game(rng=None):
    """ Create a new gam """
    wheel = create_wheel(rng=rng)
    table = Table(wheel)
    game = RouletteGame(wheel, table)
    return game
Пример #12
0
def create_table():
    wheel = create_wheel()
    table = Table(wheel)
    return table
Пример #13
0
def test_missing_body(mock_dynamodb):
    with pytest.raises(Exception):
        wheel.create_wheel({'not_body': 'Nobody is in here'})
Пример #14
0
def test_no_dynamodb_available():
    response = wheel.create_wheel({'body': {'name': 'DDB not available'}})
    assert response['statusCode'] == 500
Пример #15
0
def create_game(rng=None):
    """ Create a new gam """
    wheel = create_wheel(rng=rng)
    table = Table(wheel)
    game = RouletteGame(wheel, table)
    return game
Пример #16
0
def create_table():
    wheel = create_wheel()
    table = Table(wheel)
    return table