Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-30031 Adaptive question behaviour: ignore invalid answers without…

… penalty
  • Loading branch information...
commit 096c30165b18ebd4f4c5c03f3d2aa31ca161450a 1 parent 2117dcb
Henning Bostelmann bostelm authored
2  question/behaviour/adaptive/behaviour.php
@@ -119,7 +119,7 @@ public function process_submit(question_attempt_pending_step $pendingstep) {
119 119 $status = $this->process_save($pendingstep);
120 120
121 121 $response = $pendingstep->get_qt_data();
122   - if (!$this->question->is_gradable_response($response)) {
  122 + if (!$this->question->is_complete_response($response)) {
123 123 $pendingstep->set_state(question_state::$invalid);
124 124 if ($this->qa->get_state() != question_state::$invalid) {
125 125 $status = question_attempt::KEEP;
1  question/behaviour/adaptive/lang/en/qbehaviour_adaptive.php
@@ -23,6 +23,7 @@
23 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 24 */
25 25
  26 +$string['disregardedwithoutpenalty'] = 'The submission was invalid, and has been disregarded without penalty.';
26 27 $string['gradingdetails'] = 'Marks for this submission: {$a->raw}/{$a->max}.';
27 28 $string['gradingdetailsadjustment'] = 'Accounting for previous tries, this gives <strong>{$a->cur}/{$a->max}</strong>.';
28 29 $string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.';
18 question/behaviour/adaptive/renderer.php
@@ -42,6 +42,16 @@ public function controls(question_attempt $qa, question_display_options $options
42 42 }
43 43
44 44 public function feedback(question_attempt $qa, question_display_options $options) {
  45 + if ($qa->get_state() == question_state::$invalid) {
  46 + // If the latest answer was invalid, display an informative message
  47 + $output = '';
  48 + $info = $this->disregarded_info();
  49 + if ($info) {
  50 + $output = html_writer::tag('div', $info, array('class' => 'gradingdetails'));
  51 + }
  52 + return $output;
  53 + }
  54 +
45 55 // Try to find the last graded step.
46 56
47 57 $gradedstep = $qa->get_behaviour()->get_graded_step($qa);
@@ -116,4 +126,12 @@ protected function penalty_info(question_attempt $qa, $mark,
116 126
117 127 return $output;
118 128 }
  129 +
  130 + /**
  131 + * Display information about a disregarded (incomplete) response.
  132 + */
  133 + protected function disregarded_info() {
  134 + return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  135 + }
  136 +
119 137 }
119 question/behaviour/adaptive/simpletest/testwalkthrough.php
@@ -63,6 +63,16 @@ protected function get_does_not_contain_total_penalty_expectation() {
63 63 return new NoPatternExpectation($penaltypattern);
64 64 }
65 65
  66 + protected function get_contains_disregarded_info_expectation() {
  67 + $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  68 + return new PatternExpectation('/'.preg_quote($penaltyinfo).'/');
  69 + }
  70 +
  71 + protected function get_does_not_contain_disregarded_info_expectation() {
  72 + $penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
  73 + return new NoPatternExpectation('/'.preg_quote($penaltyinfo).'/');
  74 + }
  75 +
66 76 public function test_adaptive_multichoice() {
67 77
68 78 // Create a multiple choice, single response question.
@@ -542,7 +552,8 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
542 552 $this->get_does_not_contain_correctness_expectation(),
543 553 $this->get_does_not_contain_penalty_info_expectation(),
544 554 $this->get_does_not_contain_total_penalty_expectation(),
545   - $this->get_contains_validation_error_expectation());
  555 + $this->get_contains_validation_error_expectation(),
  556 + $this->get_contains_disregarded_info_expectation());
546 557 $this->assertNull($this->quba->get_response_summary($this->slot));
547 558
548 559 // Now get it wrong.
@@ -568,7 +579,7 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
568 579 $this->check_current_output(
569 580 $this->get_contains_mark_summary(0.8),
570 581 $this->get_contains_submit_button_expectation(true),
571   - $this->get_contains_partcorrect_expectation(),
  582 + $this->get_does_not_contain_correctness_expectation(),
572 583 $this->get_does_not_contain_penalty_info_expectation(),
573 584 $this->get_does_not_contain_total_penalty_expectation(),
574 585 $this->get_contains_validation_error_expectation());
@@ -628,4 +639,108 @@ public function test_adaptive_numerical() {
628 639 $this->get_contains_incorrect_expectation(),
629 640 $this->get_does_not_contain_validation_error_expectation());
630 641 }
  642 +
  643 + public function test_adaptive_numerical_invalid() {
  644 +
  645 + // Create a numerical question
  646 + $numq = test_question_maker::make_question('numerical', 'pi');
  647 + $numq->penalty = 0.1;
  648 + $this->start_attempt_at_question($numq, 'adaptive');
  649 +
  650 + // Check the initial state.
  651 + $this->check_current_state(question_state::$todo);
  652 + $this->check_current_mark(null);
  653 + $this->check_current_output(
  654 + $this->get_contains_marked_out_of_summary(),
  655 + $this->get_contains_submit_button_expectation(true),
  656 + $this->get_does_not_contain_feedback_expectation());
  657 +
  658 + // Submit a non-numerical answer.
  659 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
  660 +
  661 + // Verify.
  662 + $this->check_current_state(question_state::$invalid);
  663 + $this->check_current_mark(null);
  664 + $this->check_current_output(
  665 + $this->get_contains_marked_out_of_summary(1),
  666 + $this->get_contains_submit_button_expectation(true),
  667 + $this->get_does_not_contain_correctness_expectation(),
  668 + $this->get_does_not_contain_penalty_info_expectation(),
  669 + $this->get_does_not_contain_total_penalty_expectation(),
  670 + $this->get_contains_validation_error_expectation(),
  671 + $this->get_contains_disregarded_info_expectation());
  672 +
  673 + // Submit an incorrect answer.
  674 + $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
  675 +
  676 + // Verify.
  677 + $this->check_current_state(question_state::$todo);
  678 + $this->check_current_mark(0);
  679 + $this->check_current_output(
  680 + $this->get_contains_mark_summary(0),
  681 + $this->get_contains_submit_button_expectation(true),
  682 + $this->get_contains_incorrect_expectation(),
  683 + $this->get_contains_penalty_info_expectation(0.1),
  684 + $this->get_does_not_contain_total_penalty_expectation(),
  685 + $this->get_does_not_contain_validation_error_expectation(),
  686 + $this->get_does_not_contain_disregarded_info_expectation());
  687 +
  688 + // Submit another non-numerical answer.
  689 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
  690 +
  691 + // Verify.
  692 + $this->check_current_state(question_state::$invalid);
  693 + $this->check_current_mark(0);
  694 + $this->check_current_output(
  695 + $this->get_contains_mark_summary(0),
  696 + $this->get_contains_submit_button_expectation(true),
  697 + $this->get_does_not_contain_correctness_expectation(),
  698 + $this->get_does_not_contain_penalty_info_expectation(),
  699 + $this->get_does_not_contain_total_penalty_expectation(),
  700 + $this->get_contains_validation_error_expectation(),
  701 + $this->get_contains_disregarded_info_expectation());
  702 +
  703 + // Submit the correct answer.
  704 + $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
  705 +
  706 + // Verify.
  707 + $this->check_current_state(question_state::$complete);
  708 + $this->check_current_mark(0.9);
  709 + $this->check_current_output(
  710 + $this->get_contains_mark_summary(0.9),
  711 + $this->get_contains_submit_button_expectation(true),
  712 + $this->get_contains_correct_expectation(),
  713 + $this->get_does_not_contain_penalty_info_expectation(),
  714 + $this->get_does_not_contain_total_penalty_expectation(),
  715 + $this->get_does_not_contain_validation_error_expectation(),
  716 + $this->get_does_not_contain_disregarded_info_expectation());
  717 +
  718 + // Submit another non-numerical answer.
  719 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
  720 +
  721 + // Verify.
  722 + $this->check_current_state(question_state::$invalid);
  723 + $this->check_current_mark(0.9);
  724 + $this->check_current_output(
  725 + $this->get_contains_mark_summary(0.9),
  726 + $this->get_contains_submit_button_expectation(true),
  727 + $this->get_does_not_contain_correctness_expectation(),
  728 + $this->get_does_not_contain_penalty_info_expectation(),
  729 + $this->get_does_not_contain_total_penalty_expectation(),
  730 + $this->get_contains_validation_error_expectation(),
  731 + $this->get_contains_disregarded_info_expectation());
  732 +
  733 + // Finish the attempt.
  734 + $this->quba->finish_all_questions();
  735 +
  736 + // Verify.
  737 + $this->check_current_state(question_state::$gradedwrong);
  738 + $this->check_current_mark(0.9);
  739 + $this->check_current_output(
  740 + $this->get_contains_mark_summary(0.9),
  741 + $this->get_contains_submit_button_expectation(false),
  742 + $this->get_contains_incorrect_expectation(),
  743 + $this->get_does_not_contain_validation_error_expectation(),
  744 + $this->get_does_not_contain_disregarded_info_expectation());
  745 + }
631 746 }
3  question/behaviour/adaptivenopenalty/renderer.php
@@ -41,4 +41,7 @@ class qbehaviour_adaptivenopenalty_renderer extends qbehaviour_adaptive_renderer
41 41 protected function penalty_info($qa, $mark) {
42 42 return '';
43 43 }
  44 + protected function disregarded_info() {
  45 + return '';
  46 + }
44 47 }
96 question/behaviour/adaptivenopenalty/simpletest/testwalkthrough.php
@@ -38,6 +38,11 @@
38 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 39 */
40 40 class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base {
  41 +
  42 + protected function get_does_not_contain_gradingdetails_expectation() {
  43 + return new NoPatternExpectation('/class="gradingdetails"/');
  44 + }
  45 +
41 46 public function test_multichoice() {
42 47
43 48 // Create a multiple choice, single response question.
@@ -192,4 +197,95 @@ public function test_multichoice2() {
192 197 $this->get_contains_submit_button_expectation(false),
193 198 $this->get_contains_correct_expectation());
194 199 }
  200 +
  201 + public function test_numerical_invalid() {
  202 +
  203 + // Create a numerical question
  204 + $numq = test_question_maker::make_question('numerical', 'pi');
  205 + $numq->penalty = 0.1;
  206 + $this->start_attempt_at_question($numq, 'adaptivenopenalty');
  207 +
  208 + // Check the initial state.
  209 + $this->check_current_state(question_state::$todo);
  210 + $this->check_current_mark(null);
  211 + $this->check_current_output(
  212 + $this->get_contains_marked_out_of_summary(),
  213 + $this->get_contains_submit_button_expectation(true),
  214 + $this->get_does_not_contain_feedback_expectation());
  215 +
  216 + // Submit a non-numerical answer.
  217 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));
  218 +
  219 + // Verify.
  220 + $this->check_current_state(question_state::$invalid);
  221 + $this->check_current_mark(null);
  222 + $this->check_current_output(
  223 + $this->get_contains_marked_out_of_summary(1),
  224 + $this->get_contains_submit_button_expectation(true),
  225 + $this->get_does_not_contain_correctness_expectation(),
  226 + $this->get_contains_validation_error_expectation(),
  227 + $this->get_does_not_contain_feedback_expectation());
  228 +
  229 + // Submit an incorrect answer.
  230 + $this->process_submission(array('-submit' => 1, 'answer' => '-5'));
  231 +
  232 + // Verify.
  233 + $this->check_current_state(question_state::$todo);
  234 + $this->check_current_mark(0);
  235 + $this->check_current_output(
  236 + $this->get_contains_mark_summary(0),
  237 + $this->get_contains_submit_button_expectation(true),
  238 + $this->get_contains_incorrect_expectation(),
  239 + $this->get_does_not_contain_validation_error_expectation());
  240 +
  241 + // Submit another non-numerical answer.
  242 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));
  243 +
  244 + // Verify.
  245 + $this->check_current_state(question_state::$invalid);
  246 + $this->check_current_mark(0);
  247 + $this->check_current_output(
  248 + $this->get_contains_mark_summary(0),
  249 + $this->get_contains_submit_button_expectation(true),
  250 + $this->get_does_not_contain_correctness_expectation(),
  251 + $this->get_contains_validation_error_expectation(),
  252 + $this->get_does_not_contain_gradingdetails_expectation());
  253 +
  254 + // Submit the correct answer.
  255 + $this->process_submission(array('-submit' => 1, 'answer' => '3.14'));
  256 +
  257 + // Verify.
  258 + $this->check_current_state(question_state::$complete);
  259 + $this->check_current_mark(1.0);
  260 + $this->check_current_output(
  261 + $this->get_contains_mark_summary(1.0),
  262 + $this->get_contains_submit_button_expectation(true),
  263 + $this->get_contains_correct_expectation(),
  264 + $this->get_does_not_contain_validation_error_expectation());
  265 +
  266 + // Submit another non-numerical answer.
  267 + $this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));
  268 +
  269 + // Verify.
  270 + $this->check_current_state(question_state::$invalid);
  271 + $this->check_current_mark(1.0);
  272 + $this->check_current_output(
  273 + $this->get_contains_mark_summary(1.0),
  274 + $this->get_contains_submit_button_expectation(true),
  275 + $this->get_does_not_contain_correctness_expectation(),
  276 + $this->get_contains_validation_error_expectation(),
  277 + $this->get_does_not_contain_gradingdetails_expectation());
  278 +
  279 + // Finish the attempt.
  280 + $this->quba->finish_all_questions();
  281 +
  282 + // Verify.
  283 + $this->check_current_state(question_state::$gradedwrong);
  284 + $this->check_current_mark(1.0);
  285 + $this->check_current_output(
  286 + $this->get_contains_mark_summary(1.0),
  287 + $this->get_contains_submit_button_expectation(false),
  288 + $this->get_contains_incorrect_expectation(),
  289 + $this->get_does_not_contain_validation_error_expectation());
  290 + }
195 291 }

0 comments on commit 096c301

Please sign in to comment.
Something went wrong with that request. Please try again.