public function test_immediatecbm_feedback_multichoice_right()
 {
     // 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');
     $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_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->assertEqual('A [' . question_cbm::get_string(question_cbm::HIGH) . ']', $this->quba->get_right_answer_summary($this->slot));
     $this->assertPattern('/' . preg_quote($mc->questiontext) . '/', $this->quba->get_question_summary($this->slot));
     $this->assertNull($this->quba->get_response_summary($this->slot));
     // Save the wrong answer.
     $this->process_submission(array('answer' => $wrongindex, '-certainty' => 1));
     // 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(), $this->get_does_not_contain_feedback_expectation());
     // Submit the right answer.
     $this->process_submission(array('answer' => $rightindex, '-certainty' => 2, '-submit' => 1));
     // Verify.
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(2 / 3);
     $this->check_current_output($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 + 1) % 3, false, false), $this->get_contains_correct_expectation());
     $this->assertEqual('A [' . question_cbm::get_string(2) . ']', $this->quba->get_response_summary($this->slot));
     $numsteps = $this->get_step_count();
     // Finish the attempt - should not need to add a new state.
     $this->quba->finish_all_questions();
     // Verify.
     $this->assertEqual($numsteps, $this->get_step_count());
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(2 / 3);
     $this->check_current_output($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 + 1) % 3, false, false), $this->get_contains_correct_expectation());
     // Process a manual comment.
     $this->manual_grade('Not good enough!', 0.5);
     // Verify.
     $this->check_current_state(question_state::$mangrpartial);
     $this->check_current_mark(0.5);
     $this->check_current_output($this->get_contains_partcorrect_expectation(), 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(0.5);
     $this->check_current_output($this->get_contains_partcorrect_expectation());
     $autogradedstep = $this->get_step($this->get_step_count() - 2);
     $this->assertWithinMargin($autogradedstep->get_fraction(), -10 / 9, 1.0E-7);
 }
Example #2
0
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     if (!$options->feedback) {
         return '';
     }
     if ($qa->get_state() == question_state::$gaveup || $qa->get_state() == question_state::$mangaveup) {
         return '';
     }
     $feedback = '';
     if (!$qa->get_last_behaviour_var('certainty') && $qa->get_last_behaviour_var('_assumedcertainty')) {
         $feedback .= html_writer::tag('p', get_string('assumingcertainty', 'qbehaviour_deferredcbm', question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
     }
     return $feedback;
 }
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     if (!$options->feedback) {
         return '';
     }
     if ($qa->get_state() == question_state::$gaveup || $qa->get_state() == question_state::$mangaveup) {
         return '';
     }
     $feedback = '';
     if (!$qa->get_last_behaviour_var('certainty') && $qa->get_last_behaviour_var('_assumedcertainty')) {
         $feedback .= html_writer::tag('p', get_string('assumingcertainty', 'qbehaviour_deferredcbm', question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
     }
     if ($options->marks >= question_display_options::MARK_AND_MAX) {
         $a->rawmark = format_float($qa->get_last_behaviour_var('_rawfraction') * $qa->get_max_mark(), $options->markdp);
         $a->mark = $qa->format_mark($options->markdp);
         $feedback .= html_writer::tag('p', get_string('markadjustment', 'qbehaviour_deferredcbm', $a));
     }
     return $feedback;
 }
Example #4
0
    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));
    }
Example #5
0
 public function get_right_answer_summary() {
     $summary = parent::get_right_answer_summary();
     return $summary . ' [' . question_cbm::get_string(question_cbm::HIGH) . ']';
 }
Example #6
0
 public function test_deferred_cbm_truefalse_default_certainty()
 {
     // Create a true-false question with correct answer true.
     $tf = test_question_maker::make_question('truefalse', 'true');
     $this->start_attempt_at_question($tf, 'deferredcbm', 2);
     // 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_does_not_contain_correctness_expectation(), $this->get_contains_cbm_radio_expectation(1, true, false), $this->get_does_not_contain_feedback_expectation());
     // Submit ansewer with low certainty and finish the attempt.
     $this->process_submission(array('answer' => 1));
     $this->quba->finish_all_questions();
     // Verify.
     $qa = $this->quba->get_question_attempt($this->slot);
     $this->check_current_state(question_state::$gradedright);
     $this->check_current_mark(2);
     $this->check_current_output($this->get_contains_correct_expectation(), $this->get_contains_cbm_radio_expectation(1, false, false), new question_pattern_expectation('/' . preg_quote(get_string('assumingcertainty', 'qbehaviour_deferredcbm', question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))), '/') . '/'));
     $this->assertEquals(get_string('true', 'qtype_truefalse'), $this->quba->get_response_summary($this->slot));
 }