def test_add_rank(database): if not os.path.exists(database.rank_path): player = Player("user") database.add_result_to_rank(player, 100) database1 = Database() exp_rank = {"user": "******"} assert database1.rank == exp_rank pass
def __init__(self): self.name = "Millionaires" self.levels = [ 500, 1000, 2000, 5000, 10000, 20000, 40000, 75000, 125000, 250000, 500000, 1000000, ] self.base = Database() self.ans_in_game = [] self.max_number_hints = 2 self.player_acc = 0
def test_rank_file(): with open("/home/tm/PycharmProjects/Millionaires/baza/rank.json", "w") as file: json.dump({"tm": "100 PLN", "az": "200 PLN", "pz": "100 PLN"}, file) database2 = Database() assert database2.rank == { "tm": "100 PLN", "az": "200 PLN", "pz": "100 PLN" } assert isinstance(database2.rank, dict)
class Game: counter = 0 def __init__(self): self.name = "Millionaires" self.levels = [ 500, 1000, 2000, 5000, 10000, 20000, 40000, 75000, 125000, 250000, 500000, 1000000, ] self.base = Database() self.ans_in_game = [] self.max_number_hints = 2 self.player_acc = 0 # function responsible for select new question from database and checking if the questions have already been asked def select_new_question(self, category, number_question): id_ans = self.base.questions_base.loc[(category, number_question), "ID"] if id_ans not in self.ans_in_game: self.ans_in_game.append(id_ans) return True return False def draw_category(self): return choice(self.base.categories) def draw_number_question(self, category): return randint(1, len(self.base.questions_base.loc[category, :])) # choice of 50/50 hint def hint(self, category, number_question): cols_lst = [] lst_col = list(self.base.questions_base[["A", "B", "C", "D"]].columns) for column in lst_col: if self.is_correct_answer(category, number_question, column): cols_lst.append(column) while True: sec_col = choice(lst_col) if sec_col not in cols_lst: cols_lst.append(sec_col) break self.max_number_hints -= 1 shuffle(cols_lst) return cols_lst # checking if hint is available def check_number_of_hints(self): if self.max_number_hints > 0: return True return False # checking if queston is correct def check_question(self, category, number_question, answer): if self.is_correct_answer(category, number_question, answer): self.add_player_cash() self.counter += 1 return True return False # direct checking of assertions in a pandas def is_correct_answer(self, category, number_question, answer): if (self.base.questions_base.loc[( category, number_question), answer] == self.base.questions_base.loc[( category, number_question), "Answer"]): return True return False # ending game after incorrect answer or winning million def end_game(self, player): self.base.add_result_to_rank(player, self.player_acc) # actualization of player account def add_player_cash(self): self.player_acc = self.levels[self.counter]
def test_database(): database = Database() assert database
def setup_database(): database = Database() return database
def __init__(self, nick, password): super().__init__(nick) self.password = password self.printer = Printer() self.database = Database()