def test_reset_turn(self): # Test if function returns the leaderboard_len() decremnted by 1 in str format # init_game() add_to_leaderboard("Jason", 'data/leaderboard.json') add_to_leaderboard("Zebra", 'data/leaderboard.json') assert type(reset_turn('3')) is str self.assertEqual((int(reset_turn('2'))), 1)
def test_get_player_score(self): # Test if function gets a players name # init_game() add_to_leaderboard("Jason", 'data/leaderboard.json') add_to_leaderboard("Zebra", 'data/leaderboard.json') increase_user_score("Zebra", '2') self.assertEqual(get_player_score(1), 0) self.assertEqual(get_player_score(0), 10)
def test_increase_user_score_global(self): # Test if function increases the users score on the global leaderboard # clear_global_leaderboard() init_game() add_to_leaderboard_global("Petey", 'data/global_leaderboard.json') decrement_score('4') self.assertEqual(increase_user_score_global("Petey", '1'), 10) self.assertEqual(increase_user_score_global("Petey", '4'), 19)
def test_right_or_wrong(self): # Test if function checks if an answer is right or wrong # init_game() add_to_leaderboard("Jason", 'data/leaderboard.json') add_to_leaderboard("Paul", 'data/leaderboard.json') add_to_leaderboard("Eva", 'data/leaderboard.json') self.assertEqual(right_or_wrong("Jason", "Telephone", '0'), True) self.assertEqual(right_or_wrong("Paul", "The wrong answer", '2'), None) self.assertEqual(right_or_wrong("Eva", "Fall", '1'), True)
def test_add_to_leaderboard(self): # Test if function adds a new user to leaderboard # init_game() self.assertEqual(add_to_leaderboard('Jon', 'data/leaderboard.json'), True) self.assertEqual(add_to_leaderboard('Paul', 'data/leaderboard.json'), True) self.assertEqual(add_to_leaderboard('Sarah', 'data/leaderboard.json'), True)
def test_order_leaderboard(self): # Test if function returns a rearranged version of the leaderboard list # init_game() add_to_leaderboard("Jamie", 'data/leaderboard.json') add_to_leaderboard("Petey", 'data/leaderboard.json') increase_user_score("Petey", '1') with open("data/leaderboard.json", "r") as json_file: loaded_json = json.load(json_file) original_leaderboard = loaded_json['leaderboard'] assert type(order_leaderboard()) is list self.assertNotEqual(order_leaderboard(), original_leaderboard)
def index(): # User(s) enter the number of players in the game # init_game() if request.method == "POST": if int( request.form["playernum"] ) > 4 or int( request.form["playernum"] ) < 1: flash("Please Enter a Valid Number of Players (Max. 4, Min. 1)") return redirect("/") else: playernum = request.form["playernum"] return redirect("setup" + '/' + playernum) return render_template("index.html")
def test_check_answer(self): # Test if function checks if an answer is correct # init_game() self.assertEqual(check_answer("Telephone", '0'), True) self.assertEqual(check_answer("The wrong answer", '1'), False)
def test_decrement_turns(self): # Tests if function decrements the turn value of a question # init_game() self.assertEqual(decrement_turns('1'), 2) self.assertEqual(decrement_turns('2'), 2)
def test_decrement_score(self): # Tests if function decrements the points value of a question # init_game() self.assertEqual(decrement_score('1'), 9) self.assertEqual(decrement_score('1'), 8)
def test_next_player(self): # Test that function returns the next username # init_game() add_to_leaderboard("Jason", 'data/leaderboard.json') add_to_leaderboard("Zebra", 'data/leaderboard.json') self.assertEqual(next_player('Jason', '1'), 'Zebra')
def test_turn_display(self): # Test that function displays the turns value # init_game() decrement_turns('2') self.assertEqual(turn_display('1'), 3) self.assertEqual(turn_display('2'), 2)
def test_score_display(self): # Test that function displays the questions points value # init_game() decrement_score('2') self.assertEqual(score_display('1'), 10) self.assertEqual(score_display('2'), 9)
def test_q_update(self): # Test if function returns the qnumber decremnted by 1 in str format # init_game() assert type(q_update('3')) is str self.assertEqual((int(q_update('3'))), 2)
def test_get_question_points(self): # Test if function gets a questions points value # init_game() decrement_score('2') self.assertEqual(get_question_points('1'), 10) self.assertEqual(get_question_points('2'), 9)