def test_template(template): """Tests if the creation of a template ends up with a valid template. Returns 1/0 for success/failure.""" got_trough_test = 0 # 1 if template got through test, and 0 if not. # Make numbers, check condition, check calculations random_domain = template.random_domain # Efficiency note: it might be faster to pass the domain list, instead of getting them from template every time. answer = template.answer question = template.question_text solution = template.solution conditions = template.conditions conditions = remove_unnecessary(conditions) variable_dict = generate_valid_numbers(question, random_domain, "", False) inserted_conditions = string_replace(conditions, variable_dict) if len(conditions) > 1: conditions_pass = sympify(latex_to_sympy(inserted_conditions)) else: conditions_pass = True if conditions_pass: answer = string_replace(answer, variable_dict) solution = string_replace(solution, variable_dict) try: answer = parse_answer(answer, random_domain) parse_solution(solution, random_domain) # Checks if solution can be parsed got_trough_test = 1 except Exception: pass if answer == 'error': got_trough_test = 0 return got_trough_test
def multifill(choices, variable_dict): """Returns choices with fill in the blanks capability""" choices = choices.replace("@?", "") choices = choices.replace("?@", "") possible_holes = list(variable_dict.keys()) shuffle(possible_holes) choices = choices.split("§") shuffle(choices) for x in range(len(choices)): if choices[x].count(possible_holes[0]) > 0: choices[x] = choices[x].replace(possible_holes[0], "\\MathQuillMathField{}") else: for z in range(1, len(possible_holes)): if choices[x].count(possible_holes[z]) > 0: choices[x] = choices[x].replace(possible_holes[z], "\\MathQuillMathField{}") break choices = "§".join(choices) choices = string_replace(choices, variable_dict) return choices