예제 #1
0
 def test_bet_on_zero(self):
     player_bet = {'money': 20, 'color': 'black', 'number': 0}
     bet = {'color': 'red', 'number': 0}
     result = calculate_bet_result(player_bet, bet)
     expected_win = 200
     actual_win = result['player_win']
     self.assertEqual(actual_win, expected_win)
예제 #2
0
 def test_lost_bet_number_color(self):
     player_bet = {'money': 20, 'color': 'black', 'number': 32}
     bet = {'color': 'red', 'number': 23}
     result = calculate_bet_result(player_bet, bet)
     expected_win = -20
     actual_win = result['player_win']
     self.assertEqual(actual_win, expected_win)
예제 #3
0
def home():
    lst = generate_list()
    username = session.get('username')
    with db:
        balance = db.fetchPlayer(username).balance
    player = {'username': username, 'balance': balance}
    if request.method == 'POST':
        player_bet_money = request.form['moneyToBet']
        if correct_bet(player_bet_money, balance):
            bet = generate_bet()
            color = request.form['exampleRadios']
            number = request.form['bet_number']
            player_bet = format_player_bet(player_bet_money, color, number)
            bet_result = calculate_bet_result(player_bet, bet)
            new_bet_obj = generateBetForDb(player_bet, bet_result)
            new_casino_obj = generateCasinoData(username, new_bet_obj.bet_id)
            with db:
                db.createBet(new_bet_obj)
                db.createCasino(new_casino_obj)
            new_balance = balance + bet_result['player_win']
            player = {'username': username, 'balance': new_balance}
            with db:
                db.updatePlayerBalance(username, new_balance)
            return render_template('play.html',
                                   lst=lst,
                                   player=player,
                                   bet=str(bet),
                                   player_bet=str(player_bet),
                                   bet_result=str(bet_result))
        else:
            error = 'Wrong number! Bet must be number less than ' + str(
                balance)
            return render_template('play.html',
                                   lst=lst,
                                   player=player,
                                   error=error)
    return render_template('play.html', lst=lst, player=player)
예제 #4
0
 def test(self):
     player_bet = {'money': '12', 'color': 'black', 'number': 'None'}
     bet = {'color': 'black', 'number': 20}
     bet_res = calculate_bet_result(player_bet, bet)