Fix TrueFalse responses with single answers.

This commit is contained in:
Peter Fogg
2015-07-24 10:28:08 -04:00
parent f4e386268b
commit 95eccf6ea1
2 changed files with 9 additions and 2 deletions

View File

@@ -1323,9 +1323,11 @@ class TrueFalseResponse(MultipleChoiceResponse):
def get_score(self, student_answers):
correct = set(self.correct_choices)
answers = set(student_answers.get(self.answer_id, []))
answers = student_answers.get(self.answer_id, [])
if not isinstance(answers, list):
answers = [answers]
if correct == answers:
if correct == set(answers):
return CorrectMap(self.answer_id, 'correct')
return CorrectMap(self.answer_id, 'incorrect')

View File

@@ -151,6 +151,11 @@ class TrueFalseResponseTest(ResponseTest):
self.assert_grade(problem, 'choice_foil_4', 'incorrect')
self.assert_grade(problem, 'not_a_choice', 'incorrect')
def test_single_correct_response(self):
problem = self.build_problem(choices=[True, False])
self.assert_grade(problem, 'choice_0', 'correct')
self.assert_grade(problem, ['choice_0'], 'correct')
class ImageResponseTest(ResponseTest):
xml_factory_class = ImageResponseXMLFactory