Commit 4c0cc81d by Lyla Fischer

added tests

parent ca89ce73
<problem>
<multiplechoiceresponse max="10" randomize="yes">
<choicegroup>
<choice location="random" correct="false" name="foil1">
<startouttext />This is foil One.<endouttext />
</choice>
<choice location="random" correct="false" name="foil2">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice location="random" correct="true" name="foil3">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice location="random" correct="false" name="foil4">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice location="random" correct="false" name="foil5">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
<problem>
<truefalseresponse max="10" randomize="yes">
<choicegroup>
<choice location="random" correct="true" name="foil1">
<startouttext />This is foil One.<endouttext />
</choice>
<choice location="random" correct="true" name="foil2">
<startouttext />This is foil Two.<endouttext />
</choice>
<choice location="random" correct="false" name="foil3">
<startouttext />This is foil Three.<endouttext />
</choice>
<choice location="random" correct="false" name="foil4">
<startouttext />This is foil Four.<endouttext />
</choice>
<choice location="random" correct="false" name="foil5">
<startouttext />This is foil Five.<endouttext />
</choice>
</choicegroup>
</truefalseresponse>
</problem>
import unittest
import os
import numpy
import courseware.modules
import courseware.capa.calc as calc
import courseware.capa.capa_problem as lcp
from grades import Score, aggregate_scores
class ModelsTest(unittest.TestCase):
......@@ -59,6 +61,29 @@ class ModelsTest(unittest.TestCase):
exception_happened = True
self.assertTrue(exception_happened)
class MultiChoiceTest(unittest.TestCase):
def test_MC_grade(self):
multichoice_file = os.getcwd()+"/djangoapps/courseware/test_files/multichoice.xml"
test_lcp = lcp.LoncapaProblem(multichoice_file, '1')
correct_answers = {'1_2_1':'foil3'}
self.assertEquals(test_lcp.grade_answers(correct_answers)['1_2_1'], 'correct')
false_answers = {'1_2_1':'foil2'}
self.assertEquals(test_lcp.grade_answers(false_answers)['1_2_1'], 'incorrect')
def test_TF_grade(self):
truefalse_file = os.getcwd()+"/djangoapps/courseware/test_files/truefalse.xml"
test_lcp = lcp.LoncapaProblem(truefalse_file, '1')
correct_answers = {'1_2_1':['foil2', 'foil1']}
self.assertEquals(test_lcp.grade_answers(correct_answers)['1_2_1'], 'correct')
false_answers = {'1_2_1':['foil1']}
self.assertEquals(test_lcp.grade_answers(false_answers)['1_2_1'], 'incorrect')
false_answers = {'1_2_1':['foil1', 'foil3']}
self.assertEquals(test_lcp.grade_answers(false_answers)['1_2_1'], 'incorrect')
false_answers = {'1_2_1':['foil3']}
self.assertEquals(test_lcp.grade_answers(false_answers)['1_2_1'], 'incorrect')
false_answers = {'1_2_1':['foil1', 'foil2', 'foil3']}
self.assertEquals(test_lcp.grade_answers(false_answers)['1_2_1'], 'incorrect')
class GraderTest(unittest.TestCase):
def test_weighted_grading(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment