Example #1
0
    def test_problem_generates_correct_blocks(self):
        p1 = Problem(solution='(+ (- 3 2) (* 2 5))', evaluates_to='11', points=5)
        b1 = p1.generate_initial_data()['blocks']
        self.assertEqual(b1, [['(', '<nt>', '<nt>', '<nt>', ')'], ['+'], ['(', '<nt>', '<nt>', '<nt>', ')'], ['-'], ['3'], ['2'], ['(', '<nt>', '<nt>', '<nt>', ')'], ['*'], ['2'], ['5']])

        p2 = Problem(solution='(sqrt 16)', evaluates_to='11', points=5)
        p2 = Problem(solution='(sqrt 16)', evaluates_to='11', points=5)
        b2 = p2.generate_initial_data()['blocks']
        self.assertEqual(b2, [['(', '<nt>', '<nt>', ')'], ['sqrt'], ['16']])
Example #2
0
    def test_initial_data(self):
        """
        Test that the initial data JSON generated by the problem is correct.
        """
        p1 = Problem(pk=1, solution='(+ 3 (- 2 5))', points=4, evaluates_to='0')
        p1_initial_data = {}
        p1_initial_data['problem_number'] = 1
        p1_initial_data['solution'] = '(+ 3 (- 2 5))'
        p1_initial_data['blocks'] = [['(', '<nt>', '<nt>', '<nt>', ')'], ['+'], ['3'], ['(', '<nt>', '<nt>', '<nt>', ')'], ['-'], ['2'], ['5']]
        p1_initial_data['evaluates_to'] = '0'

        p2 = Problem(pk=2131312, solution='(+ (- 3 2) (* 2 5))', points=6, evaluates_to='11')
        p2_initial_data = {}
        p2_initial_data['problem_number'] = 2131312
        p2_initial_data['solution'] = '(+ (- 3 2) (* 2 5))'
        p2_initial_data['blocks'] = [['(', '<nt>', '<nt>', '<nt>', ')'], ['+'], ['(', '<nt>', '<nt>', '<nt>', ')'], ['-'], ['3'], ['2'], ['(', '<nt>', '<nt>', '<nt>', ')'], ['*'], ['2'], ['5']]
        p2_initial_data['evaluates_to'] = '11'
        self.assertEqual(p2_initial_data, p2.generate_initial_data())