Exemplo n.º 1
0
    def test_string_grader(self):
        cases = [
            case for case in self.testcases if case['test'] == 'string_grader'
        ]
        for tc in cases:
            u = Ubbr(tc['source'])
            data = u.get_context()[1]
            for r in data:
                grader = StringInputGrader()
                for answer in tc['correct']:
                    self.assertEqual(grader.grade(answer, r)[0], True)
                for answer in tc['incorrect']:
                    self.assertEqual(grader.grade(answer, r)[0], False)

    def test_integer_grader(self):
        cases = [
            case for case in self.testcases if case['test'] == 'integer_grader'
        ]
        for tc in cases:
            u = Ubbr(tc['source'])
            data = u.get_context()[1]
            for r in data:
                grader = IntegerInputGrader()
                for answer in tc['correct']:
                    self.assertEqual(grader.grade(answer, r)[0], True)
                for answer in tc['incorrect']:
                    self.assertEqual(grader.grade(answer, r)[0], False)
Exemplo n.º 2
0
 def test_random_seed(self):
     #  checking that the random seed passes to the Ubbr correctly
     cases = [a for a in self.testcases if a['test'].startswith('random')]
     for tc in cases:
         u = Ubbr(tc['source'])
         one = u.get_context(random_seed=4)
         two = u.get_context(random_seed=4)
         self.assertEqual(one, two)
Exemplo n.º 3
0
 def test_string_grader(self):
     cases = [
         case for case in self.testcases if case['test'] == 'stringgrader'
     ]
     for tc in cases:
         u = Ubbr(tc['source'])
         resources = u.get_context()[1]
         for r in resources:
             pass
Exemplo n.º 4
0
    def test_integer_grader(self):
        cases = [case for case in self.testcases if case['test']=='integer_grader']
        for tc in cases:
            u = Ubbr(tc['source'])
            data = u.get_context()[1]
            for r in data:
                grader = IntegerInputGrader()
                for answer in tc['correct']:
                    self.assertEqual(grader.grade(answer,r)['score'],grader.grade(answer,r)['max_score'])
                for answer in tc['incorrect']:
                    self.assertEqual(grader.grade(answer,r)['score'],int(0))


    def est_decimal_input_precision(self):
        tcs = [c  for c in self.testcases if c['test']=='DecimalInput Precision']
        for case in tcs:
            u = Ubbr(case['source'])
            data = u.get_context()[1]
            for r in data:
                grader = DecimalInputGrader()
                for answer in case['correct']:
                    self.assertEqual(grader.grade(answer,r)['score'],grader.grade(answer,r)['max_score'])
                for answer in case['incorrect']:
                    self.assertEqual(grader.grade(answer,r)['score'],int(0))

 
    def est_sage_expression_input(self):
        tcs = [c  for c in self.testcases if c['test']=='ExpressionInput']
        for case in tcs:
            u = Ubbr(case['source'])
            data = u.get_context()[1]
            for r in data:
                grader = ExpressionInputGrader()
                for answer in case['correct']:
                    print(r)
                    print(answer)
                    self.assertEqual(grader.grade(answer,r)['score'],grader.grade(answer,r)['max_score'])
                for answer in case['incorrect']:
                    print(answer)
                    self.assertEqual(grader.grade(answer,r)['score'],int(0))

            

 
    def test_sage_expression_input_grader(self):
        tcs = [c  for c in self.testcases if c['test']=='ExpressionInputGrader']
        for case in tcs:
            data = case['data']
            grader = ExpressionInputGrader()
            for answer in case['correct']:
                print(data)
                print(answer)
                self.assertEqual(grader.grade(answer,data)['score'],grader.grade(answer,data)['max_score'])
            for answer in case['incorrect']:
                print(answer)
                self.assertEqual(grader.grade(answer,data)['score'],int(0))
Exemplo n.º 5
0
    def test_string_input(self):
        cases = [case for case in self.testcases if case['test'] == 'input']
        for tc in cases:
            u = Ubbr(tc['source'])
            nodes = u.get_context()[0]
            for j in range(len(nodes)):
                self.assertRegex(nodes[j], tc['output']['ubbrvalues'][j])

    def test_xml_style_tags(self):
        cases = [case for case in self.testcases if case['test'] == 'xml tags']
        for tc in cases:
            u = Ubbr(tc['source'], tag_style='xml')
            ubbrvalues = u.get_context()[0]
            self.assertEqual(ubbrvalues, tc['output']['ubbrvalues'])
Exemplo n.º 6
0
    def test_string_input(self):
        cases = [case for case in self.testcases if case['test'] == 'input']
        for tc in cases:
            u = Ubbr(tc['source'])
            nodes = u.get_context()[0]
            for j in range(len(nodes)):
                self.assertRegex(nodes[j], tc['output']['ubbrvalues'][j])

    def test_string_grader(self):
        cases = [
            case for case in self.testcases if case['test'] == 'stringgrader'
        ]
        for tc in cases:
            u = Ubbr(tc['source'])
            resources = u.get_context()[1]
            for r in resources:
                pass
Exemplo n.º 7
0
def problem_view(request, id):
    model_ubbr = ModelUbbr.objects.get(id=id)
    ubbr = Ubbr(model_ubbr.source)
    # get the template string and context values from the Ubbr
    template_string = ubbr.template
    random_seed = request.GET.get('seed', '1')
    ubbrvalues = ubbr.get_context(random_seed=random_seed)[0]

    # now some standard django code for rendering a template
    # from a string and a dict of context values
    context = RequestContext(
        request,
        autoescape=False)  # we use a RequestContext to enable csrf protection
    context.update({
        'ubbrvalues': ubbrvalues,
        'problem_id': model_ubbr.id,
    })
    template = Template(template_string)
    return HttpResponse(template.render(context))
Exemplo n.º 8
0
def problem_grade(request, id):
    if request.method != 'POST':
        return HttpResponse('Only POST requests are supported')
# load the Ubbr from the DB and get the answer data
    model_ubbr = ModelUbbr.objects.get(id=id)
    ubbr = Ubbr(model_ubbr.source)
    # get the template and context values from the Ubbr
    template_string = ubbr.template
    random_seed = request.GET.get('seed', '1')
    ubbrdata = ubbr.get_context(random_seed=random_seed)[1]

    # now use the graders to compare the submitted values with the
    # correct answers
    results = {}
    for inp in ubbrdata:
        grader = grader_from_data_type(inp['data_type'])().grade

        submitted = request.POST.get('ubbr-input-{}'.format(inp['data_id']),
                                     None)
        results.update({inp['data_id']: grader(submitted, inp)})

    return HttpResponse(json.dumps(results))
Exemplo n.º 9
0
 def test_xml_style_tags(self):
     cases = [case for case in self.testcases if case['test'] == 'xml tags']
     for tc in cases:
         u = Ubbr(tc['source'], tag_style='xml')
         ubbrvalues = u.get_context()[0]
         self.assertEqual(ubbrvalues, tc['output']['ubbrvalues'])
Exemplo n.º 10
0
 def test_get_context(self):
     cases = [a for a in self.testcases if a['test'].startswith('basic')]
     for tc in cases:
         u = Ubbr(tc['source'])
         nodes = u.get_context()[0]
         self.assertEqual(nodes, tc['output']['ubbrvalues'])