public function test_multichoice() { // Create a multiple choice, single response question. $mc = test_question_maker::make_a_multichoice_single_question(); $mc->penalty = 0.3333333; $this->start_attempt_at_question($mc, 'adaptivenopenalty', 3); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_question_text_expectation($mc), $this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation()); // Process a submit. $this->process_submission(array('answer' => $wrongindex, '-submit' => 1)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(0); $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false), $this->get_contains_incorrect_expectation(), $this->get_does_not_contain_penalty_info_expectation(), $this->get_does_not_contain_total_penalty_expectation()); $this->assertRegExp('/B|C/', $this->quba->get_response_summary($this->slot)); // Process a change of answer to the right one, but not sumbitted. $this->process_submission(array('answer' => $rightindex)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(0); $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false)); $this->assertRegExp('/B|C/', $this->quba->get_response_summary($this->slot)); // Now submit the right answer. $this->process_submission(array('answer' => $rightindex, '-submit' => 1)); // Verify. $this->check_current_state(question_state::$complete); $this->check_current_mark(3); $this->check_current_output($this->get_contains_mark_summary(3), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false), $this->get_contains_correct_expectation(), $this->get_does_not_contain_penalty_info_expectation(), $this->get_does_not_contain_total_penalty_expectation()); $this->assertEquals('A', $this->quba->get_response_summary($this->slot)); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3); $this->check_current_output($this->get_contains_mark_summary(3), $this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false), $this->get_contains_correct_expectation()); // Process a manual comment. $this->manual_grade('Not good enough!', 1, FORMAT_HTML); // Verify. $this->check_current_state(question_state::$mangrpartial); $this->check_current_mark(1); $this->check_current_output($this->get_contains_mark_summary(1), new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); // Now change the correct answer to the question, and regrade. $mc->answers[13]->fraction = -0.33333333; $mc->answers[14]->fraction = 1; // We don't know which "wrong" index we chose above! $mc->answers[15]->fraction = 1; // Therefore, treat answers B and C with the same score. $this->quba->regrade_all_questions(); // Verify. $this->check_current_state(question_state::$mangrpartial); $this->check_current_mark(1); $this->check_current_output($this->get_contains_mark_summary(1), $this->get_contains_partcorrect_expectation()); $autogradedstep = $this->get_step($this->get_step_count() - 3); $this->assertEquals($autogradedstep->get_fraction(), 1, '', 1.0E-7); }
public function test_adaptive_multichoice() { // Create a multiple choice, single response question. $mc = test_question_maker::make_a_multichoice_single_question(); $mc->penalty = 0.3333333; $this->start_attempt_at_question($mc, 'adaptive', 3); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_question_text_expectation($mc), $this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation()); // Process a submit. $this->process_submission(array('answer' => $wrongindex, '-submit' => 1)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(0); $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false), $this->get_contains_incorrect_expectation()); $this->assertPattern('/B|C/', $this->quba->get_response_summary($this->slot)); // Process a change of answer to the right one, but not sumbitted. $this->process_submission(array('answer' => $rightindex)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(0); $this->check_current_output($this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false)); $this->assertPattern('/B|C/', $this->quba->get_response_summary($this->slot)); // Now submit the right answer. $this->process_submission(array('answer' => $rightindex, '-submit' => 1)); // Verify. $this->check_current_state(question_state::$complete); $this->check_current_mark(3 * (1 - $mc->penalty)); $this->check_current_output($this->get_contains_mark_summary(3 * (1 - $mc->penalty)), $this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false), $this->get_contains_correct_expectation(), new PatternExpectation('/' . preg_quote(get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($mc->penalty, $this->displayoptions->markdp))) . '/')); $this->assertEqual('A', $this->quba->get_response_summary($this->slot)); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3 * (1 - $mc->penalty)); $this->check_current_output($this->get_contains_mark_summary(3 * (1 - $mc->penalty)), $this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false), $this->get_contains_correct_expectation()); // Process a manual comment. $this->manual_grade('Not good enough!', 1); // Verify. $this->check_current_state(question_state::$mangrpartial); $this->check_current_mark(1); $this->check_current_output($this->get_contains_mark_summary(1), new PatternExpectation('/' . preg_quote('Not good enough!') . '/')); // Now change the correct answer to the question, and regrade. $mc->answers[13]->fraction = -0.33333333; $mc->answers[15]->fraction = 1; $this->quba->regrade_all_questions(); // Verify. $this->check_current_state(question_state::$mangrpartial); $this->check_current_mark(1); $this->check_current_output($this->get_contains_mark_summary(1), $this->get_contains_partcorrect_expectation()); $autogradedstep = $this->get_step($this->get_step_count() - 2); $this->assertWithinMargin($autogradedstep->get_fraction(), 0, 1.0E-7); }
public function test_get_question_summary() { $mc = test_question_maker::make_a_multichoice_single_question(); $mc->start_attempt(new question_attempt_step(), 1); $qsummary = $mc->get_question_summary(); $this->assertRegExp('/' . preg_quote($mc->questiontext, '/') . '/', $qsummary); foreach ($mc->answers as $answer) { $this->assertRegExp('/' . preg_quote($answer->answer, '/') . '/', $qsummary); } }
public function test_make_html_inline() { // Base class is abstract, so we need to pick one qusetion type to test this method. $mc = test_question_maker::make_a_multichoice_single_question(); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p>')); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog<br /></p>')); $this->assertEquals('Frog<br />Toad', $mc->make_html_inline("<p>Frog</p>\n<p>Toad</p>")); $this->assertEquals('<img src="http://example.com/pic.png" alt="Graph" />', $mc->make_html_inline('<p><img src="http://example.com/pic.png" alt="Graph" /></p>')); $this->assertEquals("Frog<br />XXX <img src='http://example.com/pic.png' alt='Graph' />", $mc->make_html_inline(" <p> Frog </p> \n\r\n <p> XXX <img src='http://example.com/pic.png' alt='Graph' /> </p> ")); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p><p></p>')); $this->assertEquals('Frog<br />†', $mc->make_html_inline('<p>Frog</p><p>†</p>')); }
public function test_deferredfeedback_feedback_multichoice_single() { // Create a multichoice, single question. $mc = test_question_maker::make_a_multichoice_single_question(); $mc->shuffleanswers = false; $mc->answers[14]->fraction = 0.1; // Make one of the choices partially right. $rightindex = 0; $this->start_attempt_at_question($mc, 'deferredfeedback', 3); $this->process_submission(array('answer' => $rightindex)); // Verify. $this->check_current_state(question_state::$complete); $this->check_current_mark(null); $this->check_current_output($this->get_contains_mc_radio_expectation($rightindex, true, true), $this->get_contains_mc_radio_expectation($rightindex + 1, true, false), $this->get_contains_mc_radio_expectation($rightindex + 2, true, false), $this->get_does_not_contain_correctness_expectation(), $this->get_does_not_contain_feedback_expectation()); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3); $this->check_current_output($this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_correct_expectation(), new question_pattern_expectation('/class="r0 correct"/'), new question_pattern_expectation('/class="r1"/')); }
public function test_immediatecbm_feedback_multichoice_wrong_on_finish() { // Create a true-false question with correct answer true. $mc = test_question_maker::make_a_multichoice_single_question(); $this->start_attempt_at_question($mc, 'immediatecbm'); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_question_text_expectation($mc), $this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation()); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; // Save the wrong answer. $this->process_submission(array('answer' => $wrongindex, '-certainty' => 3)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_correctness_expectation()); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedwrong); $this->check_current_mark(-6); $this->check_current_output($this->get_contains_mc_radio_expectation($wrongindex, false, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_incorrect_expectation()); }
public function test_simulated_post_data() { $mc = test_question_maker::make_a_multichoice_single_question(); $mc->shuffleanswers = false; $mc->answers[13]->answer = '<p>A</p>'; $mc->answers[14]->answer = '<p>B</p>'; $mc->answers[15]->answer = '<p>C</p>'; $mc->start_attempt(new question_attempt_step(), 1); $originalresponse = array('answer' => 1); $simulated = $mc->get_student_response_values_for_simulation($originalresponse); $this->assertEquals(array('answer' => 'B'), $simulated); $reconstucted = $mc->prepare_simulated_post_data($simulated); $this->assertEquals($originalresponse, $reconstucted); }
public function test_deferredfeedback_resume_multichoice_single_emptyanswer_first() { // Create a multiple-choice question. $mc = test_question_maker::make_a_multichoice_single_question(); // Attempt it and submit empty. $this->start_attempt_at_question($mc, 'deferredfeedback', 3); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; $this->check_current_state(question_state::$todo); $this->check_output_contains_lang_string('notyetanswered', 'question'); $this->check_current_mark(null); $this->process_submission(array('-submit' => 1)); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gaveup); $this->check_current_mark(null); $this->check_current_output($this->get_contains_mc_radio_expectation(0, false, false), $this->get_contains_mc_radio_expectation(1, false, false), $this->get_contains_mc_radio_expectation(2, false, false), $this->get_contains_general_feedback_expectation($mc)); // Save the old attempt. $oldqa = $this->quba->get_question_attempt($this->slot); // Reinitialise. $this->setUp(); $this->quba->set_preferred_behaviour('deferredfeedback'); $this->slot = $this->quba->add_question($mc, 3); $this->quba->start_question_based_on($this->slot, $oldqa); // Verify. $this->check_current_state(question_state::$todo); $this->check_output_contains_lang_string('notyetanswered', 'question'); $this->check_current_mark(null); $this->check_current_output($this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_correctness_expectation()); // Now get it wrong. $this->process_submission(array('answer' => $wrongindex)); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedwrong); $this->check_current_mark(-1); $this->check_current_output($this->get_contains_mc_radio_expectation($wrongindex, false, true), $this->get_contains_incorrect_expectation()); // Save the old attempt. $oldqa = $this->quba->get_question_attempt($this->slot); // Reinitialise. $this->setUp(); $this->quba->set_preferred_behaviour('deferredfeedback'); $this->slot = $this->quba->add_question($mc, 3); $this->quba->start_question_based_on($this->slot, $oldqa); // Verify. $this->check_current_state(question_state::$complete); $this->check_output_contains_lang_string('notchanged', 'question'); $this->check_current_mark(null); $this->check_current_output($this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_correctness_expectation()); // Now get it right. $this->process_submission(array('answer' => $rightindex)); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3); $this->check_current_output($this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_correct_expectation()); }
public function test_interactive_finish_when_try_again_showing() { // Create a multichoice single question. $mc = test_question_maker::make_a_multichoice_single_question(); $mc->hints = array( new question_hint_with_parts(0, 'This is the first hint.', FORMAT_HTML, false, false), ); $this->start_attempt_at_question($mc, 'interactive'); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_marked_out_of_summary(), $this->get_contains_question_text_expectation($mc), $this->get_contains_mc_radio_expectation(0, true, false), $this->get_contains_mc_radio_expectation(1, true, false), $this->get_contains_mc_radio_expectation(2, true, false), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_tries_remaining_expectation(2), $this->get_no_hint_visible_expectation(), new question_pattern_expectation('/' . preg_quote(get_string('selectone', 'qtype_multichoice'), '/') . '/')); // Submit the wrong answer. $this->process_submission(array('answer' => $wrongindex, '-submit' => 1)); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_marked_out_of_summary(), $this->get_contains_mc_radio_expectation($wrongindex, false, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_submit_button_expectation(false), $this->get_contains_try_again_button_expectation(true), $this->get_does_not_contain_correctness_expectation(), new question_pattern_expectation('/' . preg_quote(get_string('notcomplete', 'qbehaviour_interactive')) . '/'), $this->get_contains_hint_expectation('This is the first hint')); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedwrong); $this->check_current_mark(0); $this->check_current_output( $this->get_contains_mark_summary(0), $this->get_contains_mc_radio_expectation($wrongindex, false, true), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, false, false), $this->get_contains_incorrect_expectation(), $this->get_no_hint_visible_expectation()); }
public function test_deferredcbm_resume_multichoice_single() { // Create a multiple-choice question. $mc = test_question_maker::make_a_multichoice_single_question(); // Attempt it getting it wrong. $this->start_attempt_at_question($mc, 'deferredcbm', 3); $rightindex = $this->get_mc_right_answer_index($mc); $wrongindex = ($rightindex + 1) % 3; $this->process_submission(array('answer' => $wrongindex, '-certainty' => 2)); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedwrong); $this->check_current_mark(-3.3333333); $this->check_current_output( $this->get_contains_mc_radio_expectation($wrongindex, false, true), $this->get_contains_cbm_radio_expectation(2, false, true), $this->get_contains_incorrect_expectation()); $this->assertEquals('A [' . question_cbm::get_string(question_cbm::HIGH) . ']', $this->quba->get_right_answer_summary($this->slot)); $this->assertRegExp('/' . preg_quote($mc->questiontext) . '/', $this->quba->get_question_summary($this->slot)); $this->assertRegExp('/(B|C) \[' . preg_quote(question_cbm::get_string(2)) . '\]/', $this->quba->get_response_summary($this->slot)); // Save the old attempt. $oldqa = $this->quba->get_question_attempt($this->slot); // Reinitialise. $this->setUp(); $this->quba->set_preferred_behaviour('deferredcbm'); $this->slot = $this->quba->add_question($mc, 3); $this->quba->start_question_based_on($this->slot, $oldqa); // Verify. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_mc_radio_expectation($wrongindex, true, true), $this->get_contains_cbm_radio_expectation(2, true, true), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_correctness_expectation()); $this->assertEquals('A [' . question_cbm::get_string(question_cbm::HIGH) . ']', $this->quba->get_right_answer_summary($this->slot)); $this->assertRegExp('/' . preg_quote($mc->questiontext) . '/', $this->quba->get_question_summary($this->slot)); $this->assertNull($this->quba->get_response_summary($this->slot)); // Now get it right. $this->process_submission(array('answer' => $rightindex, '-certainty' => 3)); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3); $this->check_current_output( $this->get_contains_mc_radio_expectation($rightindex, false, true), $this->get_contains_cbm_radio_expectation(3, false, true), $this->get_contains_correct_expectation()); $this->assertRegExp('/(A) \[' . preg_quote(question_cbm::get_string(3)) . '\]/', $this->quba->get_response_summary($this->slot)); }
public function test_make_html_inline() { $mc = test_question_maker::make_a_multichoice_single_question(); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p>')); $this->assertEquals('Frog<br />Toad', $mc->make_html_inline("<p>Frog</p>\n<p>Toad</p>")); $this->assertEquals('<img src="http://example.com/pic.png" alt="Graph" />', $mc->make_html_inline('<p><img src="http://example.com/pic.png" alt="Graph" /></p>')); $this->assertEquals("Frog<br />XXX <img src='http://example.com/pic.png' alt='Graph' />", $mc->make_html_inline(" <p> Frog </p> \n\r\n <p> XXX <img src='http://example.com/pic.png' alt='Graph' /> </p> ")); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p><p></p>')); $this->assertEquals('Frog<br />†', $mc->make_html_inline('<p>Frog</p><p>†</p>')); }