Test multiple choice exercise. Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages are passed to this function. Args: correct (int): the index of the correct answer (should be an instruction). Starts at 1. msgs (list(str)): a list
(state, correct, msgs)
| 810 | |
| 811 | |
| 812 | def has_chosen(state, correct, msgs): |
| 813 | """Test multiple choice exercise. |
| 814 | |
| 815 | Test for a MultipleChoiceExercise. The correct answer (as an integer) and feedback messages |
| 816 | are passed to this function. |
| 817 | |
| 818 | Args: |
| 819 | correct (int): the index of the correct answer (should be an instruction). Starts at 1. |
| 820 | msgs (list(str)): a list containing all feedback messages belonging to each choice of the |
| 821 | student. The list should have the same length as the number of options. |
| 822 | """ |
| 823 | if not issubclass(type(correct), int): |
| 824 | raise InstructorError.from_message( |
| 825 | "Inside `has_chosen()`, the argument `correct` should be an integer." |
| 826 | ) |
| 827 | |
| 828 | student_process = state.student_process |
| 829 | if not isDefinedInProcess(MC_VAR_NAME, student_process): |
| 830 | raise InstructorError.from_message( |
| 831 | "Option not available in the student process" |
| 832 | ) |
| 833 | else: |
| 834 | selected_option = getOptionFromProcess(student_process, MC_VAR_NAME) |
| 835 | if not issubclass(type(selected_option), int): |
| 836 | raise InstructorError.from_message("selected_option should be an integer") |
| 837 | |
| 838 | if selected_option < 1 or correct < 1: |
| 839 | raise InstructorError.from_message( |
| 840 | "selected_option and correct should be greater than zero" |
| 841 | ) |
| 842 | |
| 843 | if selected_option > len(msgs) or correct > len(msgs): |
| 844 | raise InstructorError.from_message( |
| 845 | "there are not enough feedback messages defined" |
| 846 | ) |
| 847 | |
| 848 | feedback_msg = msgs[selected_option - 1] |
| 849 | |
| 850 | state.reporter.success_msg = msgs[correct - 1] |
| 851 | |
| 852 | state.do_test(EqualTest(selected_option, correct, feedback_msg)) |
nothing calls this directly
no test coverage detected