diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index 2e394e5e1b..00600573e7 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -715,12 +715,13 @@ class ChoiceResponse(LoncapaResponse): if not isinstance(student_answer, list): student_answer = [student_answer] + no_empty_answer = student_answer != [] student_answer = set(student_answer) required_selected = len(self.correct_choices - student_answer) == 0 no_extra_selected = len(student_answer - self.correct_choices) == 0 - correct = required_selected & no_extra_selected + correct = required_selected & no_extra_selected & no_empty_answer if correct: return CorrectMap(self.answer_id, 'correct') diff --git a/common/lib/capa/capa/tests/test_responsetypes.py b/common/lib/capa/capa/tests/test_responsetypes.py index 77bdd640f6..c1124d187b 100644 --- a/common/lib/capa/capa/tests/test_responsetypes.py +++ b/common/lib/capa/capa/tests/test_responsetypes.py @@ -1075,6 +1075,17 @@ class ChoiceResponseTest(ResponseTest): # No choice 3 exists --> mark incorrect self.assert_grade(problem, 'choice_3', 'incorrect') + def test_grade_with_no_checkbox_selected(self): + """ + Test that answer marked as incorrect if no checkbox selected. + """ + problem = self.build_problem( + choice_type='checkbox', choices=[False, False, False] + ) + + correct_map = problem.grade_answers({}) + self.assertEqual(correct_map.get_correctness('1_2_1'), 'incorrect') + class JavascriptResponseTest(ResponseTest): from capa.tests.response_xml_factory import JavascriptResponseXMLFactory