예제 #1
0
    def _generate_problem_set(quantity):
        problems = []
        for k, v in quantity.items():
            #                {0:8, 1:2}
            while v > 0:
                problem = generate_problem(k)
                new_problem_info = {
                    'question': problem.question,
                    'answer': problem.answer,
                    'difficulty': k,
                    'correct': False
                }
                problems.append(new_problem_info)
                v -= 1

        return problems
예제 #2
0
def test_randomly_generate_multiplication_problem(client):
    test_problem = generate_problem(0)
    assert eval(test_problem.question) == int(test_problem.answer)
예제 #3
0
def test_randomly_generate_composite_mult_add_problem(client):
    test_problem = generate_problem(2, 0)
    assert eval(test_problem.question) == int(test_problem.answer)
예제 #4
0
def test_randomly_generate_division_problem(client):
    # Due to floating point arithmetic, it's sufficient to check answer
    # within a hundreth
    test_problem = generate_problem(3)
    exact_answer = eval(test_problem.question)
    assert (exact_answer - .01) < test_problem.answer < (exact_answer + .01)
예제 #5
0
def test_randomly_generate_subtraction_problem(client):
    test_problem = generate_problem(2)
    assert eval(test_problem.question) == int(test_problem.answer)
예제 #6
0
def test_randomly_generate_addition_problem(client):
    test_problem = generate_problem(1)
    assert eval(test_problem.question) == int(test_problem.answer)