Skip to content
Snippets Groups Projects
Commit 15a79ac7 authored by Tim Hunt's avatar Tim Hunt
Browse files

Progress on adaptive multi-part. Correctly handle weights.

parent d4c82f55
No related branches found
No related tags found
No related merge requests found
...@@ -409,6 +409,14 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -409,6 +409,14 @@ class qtype_stack_question extends question_graded_automatically_with_countback
return true; return true;
} }
public function get_parts_and_weights() {
$weights = array();
foreach ($this->prts as $index => $prt) {
$weights[$index] = $prt->get_value();
}
return $weights;
}
public function grade_parts_that_can_be_graded(array $response, array $lastgradedresponses, $finalsubmit) { public function grade_parts_that_can_be_graded(array $response, array $lastgradedresponses, $finalsubmit) {
$partresults = array(); $partresults = array();
...@@ -435,7 +443,7 @@ class qtype_stack_question extends question_graded_automatically_with_countback ...@@ -435,7 +443,7 @@ class qtype_stack_question extends question_graded_automatically_with_countback
// TODO check for errors. // TODO check for errors.
$partresults[$index] = new qbehaviour_adaptivemultipart_part_result( $partresults[$index] = new qbehaviour_adaptivemultipart_part_result(
$index, $results['value'], $results['score'], $results['penalty']); $index, $results['score'], $results['penalty']);
} }
return $partresults; return $partresults;
......
...@@ -185,7 +185,6 @@ class stack_potentialresponse_tree { ...@@ -185,7 +185,6 @@ class stack_potentialresponse_tree {
$res['valid'] = $results->_valid; $res['valid'] = $results->_valid;
$res['score'] = $results->_score + 0; // Make sure these are PHP numbers. $res['score'] = $results->_score + 0; // Make sure these are PHP numbers.
$res['penalty'] = $results->_penalty + 0; $res['penalty'] = $results->_penalty + 0;
$res['value'] = $this->value;
$res['fraction'] = $results->_score * $this->value; $res['fraction'] = $results->_score * $this->value;
$res['fractionalpenalty'] = $results->_penalty * $this->value; $res['fractionalpenalty'] = $results->_penalty * $this->value;
...@@ -248,4 +247,11 @@ class stack_potentialresponse_tree { ...@@ -248,4 +247,11 @@ class stack_potentialresponse_tree {
} }
return $notes; return $notes;
} }
/**
* @return float the value of this PRT within the question.
*/
public function get_value() {
return $this->value;
}
} }
...@@ -38,22 +38,19 @@ require_once(dirname(__FILE__) . '/test_base.php'); ...@@ -38,22 +38,19 @@ require_once(dirname(__FILE__) . '/test_base.php');
* @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
* @group qtype_stack * @group qtype_stack
*/ */
class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base { class qtype_stack_walkthrough_adaptive_test extends qtype_stack_walkthrough_test_base {
public function setUp() {
parent::setUp();
qtype_stack_testcase::setup_test_maxima_connection($this);
$this->resetAfterTest();
}
public function test_adaptivefeedback_behaviour_test1_1() { public function test_test1_validate_then_submit_right_first_time() {
// Create the stack question 'test1'. // Create the stack question 'test1'.
$q = test_question_maker::make_question('stack', 'test1'); $q = test_question_maker::make_question('stack', 'test1');
$this->start_attempt_at_question($q, 'adaptive', 1); $this->start_attempt_at_question($q, 'adaptive', 1);
// Check the initial state. // Check the initial state.
$this->check_current_state(question_state::$todo); $this->check_current_state(question_state::$todo);
$this->check_current_mark(null); $this->assertEquals('adaptivemultipart',
$this->quba->get_question_attempt($this->slot)->get_behaviour_name());
$this->render(); $this->render();
$this->check_output_contains_text_input('ans1'); $this->check_output_contains_text_input('ans1');
$this->check_output_does_not_contain_input_validation(); $this->check_output_does_not_contain_input_validation();
...@@ -89,7 +86,7 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base { ...@@ -89,7 +86,7 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base {
$this->check_output_does_not_contain_stray_placeholders(); $this->check_output_does_not_contain_stray_placeholders();
} }
public function test_adaptivefeedback_behaviour_test1_2() { public function test_test1_validate_wrong_validate_right_submit_right() {
$q = test_question_maker::make_question('stack', 'test1'); $q = test_question_maker::make_question('stack', 'test1');
$this->start_attempt_at_question($q, 'adaptive', 1); $this->start_attempt_at_question($q, 'adaptive', 1);
...@@ -140,7 +137,7 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base { ...@@ -140,7 +137,7 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base {
$this->check_output_does_not_contain_stray_placeholders(); $this->check_output_does_not_contain_stray_placeholders();
} }
public function test_adaptivefeedback_behaviour_test1_3() { public function test_test1_invalid_valid_but_wrong_with_specific_feedback() {
// Create a stack question. // Create a stack question.
$q = test_question_maker::make_question('stack', 'test1'); $q = test_question_maker::make_question('stack', 'test1');
...@@ -198,4 +195,189 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base { ...@@ -198,4 +195,189 @@ class qtype_stack_walkthrough_test extends qtype_stack_walkthrough_test_base {
new question_pattern_expectation('/differentiated instead!/') new question_pattern_expectation('/differentiated instead!/')
); );
} }
public function test_test3_sumbit_and_finish_before_validating() {
// Create a stack question.
$q = test_question_maker::make_question('stack', 'test3');
$this->start_attempt_at_question($q, 'adaptive', 4);
// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1');
$this->check_output_contains_text_input('ans2');
$this->check_output_contains_text_input('ans3');
$this->check_output_does_not_contain_input_validation();
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), '', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Save a partially correct, partially complete response.
$this->process_submission(array('ans1' => 'x^3', 'ans2' => 'x^2', 'ans3' => 'x', 'ans4' => ''));
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3');
$this->check_output_contains_text_input('ans2', 'x^2');
$this->check_output_contains_text_input('ans3', 'x');
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), 'false', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Submit all and finish before validating.
$this->quba->finish_all_questions();
$this->check_current_state(question_state::$gradedpartial);
$this->check_current_mark(2.5);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3', false);
$this->check_output_contains_text_input('ans2', 'x^2', false);
$this->check_output_contains_text_input('ans3', 'x', false);
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_contains_prt_feedback('odd');
$this->check_output_contains_prt_feedback('even');
$this->check_output_contains_prt_feedback('oddeven');
$this->check_output_does_not_contain_prt_feedback('unique');
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), '', false),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
}
public function test_test3_save_invalid_response_correct_then_stubmit() {
// Create a stack question.
$q = test_question_maker::make_question('stack', 'test3');
$this->start_attempt_at_question($q, 'immediatefeedback', 4);
// Check the initial state.
$this->check_current_state(question_state::$todo);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1');
$this->check_output_contains_text_input('ans2');
$this->check_output_contains_text_input('ans3');
$this->check_output_does_not_contain_input_validation();
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), '', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Submit a partially correct response.
$this->process_submission(array('ans1' => 'x^3', 'ans2' => '(x +', 'ans3' => '0', 'ans4' => 'true', '-submit' => 1));
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3');
$this->check_output_contains_text_input('ans2', '(x +');
$this->check_output_contains_text_input('ans3', '0');
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), 'false', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Try to submit again without editing. Shoud not be accepted.
$this->process_submission(array('ans1' => 'x^3', 'ans2' => '(x +', 'ans3' => '0', 'ans4' => 'true',
'ans1_val' => 'x^3', 'ans3_val' => '0', '-submit' => 1));
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3');
$this->check_output_contains_text_input('ans2', '(x +');
$this->check_output_contains_text_input('ans3', '0');
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), 'false', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Now fix the resonse and submit. Should only be validated.
$this->process_submission(array('ans1' => 'x^3', 'ans2' => 'x^2', 'ans3' => '0', 'ans4' => 'true',
'ans1_val' => 'x^3', 'ans3_val' => '0', '-submit' => 1));
$this->check_current_state(question_state::$invalid);
$this->check_current_mark(null);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3');
$this->check_output_contains_text_input('ans2', 'x^2');
$this->check_output_contains_text_input('ans3', '0');
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_does_not_contain_prt_feedback();
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), 'false', true),
$this->get_does_not_contain_feedback_expectation(),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
// Submit again. Should now be graded.
$this->process_submission(array('ans1' => 'x^3', 'ans2' => 'x^2', 'ans3' => '0', 'ans4' => 'true',
'ans1_val' => 'x^3', 'ans2_val' => 'x^2', 'ans3_val' => '0', '-submit' => 1));
$this->check_current_state(question_state::$gradedright);
$this->check_current_mark(4);
$this->render();
$this->check_output_contains_text_input('ans1', 'x^3', false);
$this->check_output_contains_text_input('ans2', 'x^2', false);
$this->check_output_contains_text_input('ans3', '0', false);
$this->check_output_contains_input_validation('ans1');
$this->check_output_contains_input_validation('ans2');
$this->check_output_contains_input_validation('ans3');
$this->check_output_does_not_contain_input_validation('ans4');
$this->check_output_contains_prt_feedback('odd');
$this->check_output_contains_prt_feedback('even');
$this->check_output_contains_prt_feedback('oddeven');
$this->check_output_contains_prt_feedback('unique');
$this->check_output_does_not_contain_stray_placeholders();
$this->check_current_output(
$this->get_contains_select_expectation('ans4', stack_boolean_input::get_choices(), 'false', false),
$this->get_does_not_contain_num_parts_correct(),
$this->get_no_hint_visible_expectation()
);
}
} }
...@@ -40,7 +40,7 @@ require_once(dirname(__FILE__) . '/test_base.php'); ...@@ -40,7 +40,7 @@ require_once(dirname(__FILE__) . '/test_base.php');
*/ */
class qtype_stack_walkthrough_immediate_feedback_test extends qtype_stack_walkthrough_test_base { class qtype_stack_walkthrough_immediate_feedback_test extends qtype_stack_walkthrough_test_base {
public function test_test3_partially_right_the_right() { public function test_test3_partially_right_then_right() {
// Create a stack question. // Create a stack question.
$q = test_question_maker::make_question('stack', 'test3'); $q = test_question_maker::make_question('stack', 'test3');
$this->start_attempt_at_question($q, 'immediatefeedback', 4); $this->start_attempt_at_question($q, 'immediatefeedback', 4);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment