public function test_adjust_fraction() { $this->assertEquals(0, question_cbm::adjust_fraction(0, question_cbm::LOW), '', 0.0000001); $this->assertEquals(-2/3, question_cbm::adjust_fraction(0, question_cbm::MED), '', 0.0000001); $this->assertEquals(-2, question_cbm::adjust_fraction(0, question_cbm::HIGH), '', 0.0000001); $this->assertEquals(1/3, question_cbm::adjust_fraction(1, question_cbm::LOW), '', 0.0000001); $this->assertEquals(2/3, question_cbm::adjust_fraction(1, question_cbm::MED), '', 0.0000001); $this->assertEquals(1, question_cbm::adjust_fraction(1, question_cbm::HIGH), '', 0.0000001); }
public function test_adjust_fraction() { $this->assertWithinMargin(0, question_cbm::adjust_fraction(0, question_cbm::LOW), 1.0E-7); $this->assertWithinMargin(-2 / 3, question_cbm::adjust_fraction(0, question_cbm::MED), 1.0E-7); $this->assertWithinMargin(-2, question_cbm::adjust_fraction(0, question_cbm::HIGH), 1.0E-7); $this->assertWithinMargin(1 / 3, question_cbm::adjust_fraction(1, question_cbm::LOW), 1.0E-7); $this->assertWithinMargin(2 / 3, question_cbm::adjust_fraction(1, question_cbm::MED), 1.0E-7); $this->assertWithinMargin(1, question_cbm::adjust_fraction(1, question_cbm::HIGH), 1.0E-7); }
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->assertEquals('A [' . question_cbm::get_short_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)); // 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); $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->assertEquals('A [' . question_cbm::get_short_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->assertEquals($numsteps, $this->get_step_count()); $this->check_current_state(question_state::$gradedright); $this->check_current_mark(2); $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, FORMAT_HTML); // Verify. $this->check_current_state(question_state::$mangrpartial); $this->check_current_mark(0.5); $this->check_current_output($this->get_contains_partcorrect_expectation(), 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[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->assertEquals($autogradedstep->get_fraction(), -2, '', 1.0E-7); }
public function test_adjust_fraction() { $this->assertEquals(1, question_cbm::adjust_fraction(1, question_cbm::LOW), '', 1.0E-7); $this->assertEquals(2, question_cbm::adjust_fraction(1, question_cbm::MED), '', 1.0E-7); $this->assertEquals(3, question_cbm::adjust_fraction(1, question_cbm::HIGH), '', 1.0E-7); $this->assertEquals(0, question_cbm::adjust_fraction(0, question_cbm::LOW), '', 1.0E-7); $this->assertEquals(-2, question_cbm::adjust_fraction(0, question_cbm::MED), '', 1.0E-7); $this->assertEquals(-6, question_cbm::adjust_fraction(0, question_cbm::HIGH), '', 1.0E-7); $this->assertEquals(0.5, question_cbm::adjust_fraction(0.5, question_cbm::LOW), '', 1.0E-7); $this->assertEquals(1, question_cbm::adjust_fraction(0.5, question_cbm::MED), '', 1.0E-7); $this->assertEquals(1.5, question_cbm::adjust_fraction(0.5, question_cbm::HIGH), '', 1.0E-7); $this->assertEquals(0, question_cbm::adjust_fraction(-0.25, question_cbm::LOW), '', 1.0E-7); $this->assertEquals(-2, question_cbm::adjust_fraction(-0.25, question_cbm::MED), '', 1.0E-7); $this->assertEquals(-6, question_cbm::adjust_fraction(-0.25, question_cbm::HIGH), '', 1.0E-7); }
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; }
public function calculate_bonus($total, $accuracy) { $expectedforaccuracy = max($accuracy * question_cbm::adjust_fraction(1, question_cbm::LOW) + (1 - $accuracy) * question_cbm::adjust_fraction(0, question_cbm::LOW), $accuracy * question_cbm::adjust_fraction(1, question_cbm::MED) + (1 - $accuracy) * question_cbm::adjust_fraction(0, question_cbm::MED), $accuracy * question_cbm::adjust_fraction(1, question_cbm::HIGH) + (1 - $accuracy) * question_cbm::adjust_fraction(0, question_cbm::HIGH)); // The constant 0.1 here is determinted empirically from looking at lots // for CBM quiz results. See www.ucl.ac.uk/~ucgbarg/tea/IUPS_2013a.pdf. // It approximately maximises the reliability of accuracy + bonus. return 0.1 * ($total - $expectedforaccuracy); }
public static function adjust_random_guess_score($fraction) { return question_cbm::adjust_fraction($fraction, question_cbm::default_certainty()); }
public function test_test0_no_validation_required() { // Account for the changes in Moodle 2.6. if (question_cbm::adjust_fraction(1, question_cbm::HIGH) > 2) { // Moodle 2.6+. $outof = 1; } else { // Moodle 2.5-. $outof = 3; } // Create a stack question - we use test0, then replace the input with // a dropdown, to get a question that does not require validation. $q = test_question_maker::make_question('stack', 'test0'); $q->inputs['ans1'] = stack_input_factory::make('dropdown', 'ans1', '2', array('ddl_values' => '1,2')); $this->start_attempt_at_question($q, 'deferredcbm', $outof); // Check the right behaviour is used. $this->assertEquals('deferredcbm', $this->quba->get_question_attempt($this->slot)->get_behaviour_name()); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->render(); $this->check_output_does_not_contain_input_validation(); $this->check_output_does_not_contain_prt_feedback(); $this->check_output_does_not_contain_stray_placeholders(); $this->check_current_output($this->get_contains_select_expectation('ans1', array('' => stack_string('notanswered'), '1' => '1', '2' => '2'), null, true), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_num_parts_correct(), $this->get_no_hint_visible_expectation()); // Save a correct response, medium certainty. $this->process_submission(array('ans1' => '2', '-certainty' => 2)); $this->check_current_state(question_state::$complete); $this->check_current_mark(null); $this->render(); $this->check_output_does_not_contain_input_validation(); $this->check_output_does_not_contain_prt_feedback(); $this->check_output_does_not_contain_stray_placeholders(); $this->check_current_output($this->get_contains_select_expectation('ans1', array('' => stack_string('notanswered'), '1' => '1', '2' => '2'), '2', true), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_num_parts_correct(), $this->get_no_hint_visible_expectation()); // Submit all and finish. $this->quba->finish_all_questions(); $this->check_current_state(question_state::$gradedright); $this->check_current_mark(2); $this->render(); $this->check_output_does_not_contain_input_validation(); $this->check_output_contains_prt_feedback('firsttree'); $this->check_output_does_not_contain_stray_placeholders(); $this->check_current_output($this->get_contains_select_expectation('ans1', array('' => stack_string('notanswered'), '1' => '1', '2' => '2'), '2', false), $this->get_does_not_contain_num_parts_correct(), $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 summarise_action(question_attempt_step $step) { $summary = parent::summarise_action($step); if ($step->has_behaviour_var('certainty')) { $summary = question_cbm::summary_with_certainty($summary, $step->get_behaviour_var('certainty')); } return $summary; }
public function marked_out_of_max(question_attempt $qa, core_question_renderer $qoutput, question_display_options $options) { return get_string('basemark', 'qbehaviour_deferredcbm', $qa->format_fraction_as_mark(question_cbm::adjust_fraction(1, question_cbm::default_certainty()), $options->markdp)); }