|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 require_once(dirname(__FILE__) . '/../../../engine/lib.php'); 00031 require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php'); 00032 00033 00040 class qbehaviour_deferredcbm_walkthrough_test extends qbehaviour_walkthrough_test_base { 00041 public function test_deferred_cbm_truefalse_high_certainty() { 00042 00043 // Create a true-false question with correct answer true. 00044 $tf = test_question_maker::make_question('truefalse', 'true'); 00045 $this->start_attempt_at_question($tf, 'deferredcbm', 2); 00046 00047 // Verify. 00048 $this->check_current_state(question_state::$todo); 00049 $this->check_current_mark(null); 00050 $this->check_current_output( 00051 $this->get_contains_question_text_expectation($tf), 00052 $this->get_contains_tf_true_radio_expectation(true, false), 00053 $this->get_contains_tf_false_radio_expectation(true, false), 00054 $this->get_contains_cbm_radio_expectation(1, true, false), 00055 $this->get_contains_cbm_radio_expectation(2, true, false), 00056 $this->get_contains_cbm_radio_expectation(3, true, false), 00057 $this->get_does_not_contain_feedback_expectation()); 00058 00059 // Process the data extracted for this question. 00060 $this->process_submission(array('answer' => 1, '-certainty' => 3)); 00061 00062 // Verify. 00063 $this->check_current_state(question_state::$complete); 00064 $this->check_current_mark(null); 00065 $this->check_current_output( 00066 $this->get_contains_tf_true_radio_expectation(true, true), 00067 $this->get_contains_cbm_radio_expectation(3, true, true), 00068 $this->get_does_not_contain_correctness_expectation(), 00069 $this->get_does_not_contain_feedback_expectation()); 00070 00071 // Process the same data again, check it does not create a new step. 00072 $numsteps = $this->get_step_count(); 00073 $this->process_submission(array('answer' => 1, '-certainty' => 3)); 00074 $this->check_step_count($numsteps); 00075 00076 // Process different data, check it creates a new step. 00077 $this->process_submission(array('answer' => 1, '-certainty' => 1)); 00078 $this->check_step_count($numsteps + 1); 00079 $this->check_current_state(question_state::$complete); 00080 00081 // Change back, check it creates a new step. 00082 $this->process_submission(array('answer' => 1, '-certainty' => 3)); 00083 $this->check_step_count($numsteps + 2); 00084 00085 // Finish the attempt. 00086 $this->quba->finish_all_questions(); 00087 00088 // Verify. 00089 $this->check_current_state(question_state::$gradedright); 00090 $this->check_current_mark(2); 00091 $this->check_current_output( 00092 $this->get_contains_tf_true_radio_expectation(false, true), 00093 $this->get_contains_cbm_radio_expectation(3, false, true), 00094 $this->get_contains_correct_expectation()); 00095 00096 // Process a manual comment. 00097 $this->manual_grade('Not good enough!', 1); 00098 00099 // Verify. 00100 $this->check_current_state(question_state::$mangrpartial); 00101 $this->check_current_mark(1); 00102 $this->check_current_output(new PatternExpectation('/' . 00103 preg_quote('Not good enough!') . '/')); 00104 00105 // Now change the correct answer to the question, and regrade. 00106 $tf->rightanswer = false; 00107 $this->quba->regrade_all_questions(); 00108 00109 // Verify. 00110 $this->check_current_state(question_state::$mangrpartial); 00111 $this->check_current_mark(1); 00112 $autogradedstep = $this->get_step($this->get_step_count() - 2); 00113 $this->assertWithinMargin($autogradedstep->get_fraction(), -2, 0.0000001); 00114 } 00115 00116 public function test_deferred_cbm_truefalse_low_certainty() { 00117 00118 // Create a true-false question with correct answer true. 00119 $tf = test_question_maker::make_question('truefalse', 'true'); 00120 $this->start_attempt_at_question($tf, 'deferredcbm', 2); 00121 00122 // Verify. 00123 $this->check_current_state(question_state::$todo); 00124 $this->check_current_mark(null); 00125 $this->check_current_output( 00126 $this->get_does_not_contain_correctness_expectation(), 00127 $this->get_contains_cbm_radio_expectation(1, true, false), 00128 $this->get_does_not_contain_feedback_expectation()); 00129 00130 // Submit ansewer with low certainty. 00131 $this->process_submission(array('answer' => 1, '-certainty' => 1)); 00132 00133 // Verify. 00134 $this->check_current_state(question_state::$complete); 00135 $this->check_current_mark(null); 00136 $this->check_current_output($this->get_does_not_contain_correctness_expectation(), 00137 $this->get_contains_cbm_radio_expectation(1, true, true), 00138 $this->get_does_not_contain_feedback_expectation()); 00139 00140 // Finish the attempt. 00141 $this->quba->finish_all_questions(); 00142 00143 // Verify. 00144 $this->check_current_state(question_state::$gradedright); 00145 $this->check_current_mark(0.6666667); 00146 $this->check_current_output($this->get_contains_correct_expectation(), 00147 $this->get_contains_cbm_radio_expectation(1, false, true)); 00148 $this->assertEqual(get_string('true', 'qtype_truefalse') . ' [' . 00149 question_cbm::get_string(1) . ']', 00150 $this->quba->get_response_summary($this->slot)); 00151 } 00152 00153 public function test_deferred_cbm_truefalse_default_certainty() { 00154 00155 // Create a true-false question with correct answer true. 00156 $tf = test_question_maker::make_question('truefalse', 'true'); 00157 $this->start_attempt_at_question($tf, 'deferredcbm', 2); 00158 00159 // Verify. 00160 $this->check_current_state(question_state::$todo); 00161 $this->check_current_mark(null); 00162 $this->check_current_output( 00163 $this->get_does_not_contain_correctness_expectation(), 00164 $this->get_contains_cbm_radio_expectation(1, true, false), 00165 $this->get_does_not_contain_feedback_expectation()); 00166 00167 // Submit ansewer with low certainty and finish the attempt. 00168 $this->process_submission(array('answer' => 1)); 00169 $this->quba->finish_all_questions(); 00170 00171 // Verify. 00172 $qa = $this->quba->get_question_attempt($this->slot); 00173 $this->check_current_state(question_state::$gradedright); 00174 $this->check_current_mark(0.6666667); 00175 $this->check_current_output($this->get_contains_correct_expectation(), 00176 $this->get_contains_cbm_radio_expectation(1, false, false), 00177 new PatternExpectation('/' . preg_quote( 00178 get_string('assumingcertainty', 'qbehaviour_deferredcbm', 00179 question_cbm::get_string( 00180 $qa->get_last_behaviour_var('_assumedcertainty')))) . '/')); 00181 $this->assertEqual(get_string('true', 'qtype_truefalse'), 00182 $this->quba->get_response_summary($this->slot)); 00183 } 00184 00185 public function test_deferredcbm_resume_multichoice_single() { 00186 00187 // Create a multiple-choice question. 00188 $mc = test_question_maker::make_a_multichoice_single_question(); 00189 00190 // Attempt it getting it wrong. 00191 $this->start_attempt_at_question($mc, 'deferredcbm', 3); 00192 $rightindex = $this->get_mc_right_answer_index($mc); 00193 $wrongindex = ($rightindex + 1) % 3; 00194 $this->process_submission(array('answer' => $wrongindex, '-certainty' => 2)); 00195 $this->quba->finish_all_questions(); 00196 00197 // Verify. 00198 $this->check_current_state(question_state::$gradedwrong); 00199 $this->check_current_mark(-3.3333333); 00200 $this->check_current_output( 00201 $this->get_contains_mc_radio_expectation($wrongindex, false, true), 00202 $this->get_contains_cbm_radio_expectation(2, false, true), 00203 $this->get_contains_incorrect_expectation()); 00204 $this->assertEqual('A [' . question_cbm::get_string(question_cbm::HIGH) . ']', 00205 $this->quba->get_right_answer_summary($this->slot)); 00206 $this->assertPattern('/' . preg_quote($mc->questiontext) . '/', 00207 $this->quba->get_question_summary($this->slot)); 00208 $this->assertPattern('/(B|C) \[' . preg_quote(question_cbm::get_string(2)) . '\]/', 00209 $this->quba->get_response_summary($this->slot)); 00210 00211 // Save the old attempt. 00212 $oldqa = $this->quba->get_question_attempt($this->slot); 00213 00214 // Reinitialise. 00215 $this->setUp(); 00216 $this->quba->set_preferred_behaviour('deferredcbm'); 00217 $this->slot = $this->quba->add_question($mc, 3); 00218 $this->quba->start_question_based_on($this->slot, $oldqa); 00219 00220 // Verify. 00221 $this->check_current_state(question_state::$todo); 00222 $this->check_current_mark(null); 00223 $this->check_current_output( 00224 $this->get_contains_mc_radio_expectation($wrongindex, true, true), 00225 $this->get_contains_cbm_radio_expectation(2, true, true), 00226 $this->get_does_not_contain_feedback_expectation(), 00227 $this->get_does_not_contain_correctness_expectation()); 00228 $this->assertEqual('A [' . question_cbm::get_string(question_cbm::HIGH) . ']', 00229 $this->quba->get_right_answer_summary($this->slot)); 00230 $this->assertPattern('/' . preg_quote($mc->questiontext) . '/', 00231 $this->quba->get_question_summary($this->slot)); 00232 $this->assertNull($this->quba->get_response_summary($this->slot)); 00233 00234 // Now get it right. 00235 $this->process_submission(array('answer' => $rightindex, '-certainty' => 3)); 00236 $this->quba->finish_all_questions(); 00237 00238 // Verify. 00239 $this->check_current_state(question_state::$gradedright); 00240 $this->check_current_mark(3); 00241 $this->check_current_output( 00242 $this->get_contains_mc_radio_expectation($rightindex, false, true), 00243 $this->get_contains_cbm_radio_expectation(3, false, true), 00244 $this->get_contains_correct_expectation()); 00245 $this->assertPattern('/(A) \[' . preg_quote(question_cbm::get_string(3)) . '\]/', 00246 $this->quba->get_response_summary($this->slot)); 00247 } 00248 00249 public function test_deferred_cbm_truefalse_no_certainty_feedback_when_not_answered() { 00250 00251 // Create a true-false question with correct answer true. 00252 $tf = test_question_maker::make_question('truefalse', 'true'); 00253 $this->start_attempt_at_question($tf, 'deferredcbm', 2); 00254 00255 // Verify. 00256 $this->check_current_state(question_state::$todo); 00257 $this->check_current_mark(null); 00258 $this->check_current_output( 00259 $this->get_does_not_contain_correctness_expectation(), 00260 $this->get_contains_cbm_radio_expectation(1, true, false), 00261 $this->get_does_not_contain_feedback_expectation()); 00262 00263 // Finish without answering. 00264 $this->quba->finish_all_questions(); 00265 00266 // Verify. 00267 $this->check_current_state(question_state::$gaveup); 00268 $this->check_current_mark(null); 00269 $this->check_current_output( 00270 new NoPatternExpectation('/class=\"im-feedback/')); 00271 } 00272 }