Skip to content

Commit

Permalink
Merge branch 'MDL-30031-21' of git://github.com/bostelm/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_21_STABLE
  • Loading branch information
stronk7 committed Jan 9, 2012
2 parents b48d180 + 6a9b598 commit 9334f3d
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 3 deletions.
2 changes: 1 addition & 1 deletion question/behaviour/adaptive/behaviour.php
Expand Up @@ -119,7 +119,7 @@ public function process_submit(question_attempt_pending_step $pendingstep) {
$status = $this->process_save($pendingstep); $status = $this->process_save($pendingstep);


$response = $pendingstep->get_qt_data(); $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); $pendingstep->set_state(question_state::$invalid);
if ($this->qa->get_state() != question_state::$invalid) { if ($this->qa->get_state() != question_state::$invalid) {
$status = question_attempt::KEEP; $status = question_attempt::KEEP;
Expand Down
Expand Up @@ -23,6 +23,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @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['gradingdetails'] = 'Marks for this submission: {$a->raw}/{$a->max}.';
$string['gradingdetailsadjustment'] = 'With previous penalties this gives <strong>{$a->cur}/{$a->max}</strong>.'; $string['gradingdetailsadjustment'] = 'With previous penalties this gives <strong>{$a->cur}/{$a->max}</strong>.';
$string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.'; $string['gradingdetailspenalty'] = 'This submission attracted a penalty of {$a}.';
Expand Down
18 changes: 18 additions & 0 deletions question/behaviour/adaptive/renderer.php
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) { 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. // Try to find the last graded step.


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


return $output; return $output;
} }

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

} }
114 changes: 112 additions & 2 deletions question/behaviour/adaptive/simpletest/testwalkthrough.php
Expand Up @@ -51,6 +51,16 @@ protected function get_does_not_contain_penalty_info_expectation() {
return new NoPatternExpectation($penaltypattern); 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() { public function test_adaptive_multichoice() {


// Create a multiple choice, single response question. // Create a multiple choice, single response question.
Expand Down Expand Up @@ -458,7 +468,8 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->get_contains_submit_button_expectation(true), $this->get_contains_submit_button_expectation(true),
$this->get_does_not_contain_correctness_expectation(), $this->get_does_not_contain_correctness_expectation(),
$this->get_does_not_contain_penalty_info_expectation(), $this->get_does_not_contain_penalty_info_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)); $this->assertNull($this->quba->get_response_summary($this->slot));


// Now get it wrong. // Now get it wrong.
Expand All @@ -483,7 +494,7 @@ public function test_adaptive_shortanswer_try_to_submit_blank() {
$this->check_current_output( $this->check_current_output(
$this->get_contains_mark_summary(0.8), $this->get_contains_mark_summary(0.8),
$this->get_contains_submit_button_expectation(true), $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_penalty_info_expectation(),
$this->get_contains_validation_error_expectation()); $this->get_contains_validation_error_expectation());
} }
Expand Down Expand Up @@ -540,4 +551,103 @@ public function test_adaptive_numerical() {
$this->get_contains_incorrect_expectation(), $this->get_contains_incorrect_expectation(),
$this->get_does_not_contain_validation_error_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_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_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_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_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_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
Expand Up @@ -41,4 +41,7 @@ class qbehaviour_adaptivenopenalty_renderer extends qbehaviour_adaptive_renderer
protected function penalty_info($qa, $mark) { protected function penalty_info($qa, $mark) {
return ''; return '';
} }
protected function disregarded_info() {
return '';
}
} }
Expand Up @@ -38,6 +38,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
class qbehaviour_adaptivenopenalty_walkthrough_test extends qbehaviour_walkthrough_test_base { 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() { public function test_multichoice() {


// Create a multiple choice, single response question. // 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_submit_button_expectation(false),
$this->get_contains_correct_expectation()); $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 9334f3d

Please sign in to comment.