|
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 00017 00029 defined('MOODLE_INTERNAL') || die(); 00030 00031 require_once(dirname(__FILE__) . '/../../../engine/lib.php'); 00032 require_once(dirname(__FILE__) . '/../../../engine/simpletest/helpers.php'); 00033 00034 00041 class qbehaviour_adaptive_walkthrough_test extends qbehaviour_walkthrough_test_base { 00042 protected function get_contains_penalty_info_expectation($penalty) { 00043 $penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive', 00044 format_float($penalty, $this->displayoptions->markdp)); 00045 return new PatternExpectation('/'.preg_quote($penaltyinfo).'/'); 00046 } 00047 00048 protected function get_does_not_contain_penalty_info_expectation() { 00049 $penaltyinfo = get_string('gradingdetailspenalty', 'qbehaviour_adaptive', 'XXXXX'); 00050 $penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo)).'/'; 00051 return new NoPatternExpectation($penaltypattern); 00052 } 00053 00054 protected function get_contains_total_penalty_expectation($penalty) { 00055 $penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', 00056 format_float($penalty, $this->displayoptions->markdp)); 00057 return new PatternExpectation('/'.preg_quote($penaltyinfo).'/'); 00058 } 00059 00060 protected function get_does_not_contain_total_penalty_expectation() { 00061 $penaltyinfo = get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', 'XXXXX'); 00062 $penaltypattern = '/'.str_replace('XXXXX', '\\w*', preg_quote($penaltyinfo)).'/'; 00063 return new NoPatternExpectation($penaltypattern); 00064 } 00065 00066 protected function get_contains_disregarded_info_expectation() { 00067 $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive'); 00068 return new PatternExpectation('/'.preg_quote($penaltyinfo).'/'); 00069 } 00070 00071 protected function get_does_not_contain_disregarded_info_expectation() { 00072 $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive'); 00073 return new NoPatternExpectation('/'.preg_quote($penaltyinfo).'/'); 00074 } 00075 00076 public function test_adaptive_multichoice() { 00077 00078 // Create a multiple choice, single response question. 00079 $mc = test_question_maker::make_a_multichoice_single_question(); 00080 $mc->penalty = 0.3333333; 00081 $this->start_attempt_at_question($mc, 'adaptive', 3); 00082 00083 $rightindex = $this->get_mc_right_answer_index($mc); 00084 $wrongindex = ($rightindex + 1) % 3; 00085 00086 // Check the initial state. 00087 $this->check_current_state(question_state::$todo); 00088 $this->check_current_mark(null); 00089 $this->check_current_output( 00090 $this->get_contains_marked_out_of_summary(), 00091 $this->get_contains_question_text_expectation($mc), 00092 $this->get_contains_mc_radio_expectation(0, true, false), 00093 $this->get_contains_mc_radio_expectation(1, true, false), 00094 $this->get_contains_mc_radio_expectation(2, true, false), 00095 $this->get_contains_submit_button_expectation(true), 00096 $this->get_does_not_contain_feedback_expectation()); 00097 00098 // Process a submit. 00099 $this->process_submission(array('answer' => $wrongindex, '-submit' => 1)); 00100 00101 // Verify. 00102 $this->check_current_state(question_state::$todo); 00103 $this->check_current_mark(0); 00104 $this->check_current_output( 00105 $this->get_contains_mark_summary(0), 00106 $this->get_contains_mc_radio_expectation($wrongindex, true, true), 00107 $this->get_contains_mc_radio_expectation(($wrongindex + 1) % 3, true, false), 00108 $this->get_contains_mc_radio_expectation(($wrongindex + 2) % 3, true, false), 00109 $this->get_contains_incorrect_expectation(), 00110 $this->get_contains_penalty_info_expectation(1.00), 00111 $this->get_does_not_contain_total_penalty_expectation()); 00112 $this->assertPattern('/B|C/', 00113 $this->quba->get_response_summary($this->slot)); 00114 00115 // Process a change of answer to the right one, but not sumbitted. 00116 $this->process_submission(array('answer' => $rightindex)); 00117 00118 // Verify. 00119 $this->check_current_state(question_state::$todo); 00120 $this->check_current_mark(0); 00121 $this->check_current_output( 00122 $this->get_contains_mark_summary(0), 00123 $this->get_contains_mc_radio_expectation($rightindex, true, true), 00124 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), 00125 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false)); 00126 $this->assertPattern('/B|C/', 00127 $this->quba->get_response_summary($this->slot)); 00128 00129 // Now submit the right answer. 00130 $this->process_submission(array('answer' => $rightindex, '-submit' => 1)); 00131 00132 // Verify. 00133 $this->check_current_state(question_state::$complete); 00134 $this->check_current_mark(3 * (1 - $mc->penalty)); 00135 $this->check_current_output( 00136 $this->get_contains_mark_summary(3 * (1 - $mc->penalty)), 00137 $this->get_contains_mc_radio_expectation($rightindex, true, true), 00138 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, true, false), 00139 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, true, false), 00140 $this->get_contains_correct_expectation(), 00141 $this->get_does_not_contain_penalty_info_expectation(), 00142 $this->get_does_not_contain_total_penalty_expectation()); 00143 $this->assertEqual('A', 00144 $this->quba->get_response_summary($this->slot)); 00145 00146 // Finish the attempt. 00147 $this->quba->finish_all_questions(); 00148 00149 // Verify. 00150 $this->check_current_state(question_state::$gradedright); 00151 $this->check_current_mark(3 * (1 - $mc->penalty)); 00152 $this->check_current_output( 00153 $this->get_contains_mark_summary(3 * (1 - $mc->penalty)), 00154 $this->get_contains_mc_radio_expectation($rightindex, false, true), 00155 $this->get_contains_mc_radio_expectation(($rightindex + 1) % 3, false, false), 00156 $this->get_contains_mc_radio_expectation(($rightindex + 2) % 3, false, false), 00157 $this->get_contains_correct_expectation()); 00158 00159 // Process a manual comment. 00160 $this->manual_grade('Not good enough!', 1); 00161 00162 // Verify. 00163 $this->check_current_state(question_state::$mangrpartial); 00164 $this->check_current_mark(1); 00165 $this->check_current_output( 00166 $this->get_contains_mark_summary(1), 00167 new PatternExpectation('/' . preg_quote('Not good enough!') . '/')); 00168 00169 // Now change the correct answer to the question, and regrade. 00170 $mc->answers[13]->fraction = -0.33333333; 00171 $mc->answers[14]->fraction = 1; // We don't know which "wrong" index we chose above! 00172 $mc->answers[15]->fraction = 1; // Therefore, treat answers B and C with the same score. 00173 $this->quba->regrade_all_questions(); 00174 00175 // Verify. 00176 $this->check_current_state(question_state::$mangrpartial); 00177 $this->check_current_mark(1); 00178 $this->check_current_output( 00179 $this->get_contains_mark_summary(1), 00180 $this->get_contains_partcorrect_expectation()); 00181 00182 $autogradedstep = $this->get_step($this->get_step_count() - 2); 00183 $this->assertWithinMargin($autogradedstep->get_fraction(), 1, 0.0000001); 00184 } 00185 00186 public function test_adaptive_multichoice2() { 00187 00188 // Create a multiple choice, multiple response question. 00189 $mc = test_question_maker::make_a_multichoice_multi_question(); 00190 $mc->penalty = 0.3333333; 00191 $mc->shuffleanswers = 0; 00192 $this->start_attempt_at_question($mc, 'adaptive', 2); 00193 00194 // Check the initial state. 00195 $this->check_current_state(question_state::$todo); 00196 $this->check_current_mark(null); 00197 $this->check_current_output( 00198 $this->get_contains_marked_out_of_summary(), 00199 $this->get_contains_question_text_expectation($mc), 00200 $this->get_contains_submit_button_expectation(true), 00201 $this->get_does_not_contain_feedback_expectation()); 00202 00203 // Process a submit. 00204 $this->process_submission(array('choice0' => 1, 'choice2' => 1, '-submit' => 1)); 00205 00206 // Verify. 00207 $this->check_current_state(question_state::$complete); 00208 $this->check_current_mark(2); 00209 $this->check_current_output( 00210 $this->get_contains_mark_summary(2), 00211 $this->get_contains_submit_button_expectation(true), 00212 $this->get_contains_correct_expectation(), 00213 $this->get_does_not_contain_penalty_info_expectation(), 00214 $this->get_does_not_contain_total_penalty_expectation()); 00215 00216 // Save the same correct answer again. Should not do anything. 00217 $numsteps = $this->get_step_count(); 00218 $this->process_submission(array('choice0' => 1, 'choice2' => 1)); 00219 00220 // Verify. 00221 $this->check_step_count($numsteps); 00222 $this->check_current_mark(2); 00223 $this->check_current_state(question_state::$complete); 00224 00225 // Finish the attempt. 00226 $this->quba->finish_all_questions(); 00227 00228 // Verify. 00229 $this->check_step_count($numsteps + 1); 00230 $this->check_current_state(question_state::$gradedright); 00231 $this->check_current_mark(2); 00232 $this->check_current_output( 00233 $this->get_contains_mark_summary(2), 00234 $this->get_contains_submit_button_expectation(false), 00235 $this->get_contains_correct_expectation()); 00236 } 00237 00238 public function test_adaptive_shortanswer_partially_right() { 00239 00240 // Create a short answer question 00241 $sa = test_question_maker::make_question('shortanswer'); 00242 $this->start_attempt_at_question($sa, 'adaptive'); 00243 00244 // Check the initial state. 00245 $this->check_current_state(question_state::$todo); 00246 $this->check_current_mark(null); 00247 $this->check_current_output( 00248 $this->get_contains_marked_out_of_summary(), 00249 $this->get_contains_submit_button_expectation(true), 00250 $this->get_does_not_contain_feedback_expectation()); 00251 00252 // Submit a partially correct answer. 00253 $this->process_submission(array('-submit' => 1, 'answer' => 'toad')); 00254 00255 // Verify. 00256 $this->check_current_state(question_state::$todo); 00257 $this->check_current_mark(0.8); 00258 $this->check_current_output( 00259 $this->get_contains_mark_summary(0.8), 00260 $this->get_contains_submit_button_expectation(true), 00261 $this->get_contains_partcorrect_expectation(), 00262 $this->get_contains_penalty_info_expectation(0.33), 00263 $this->get_does_not_contain_total_penalty_expectation(), 00264 $this->get_does_not_contain_validation_error_expectation()); 00265 00266 // Submit an incorrect answer. 00267 $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee')); 00268 00269 // Verify. 00270 $this->check_current_state(question_state::$todo); 00271 $this->check_current_mark(0.8); 00272 $this->check_current_output( 00273 $this->get_contains_mark_summary(0.8), 00274 $this->get_contains_submit_button_expectation(true), 00275 $this->get_contains_incorrect_expectation(), 00276 $this->get_contains_penalty_info_expectation(0.33), 00277 $this->get_contains_total_penalty_expectation(0.67), 00278 $this->get_does_not_contain_validation_error_expectation()); 00279 00280 // Submit a correct answer. 00281 $this->process_submission(array('-submit' => 1, 'answer' => 'frog')); 00282 00283 // Verify. 00284 $this->check_current_state(question_state::$complete); 00285 $this->check_current_mark(0.8); 00286 $this->check_current_output( 00287 $this->get_contains_mark_summary(0.8), 00288 $this->get_contains_submit_button_expectation(true), 00289 $this->get_contains_correct_expectation(), 00290 $this->get_does_not_contain_penalty_info_expectation(), 00291 $this->get_does_not_contain_total_penalty_expectation(), 00292 $this->get_does_not_contain_validation_error_expectation()); 00293 00294 // Finish the attempt. 00295 $this->quba->finish_all_questions(); 00296 00297 // Verify. 00298 $this->check_current_state(question_state::$gradedright); 00299 $this->check_current_mark(0.8); 00300 $this->check_current_output( 00301 $this->get_contains_mark_summary(0.8), 00302 $this->get_contains_submit_button_expectation(false), 00303 $this->get_contains_correct_expectation(), 00304 $this->get_does_not_contain_validation_error_expectation()); 00305 } 00306 00307 public function test_adaptive_shortanswer_wrong_right_wrong() { 00308 00309 // Create a short answer question 00310 $sa = test_question_maker::make_question('shortanswer'); 00311 $this->start_attempt_at_question($sa, 'adaptive', 6); 00312 00313 // Check the initial state. 00314 $this->check_current_state(question_state::$todo); 00315 $this->check_current_mark(null); 00316 $this->check_current_output( 00317 $this->get_contains_marked_out_of_summary(), 00318 $this->get_contains_submit_button_expectation(true), 00319 $this->get_does_not_contain_feedback_expectation()); 00320 00321 // Submit a wrong answer. 00322 $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus')); 00323 00324 // Verify. 00325 $this->check_current_state(question_state::$todo); 00326 $this->check_current_mark(0); 00327 $this->check_current_output( 00328 $this->get_contains_mark_summary(0), 00329 $this->get_contains_submit_button_expectation(true), 00330 $this->get_contains_incorrect_expectation(), 00331 $this->get_contains_penalty_info_expectation(2.00), 00332 $this->get_does_not_contain_total_penalty_expectation(), 00333 $this->get_does_not_contain_validation_error_expectation()); 00334 00335 // Submit the same wrong answer again. Nothing should change. 00336 $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus')); 00337 00338 // Verify. 00339 $this->check_current_state(question_state::$todo); 00340 $this->check_current_mark(0); 00341 $this->check_current_output( 00342 $this->get_contains_mark_summary(0), 00343 $this->get_contains_submit_button_expectation(true), 00344 $this->get_contains_incorrect_expectation(), 00345 $this->get_contains_penalty_info_expectation(2.00), 00346 $this->get_does_not_contain_total_penalty_expectation(), 00347 $this->get_does_not_contain_validation_error_expectation()); 00348 00349 // Submit a correct answer. 00350 $this->process_submission(array('-submit' => 1, 'answer' => 'frog')); 00351 00352 // Verify. 00353 $this->check_current_state(question_state::$complete); 00354 $this->check_current_mark(4.00); 00355 $this->check_current_output( 00356 $this->get_contains_mark_summary(4.00), 00357 $this->get_contains_submit_button_expectation(true), 00358 $this->get_contains_correct_expectation(), 00359 $this->get_does_not_contain_penalty_info_expectation(), 00360 $this->get_does_not_contain_total_penalty_expectation(), 00361 $this->get_does_not_contain_validation_error_expectation()); 00362 00363 // Submit another incorrect answer. 00364 $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee')); 00365 00366 // Verify. 00367 $this->check_current_state(question_state::$complete); 00368 $this->check_current_mark(4.00); 00369 $this->check_current_output( 00370 $this->get_contains_mark_summary(4.00), 00371 $this->get_contains_submit_button_expectation(true), 00372 $this->get_contains_incorrect_expectation(), 00373 $this->get_does_not_contain_penalty_info_expectation(), 00374 $this->get_does_not_contain_total_penalty_expectation(), 00375 $this->get_does_not_contain_validation_error_expectation()); 00376 00377 // Finish the attempt. 00378 $this->quba->finish_all_questions(); 00379 00380 // Verify. 00381 $this->check_current_state(question_state::$gradedwrong); 00382 $this->check_current_mark(4.00); 00383 $this->check_current_output( 00384 $this->get_contains_mark_summary(4.00), 00385 $this->get_contains_submit_button_expectation(false), 00386 $this->get_contains_incorrect_expectation(), 00387 $this->get_does_not_contain_validation_error_expectation()); 00388 } 00389 00390 public function test_adaptive_shortanswer_invalid_after_complete() { 00391 00392 // Create a short answer question 00393 $sa = test_question_maker::make_question('shortanswer'); 00394 $this->start_attempt_at_question($sa, 'adaptive'); 00395 00396 // Check the initial state. 00397 $this->check_current_state(question_state::$todo); 00398 $this->check_current_mark(null); 00399 $this->check_current_output( 00400 $this->get_contains_marked_out_of_summary(), 00401 $this->get_contains_submit_button_expectation(true), 00402 $this->get_does_not_contain_feedback_expectation()); 00403 00404 // Submit a wrong answer. 00405 $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus')); 00406 00407 // Verify. 00408 $this->check_current_state(question_state::$todo); 00409 $this->check_current_mark(0); 00410 $this->check_current_output( 00411 $this->get_contains_mark_summary(0), 00412 $this->get_contains_submit_button_expectation(true), 00413 $this->get_contains_incorrect_expectation(), 00414 $this->get_contains_penalty_info_expectation(0.33), 00415 $this->get_does_not_contain_total_penalty_expectation(), 00416 $this->get_does_not_contain_validation_error_expectation()); 00417 00418 // Submit a correct answer. 00419 $this->process_submission(array('-submit' => 1, 'answer' => 'frog')); 00420 00421 // Verify. 00422 $this->check_current_state(question_state::$complete); 00423 $this->check_current_mark(0.66666667); 00424 $this->check_current_output( 00425 $this->get_contains_mark_summary(0.67), 00426 $this->get_contains_submit_button_expectation(true), 00427 $this->get_contains_correct_expectation(), 00428 $this->get_does_not_contain_penalty_info_expectation(), 00429 $this->get_does_not_contain_total_penalty_expectation(), 00430 $this->get_does_not_contain_validation_error_expectation()); 00431 00432 // Submit an empty answer. 00433 $this->process_submission(array('-submit' => 1, 'answer' => '')); 00434 00435 // Verify. 00436 $this->check_current_state(question_state::$invalid); 00437 $this->check_current_mark(0.66666667); 00438 $this->check_current_output( 00439 $this->get_contains_mark_summary(0.67), 00440 $this->get_contains_submit_button_expectation(true), 00441 $this->get_does_not_contain_penalty_info_expectation(), 00442 $this->get_does_not_contain_total_penalty_expectation(), 00443 $this->get_contains_validation_error_expectation()); 00444 00445 // Submit another wrong answer. 00446 $this->process_submission(array('-submit' => 1, 'answer' => 'bumblebee')); 00447 00448 // Verify. 00449 $this->check_current_state(question_state::$complete); 00450 $this->check_current_mark(0.66666667); 00451 $this->check_current_output( 00452 $this->get_contains_mark_summary(0.67), 00453 $this->get_contains_submit_button_expectation(true), 00454 $this->get_contains_incorrect_expectation(), 00455 $this->get_does_not_contain_penalty_info_expectation(), 00456 $this->get_does_not_contain_total_penalty_expectation(), 00457 $this->get_does_not_contain_validation_error_expectation()); 00458 00459 // Finish the attempt. 00460 $this->quba->finish_all_questions(); 00461 00462 // Verify. 00463 $this->check_current_state(question_state::$gradedwrong); 00464 $this->check_current_mark(0.66666667); 00465 $this->check_current_output( 00466 $this->get_contains_mark_summary(0.67), 00467 $this->get_contains_submit_button_expectation(false), 00468 $this->get_contains_incorrect_expectation(), 00469 $this->get_does_not_contain_validation_error_expectation()); 00470 } 00471 00472 public function test_adaptive_shortanswer_zero_penalty() { 00473 00474 // Create a short answer question 00475 $sa = test_question_maker::make_question('shortanswer'); 00476 // Disable penalties for this question 00477 $sa->penalty = 0; 00478 $this->start_attempt_at_question($sa, 'adaptive'); 00479 00480 // Check the initial state. 00481 $this->check_current_state(question_state::$todo); 00482 $this->check_current_mark(null); 00483 $this->check_current_output( 00484 $this->get_contains_marked_out_of_summary(), 00485 $this->get_contains_submit_button_expectation(true), 00486 $this->get_does_not_contain_feedback_expectation()); 00487 00488 // Submit a wrong answer. 00489 $this->process_submission(array('-submit' => 1, 'answer' => 'hippopotamus')); 00490 00491 // Verify. 00492 $this->check_current_state(question_state::$todo); 00493 $this->check_current_mark(0); 00494 $this->check_current_output( 00495 $this->get_contains_mark_summary(0), 00496 $this->get_contains_submit_button_expectation(true), 00497 $this->get_contains_incorrect_expectation(), 00498 $this->get_does_not_contain_penalty_info_expectation(), 00499 $this->get_does_not_contain_total_penalty_expectation(), 00500 $this->get_does_not_contain_validation_error_expectation()); 00501 00502 // Submit a correct answer. 00503 $this->process_submission(array('-submit' => 1, 'answer' => 'frog')); 00504 00505 // Verify. 00506 $this->check_current_state(question_state::$complete); 00507 $this->check_current_mark(1.0); 00508 $this->check_current_output( 00509 $this->get_contains_mark_summary(1.0), 00510 $this->get_contains_submit_button_expectation(true), 00511 $this->get_contains_correct_expectation(), 00512 $this->get_does_not_contain_penalty_info_expectation(), 00513 $this->get_does_not_contain_total_penalty_expectation(), 00514 $this->get_does_not_contain_validation_error_expectation()); 00515 00516 // Finish the attempt. 00517 $this->quba->finish_all_questions(); 00518 00519 // Verify. 00520 $this->check_current_state(question_state::$gradedright); 00521 $this->check_current_mark(1.0); 00522 $this->check_current_output( 00523 $this->get_contains_mark_summary(1.0), 00524 $this->get_contains_submit_button_expectation(false), 00525 $this->get_contains_correct_expectation(), 00526 $this->get_does_not_contain_validation_error_expectation()); 00527 } 00528 00529 public function test_adaptive_shortanswer_try_to_submit_blank() { 00530 00531 // Create a short answer question with correct answer true. 00532 $sa = test_question_maker::make_question('shortanswer'); 00533 $this->start_attempt_at_question($sa, 'adaptive'); 00534 00535 // Check the initial state. 00536 $this->check_current_state(question_state::$todo); 00537 $this->check_current_mark(null); 00538 $this->check_current_output( 00539 $this->get_contains_marked_out_of_summary(), 00540 $this->get_contains_submit_button_expectation(true), 00541 $this->get_does_not_contain_feedback_expectation()); 00542 00543 // Submit with blank answer. 00544 $this->process_submission(array('-submit' => 1, 'answer' => '')); 00545 00546 // Verify. 00547 $this->check_current_state(question_state::$invalid); 00548 $this->check_current_mark(null); 00549 $this->check_current_output( 00550 $this->get_contains_marked_out_of_summary(), 00551 $this->get_contains_submit_button_expectation(true), 00552 $this->get_does_not_contain_correctness_expectation(), 00553 $this->get_does_not_contain_penalty_info_expectation(), 00554 $this->get_does_not_contain_total_penalty_expectation(), 00555 $this->get_contains_validation_error_expectation(), 00556 $this->get_contains_disregarded_info_expectation()); 00557 $this->assertNull($this->quba->get_response_summary($this->slot)); 00558 00559 // Now get it wrong. 00560 $this->process_submission(array('-submit' => 1, 'answer' => 'toad')); 00561 00562 // Verify. 00563 $this->check_current_state(question_state::$todo); 00564 $this->check_current_mark(0.8); 00565 $this->check_current_output( 00566 $this->get_contains_mark_summary(0.8), 00567 $this->get_contains_submit_button_expectation(true), 00568 $this->get_contains_partcorrect_expectation(), 00569 $this->get_contains_penalty_info_expectation(0.33), 00570 $this->get_does_not_contain_total_penalty_expectation(), 00571 $this->get_does_not_contain_validation_error_expectation()); 00572 00573 // Now submit blank again. 00574 $this->process_submission(array('-submit' => 1, 'answer' => '')); 00575 00576 // Verify. 00577 $this->check_current_state(question_state::$invalid); 00578 $this->check_current_mark(0.8); 00579 $this->check_current_output( 00580 $this->get_contains_mark_summary(0.8), 00581 $this->get_contains_submit_button_expectation(true), 00582 $this->get_does_not_contain_correctness_expectation(), 00583 $this->get_does_not_contain_penalty_info_expectation(), 00584 $this->get_does_not_contain_total_penalty_expectation(), 00585 $this->get_contains_validation_error_expectation()); 00586 } 00587 00588 public function test_adaptive_numerical() { 00589 00590 // Create a numerical question 00591 $sa = test_question_maker::make_question('numerical', 'pi'); 00592 $this->start_attempt_at_question($sa, 'adaptive'); 00593 00594 // Check the initial state. 00595 $this->check_current_state(question_state::$todo); 00596 $this->check_current_mark(null); 00597 $this->check_current_output( 00598 $this->get_contains_marked_out_of_summary(), 00599 $this->get_contains_submit_button_expectation(true), 00600 $this->get_does_not_contain_feedback_expectation()); 00601 00602 // Submit the correct answer. 00603 $this->process_submission(array('-submit' => 1, 'answer' => '3.14')); 00604 00605 // Verify. 00606 $this->check_current_state(question_state::$complete); 00607 $this->check_current_mark(1); 00608 $this->check_current_output( 00609 $this->get_contains_mark_summary(1), 00610 $this->get_contains_submit_button_expectation(true), 00611 $this->get_contains_correct_expectation(), 00612 $this->get_does_not_contain_penalty_info_expectation(), 00613 $this->get_does_not_contain_total_penalty_expectation(), 00614 $this->get_does_not_contain_validation_error_expectation()); 00615 00616 // Submit an incorrect answer. 00617 $this->process_submission(array('-submit' => 1, 'answer' => '-5')); 00618 00619 // Verify. 00620 $this->check_current_state(question_state::$complete); 00621 $this->check_current_mark(1); 00622 $this->check_current_output( 00623 $this->get_contains_mark_summary(1), 00624 $this->get_contains_submit_button_expectation(true), 00625 $this->get_contains_incorrect_expectation(), 00626 $this->get_does_not_contain_penalty_info_expectation(), 00627 $this->get_does_not_contain_total_penalty_expectation(), 00628 $this->get_does_not_contain_validation_error_expectation()); 00629 00630 // Finish the attempt. 00631 $this->quba->finish_all_questions(); 00632 00633 // Verify. 00634 $this->check_current_state(question_state::$gradedwrong); 00635 $this->check_current_mark(1); 00636 $this->check_current_output( 00637 $this->get_contains_mark_summary(1), 00638 $this->get_contains_submit_button_expectation(false), 00639 $this->get_contains_incorrect_expectation(), 00640 $this->get_does_not_contain_validation_error_expectation()); 00641 } 00642 00643 public function test_adaptive_numerical_invalid() { 00644 00645 // Create a numerical question 00646 $numq = test_question_maker::make_question('numerical', 'pi'); 00647 $numq->penalty = 0.1; 00648 $this->start_attempt_at_question($numq, 'adaptive'); 00649 00650 // Check the initial state. 00651 $this->check_current_state(question_state::$todo); 00652 $this->check_current_mark(null); 00653 $this->check_current_output( 00654 $this->get_contains_marked_out_of_summary(), 00655 $this->get_contains_submit_button_expectation(true), 00656 $this->get_does_not_contain_feedback_expectation()); 00657 00658 // Submit a non-numerical answer. 00659 $this->process_submission(array('-submit' => 1, 'answer' => 'Pi')); 00660 00661 // Verify. 00662 $this->check_current_state(question_state::$invalid); 00663 $this->check_current_mark(null); 00664 $this->check_current_output( 00665 $this->get_contains_marked_out_of_summary(1), 00666 $this->get_contains_submit_button_expectation(true), 00667 $this->get_does_not_contain_correctness_expectation(), 00668 $this->get_does_not_contain_penalty_info_expectation(), 00669 $this->get_does_not_contain_total_penalty_expectation(), 00670 $this->get_contains_validation_error_expectation(), 00671 $this->get_contains_disregarded_info_expectation()); 00672 00673 // Submit an incorrect answer. 00674 $this->process_submission(array('-submit' => 1, 'answer' => '-5')); 00675 00676 // Verify. 00677 $this->check_current_state(question_state::$todo); 00678 $this->check_current_mark(0); 00679 $this->check_current_output( 00680 $this->get_contains_mark_summary(0), 00681 $this->get_contains_submit_button_expectation(true), 00682 $this->get_contains_incorrect_expectation(), 00683 $this->get_contains_penalty_info_expectation(0.1), 00684 $this->get_does_not_contain_total_penalty_expectation(), 00685 $this->get_does_not_contain_validation_error_expectation(), 00686 $this->get_does_not_contain_disregarded_info_expectation()); 00687 00688 // Submit another non-numerical answer. 00689 $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2')); 00690 00691 // Verify. 00692 $this->check_current_state(question_state::$invalid); 00693 $this->check_current_mark(0); 00694 $this->check_current_output( 00695 $this->get_contains_mark_summary(0), 00696 $this->get_contains_submit_button_expectation(true), 00697 $this->get_does_not_contain_correctness_expectation(), 00698 $this->get_does_not_contain_penalty_info_expectation(), 00699 $this->get_does_not_contain_total_penalty_expectation(), 00700 $this->get_contains_validation_error_expectation(), 00701 $this->get_contains_disregarded_info_expectation()); 00702 00703 // Submit the correct answer. 00704 $this->process_submission(array('-submit' => 1, 'answer' => '3.14')); 00705 00706 // Verify. 00707 $this->check_current_state(question_state::$complete); 00708 $this->check_current_mark(0.9); 00709 $this->check_current_output( 00710 $this->get_contains_mark_summary(0.9), 00711 $this->get_contains_submit_button_expectation(true), 00712 $this->get_contains_correct_expectation(), 00713 $this->get_does_not_contain_penalty_info_expectation(), 00714 $this->get_does_not_contain_total_penalty_expectation(), 00715 $this->get_does_not_contain_validation_error_expectation(), 00716 $this->get_does_not_contain_disregarded_info_expectation()); 00717 00718 // Submit another non-numerical answer. 00719 $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3')); 00720 00721 // Verify. 00722 $this->check_current_state(question_state::$invalid); 00723 $this->check_current_mark(0.9); 00724 $this->check_current_output( 00725 $this->get_contains_mark_summary(0.9), 00726 $this->get_contains_submit_button_expectation(true), 00727 $this->get_does_not_contain_correctness_expectation(), 00728 $this->get_does_not_contain_penalty_info_expectation(), 00729 $this->get_does_not_contain_total_penalty_expectation(), 00730 $this->get_contains_validation_error_expectation(), 00731 $this->get_contains_disregarded_info_expectation()); 00732 00733 // Finish the attempt. 00734 $this->quba->finish_all_questions(); 00735 00736 // Verify. 00737 $this->check_current_state(question_state::$gradedwrong); 00738 $this->check_current_mark(0.9); 00739 $this->check_current_output( 00740 $this->get_contains_mark_summary(0.9), 00741 $this->get_contains_submit_button_expectation(false), 00742 $this->get_contains_incorrect_expectation(), 00743 $this->get_does_not_contain_validation_error_expectation(), 00744 $this->get_does_not_contain_disregarded_info_expectation()); 00745 } 00746 }