Skip to content

Commit

Permalink
MDL-30031 Adaptive question behaviour: ignore invalid answers without…
Browse files Browse the repository at this point in the history
… penalty
  • Loading branch information
bostelm committed Dec 28, 2011
1 parent 929c26c commit fb93cfa
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 3 deletions.
2 changes: 1 addition & 1 deletion question/behaviour/adaptive/behaviour.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function process_submit(question_attempt_pending_step $pendingstep) {
$status = $this->process_save($pendingstep);

$response = $pendingstep->get_qt_data();
if (!$this->question->is_gradable_response($response)) {
if (!$this->question->is_complete_response($response)) {
$pendingstep->set_state(question_state::$invalid);
if ($this->qa->get_state() != question_state::$invalid) {
$status = question_attempt::KEEP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['disregardedwithoutpenalty'] = 'The submission was invalid, and has been disregarded without penalty.';
$string['gradingdetails'] = 'Marks for this submission: {$a->raw}/{$a->max}.';
$string['gradingdetailsadjustment'] = 'Accounting for previous tries, this gives <strong>{$a->cur}/{$a->max}</strong>.';
$string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.';
Expand Down
18 changes: 18 additions & 0 deletions question/behaviour/adaptive/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public function controls(question_attempt $qa, question_display_options $options
}

public function feedback(question_attempt $qa, question_display_options $options) {
if ($qa->get_state() == question_state::$invalid) {
// If the latest answer was invalid, display an informative message
$output = '';
$info = $this->disregarded_info();
if ($info) {
$output = html_writer::tag('div', $info, array('class' => 'gradingdetails'));
}
return $output;
}

// Try to find the last graded step.

$gradedstep = $qa->get_behaviour()->get_graded_step($qa);
Expand Down Expand Up @@ -116,4 +126,12 @@ protected function penalty_info(question_attempt $qa, $mark,

return $output;
}

/**
* Display information about a disregarded (incomplete) response.
*/
protected function disregarded_info() {
return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
}

}
119 changes: 117 additions & 2 deletions question/behaviour/adaptive/simpletest/testwalkthrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ protected function get_does_not_contain_total_penalty_expectation() {
return new NoPatternExpectation($penaltypattern);
}

protected function get_contains_disregarded_info_expectation() {
$penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
return new PatternExpectation('/'.preg_quote($penaltyinfo).'/');
}

protected function get_does_not_contain_disregarded_info_expectation() {
$penaltyinfo = get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive');
return new NoPatternExpectation('/'.preg_quote($penaltyinfo).'/');
}

public function test_adaptive_multichoice() {

// Create a multiple choice, single response question.
Expand Down Expand Up @@ -542,7 +552,8 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation());
$this->get_contains_validation_error_expectation(),
$this->get_contains_disregarded_info_expectation());
$this->assertNull($this->quba->get_response_summary($this->slot));

// Now get it wrong.
Expand All @@ -568,7 +579,7 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->check_current_output(
$this->get_contains_mark_summary(0.8),
$this->get_contains_submit_button_expectation(true),
$this->get_contains_partcorrect_expectation(),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation());
Expand Down Expand Up @@ -628,4 +639,108 @@ public function test_adaptive_numerical() {
$this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_expectation());
}

public function test_adaptive_numerical_invalid() {

// Create a numerical question
$numq = test_question_maker::make_question('numerical', 'pi');
$numq->penalty = 0.1;
$this->start_attempt_at_question($numq, 'adaptive');

// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_marked_out_of_summary(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation());

// Submit a non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_marked_out_of_summary(1),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_contains_disregarded_info_expectation());

// Submit an incorrect answer.
$this->process_submission(array('-submit' => 1, 'answer' => '-5'));

// Verify.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(0);
$this->check_current_output(
$this->get_contains_mark_summary(0),
$this->get_contains_submit_button_expectation(true),
$this->get_contains_incorrect_expectation(),
$this->get_contains_penalty_info_expectation(0.1),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_does_not_contain_validation_error_expectation(),
$this->get_does_not_contain_disregarded_info_expectation());

// Submit another non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(0);
$this->check_current_output(
$this->get_contains_mark_summary(0),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_contains_disregarded_info_expectation());

// Submit the correct answer.
$this->process_submission(array('-submit' => 1, 'answer' => '3.14'));

// Verify.
$this->check_current_state(question_state::$complete);
$this->check_current_mark(0.9);
$this->check_current_output(
$this->get_contains_mark_summary(0.9),
$this->get_contains_submit_button_expectation(true),
$this->get_contains_correct_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_does_not_contain_validation_error_expectation(),
$this->get_does_not_contain_disregarded_info_expectation());

// Submit another non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(0.9);
$this->check_current_output(
$this->get_contains_mark_summary(0.9),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(),
$this->get_does_not_contain_total_penalty_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_contains_disregarded_info_expectation());

// Finish the attempt.
$this->quba->finish_all_questions();

// Verify.
$this->check_current_state(question_state::$gradedwrong);
$this->check_current_mark(0.9);
$this->check_current_output(
$this->get_contains_mark_summary(0.9),
$this->get_contains_submit_button_expectation(false),
$this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_expectation(),
$this->get_does_not_contain_disregarded_info_expectation());
}
}
3 changes: 3 additions & 0 deletions question/behaviour/adaptivenopenalty/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ class qbehaviour_adaptivenopenalty_renderer extends qbehaviour_adaptive_renderer
protected function penalty_info($qa, $mark) {
return '';
}
protected function disregarded_info() {
return '';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base {

protected function get_does_not_contain_gradingdetails_expectation() {
return new NoPatternExpectation('/class="gradingdetails"/');
}

public function test_multichoice() {

// Create a multiple choice, single response question.
Expand Down Expand Up @@ -192,4 +197,95 @@ public function test_multichoice2() {
$this->get_contains_submit_button_expectation(false),
$this->get_contains_correct_expectation());
}

public function test_numerical_invalid() {

// Create a numerical question
$numq = test_question_maker::make_question('numerical', 'pi');
$numq->penalty = 0.1;
$this->start_attempt_at_question($numq, 'adaptivenopenalty');

// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_marked_out_of_summary(),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_feedback_expectation());

// Submit a non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->check_current_output(
$this->get_contains_marked_out_of_summary(1),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_does_not_contain_feedback_expectation());

// Submit an incorrect answer.
$this->process_submission(array('-submit' => 1, 'answer' => '-5'));

// Verify.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(0);
$this->check_current_output(
$this->get_contains_mark_summary(0),
$this->get_contains_submit_button_expectation(true),
$this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_expectation());

// Submit another non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi*2'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(0);
$this->check_current_output(
$this->get_contains_mark_summary(0),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_does_not_contain_gradingdetails_expectation());

// Submit the correct answer.
$this->process_submission(array('-submit' => 1, 'answer' => '3.14'));

// Verify.
$this->check_current_state(question_state::$complete);
$this->check_current_mark(1.0);
$this->check_current_output(
$this->get_contains_mark_summary(1.0),
$this->get_contains_submit_button_expectation(true),
$this->get_contains_correct_expectation(),
$this->get_does_not_contain_validation_error_expectation());

// Submit another non-numerical answer.
$this->process_submission(array('-submit' => 1, 'answer' => 'Pi/3'));

// Verify.
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(1.0);
$this->check_current_output(
$this->get_contains_mark_summary(1.0),
$this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(),
$this->get_contains_validation_error_expectation(),
$this->get_does_not_contain_gradingdetails_expectation());

// Finish the attempt.
$this->quba->finish_all_questions();

// Verify.
$this->check_current_state(question_state::$gradedwrong);
$this->check_current_mark(1.0);
$this->check_current_output(
$this->get_contains_mark_summary(1.0),
$this->get_contains_submit_button_expectation(false),
$this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_expectation());
}
}

0 comments on commit fb93cfa

Please sign in to comment.