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

Fill in the rest of the form to make a passing test-case button.

parent 13f4e4a7
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,7 @@ List of bugs follows/TODOs (see also https://github.com/maths/moodle-qtype_stack ...@@ -93,6 +93,7 @@ List of bugs follows/TODOs (see also https://github.com/maths/moodle-qtype_stack
1. With a question like test-3, if all the inputs were valid, and then you change the value for some inputs, the corresponding PRTs output the 'Standard feedback for incorrect' when showing the new inputs for the purpose of validation. 1. With a question like test-3, if all the inputs were valid, and then you change the value for some inputs, the corresponding PRTs output the 'Standard feedback for incorrect' when showing the new inputs for the purpose of validation.
2. Images added to prt node true or false feedback do not get displayed. There is a missing call to format_text. 2. Images added to prt node true or false feedback do not get displayed. There is a missing call to format_text.
3. **DONE** A button on the create test-case form, to fill in the expected results to automatically make a passing test-case.
### Optimising Maxima ### Optimising Maxima
......
...@@ -7,7 +7,6 @@ The following features are in approximate priority order. How to report bugs an ...@@ -7,7 +7,6 @@ The following features are in approximate priority order. How to report bugs an
* Introduce a variable so the maxima code "knows the attempt number". * Introduce a variable so the maxima code "knows the attempt number".
* Ensure the conditionals in CASText adaptive blocks code makes it into version 3. (Aalto) * Ensure the conditionals in CASText adaptive blocks code makes it into version 3. (Aalto)
* A button on the create test-case form, to fill in the expected results to automatically make a passing test-case.
* Facility to import test-cases in-bulk as CSV (or something). Likewise export. * Facility to import test-cases in-bulk as CSV (or something). Likewise export.
* Improve editing UI for test-cases https://github.com/maths/moodle-qtype_stack/issues/15 * Improve editing UI for test-cases https://github.com/maths/moodle-qtype_stack/issues/15
* Improve the way questions are deployed. * Improve the way questions are deployed.
......
...@@ -211,6 +211,7 @@ $string['ddl_empty'] = 'No choices were provided for this drop-down. Please inpu ...@@ -211,6 +211,7 @@ $string['ddl_empty'] = 'No choices were provided for this drop-down. Please inpu
$string['addanothertestcase'] = 'Add another test case...'; $string['addanothertestcase'] = 'Add another test case...';
$string['addatestcase'] = 'Add a test case...'; $string['addatestcase'] = 'Add a test case...';
$string['addingatestcase'] = 'Adding a test case to question {$a}'; $string['addingatestcase'] = 'Adding a test case to question {$a}';
$string['completetestcase'] = 'Fill in the rest of the form to make a passing test-case';
$string['createtestcase'] = 'Create test case'; $string['createtestcase'] = 'Create test case';
$string['currentlyselectedvariant'] = 'This is the variant shown below'; $string['currentlyselectedvariant'] = 'This is the variant shown below';
$string['deletetestcase'] = 'Delete test case {$a->no} for question {$a->question}'; $string['deletetestcase'] = 'Delete test case {$a->no} for question {$a->question}';
......
...@@ -62,6 +62,12 @@ if (!is_null($testcase)) { ...@@ -62,6 +62,12 @@ if (!is_null($testcase)) {
$submitlabel = get_string('createtestcase', 'qtype_stack'); $submitlabel = get_string('createtestcase', 'qtype_stack');
} }
// Create the question usage we will use.
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot, $seed);
// Create the editing form. // Create the editing form.
$mform = new qtype_stack_question_test_form($PAGE->url, $mform = new qtype_stack_question_test_form($PAGE->url,
array('submitlabel' => $submitlabel, 'question' => $question)); array('submitlabel' => $submitlabel, 'question' => $question));
...@@ -106,12 +112,6 @@ if ($mform->is_cancelled()) { ...@@ -106,12 +112,6 @@ if ($mform->is_cancelled()) {
redirect($backurl); redirect($backurl);
} }
// Create the question usage we will use.
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot, $seed);
// Prepare the display options. // Prepare the display options.
$options = new question_display_options(); $options = new question_display_options();
$options->readonly = true; $options->readonly = true;
......
...@@ -47,9 +47,8 @@ class qtype_stack_question_test_form extends moodleform { ...@@ -47,9 +47,8 @@ class qtype_stack_question_test_form extends moodleform {
$input->add_to_moodleform_testinput($mform); $input->add_to_moodleform_testinput($mform);
} }
// TODO I would really like to add a button here: $mform->addElement('submit', 'complete', get_string('completetestcase', 'qtype_stack'));
// "Fill in the rest of the form to make a passing test" $mform->registerNoSubmitButton('complete');
// but I am not quite sure how to do that easily.
// Expected outcome. // Expected outcome.
$mform->addElement('header', 'prtsheader', get_string('expectedoutcomes', 'qtype_stack')); $mform->addElement('header', 'prtsheader', get_string('expectedoutcomes', 'qtype_stack'));
...@@ -63,13 +62,41 @@ class qtype_stack_question_test_form extends moodleform { ...@@ -63,13 +62,41 @@ class qtype_stack_question_test_form extends moodleform {
$mform->createElement('select', $prtname . 'answernote', $mform->createElement('select', $prtname . 'answernote',
get_string('answernote', 'qtype_stack'), $prt->get_all_answer_notes()) get_string('answernote', 'qtype_stack'), $prt->get_all_answer_notes())
); );
$mform->addGroup($elements, null, $prtname, ' ', false); $mform->addGroup($elements, $prtname . 'group', $prtname, ' ', false);
} }
// Submit buttons. // Submit buttons.
$this->add_action_buttons(true, $this->_customdata['submitlabel']); $this->add_action_buttons(true, $this->_customdata['submitlabel']);
} }
public function definition_after_data() {
if ($this->_form->exportValue('complete')) {
$this->complete_passing_testcase();
}
}
protected function complete_passing_testcase() {
$mform = $this->_form;
$question = $this->_customdata['question'];
$inputs = array();
foreach ($question->inputs as $inputname => $input) {
$inputs[$inputname] = $mform->exportValue($inputname);
}
$response = stack_question_test::compute_response($question, $inputs);
foreach ($question->prts as $prtname => $prt) {
$result = $question->get_prt_result($prtname, $response, false);
$notes = explode(' | ', $result['answernote']);
$mform->getElement($prtname . 'group')->setValue(array(
$prtname . 'score' => $result['score'],
$prtname . 'penalty' => $result['penalty'],
$prtname . 'answernote' => end($notes)));
}
}
public function validation($data, $files) { public function validation($data, $files) {
$errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
......
...@@ -53,6 +53,7 @@ class stack_boolean_input extends stack_input { ...@@ -53,6 +53,7 @@ class stack_boolean_input extends stack_input {
public function add_to_moodleform_testinput(MoodleQuickForm $mform) { public function add_to_moodleform_testinput(MoodleQuickForm $mform) {
$mform->addElement('select', $this->name, $this->name, self::get_choices()); $mform->addElement('select', $this->name, $this->name, self::get_choices());
$mform->setDefault($this->name, '');
} }
/** /**
......
...@@ -73,7 +73,7 @@ class stack_question_test { ...@@ -73,7 +73,7 @@ class stack_question_test {
$slot = $quba->add_question($question, $question->defaultmark); $slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot, $seed); $quba->start_question($slot, $seed);
$response = $this->compute_response($question); $response = self::compute_response($question, $this->inputs);
$quba->process_action($slot, $response); $quba->process_action($slot, $response);
...@@ -100,19 +100,18 @@ class stack_question_test { ...@@ -100,19 +100,18 @@ class stack_question_test {
* @param qtype_stack_question $question the question - with $question->session initialised. * @param qtype_stack_question $question the question - with $question->session initialised.
* @return array the respones to send to $quba->process_action. * @return array the respones to send to $quba->process_action.
*/ */
protected function compute_response(qtype_stack_question $question) { public static function compute_response(qtype_stack_question $question, $inputs) {
$localoptions = clone $question->options; $localoptions = clone $question->options;
$localoptions->set_option('simplify', true); $localoptions->set_option('simplify', true);
// Start with the quetsion variables (note that order matters here). // Start with the question variables (note that order matters here).
$cascontext = new stack_cas_session(null, $localoptions, $question->seed); $cascontext = new stack_cas_session(null, $localoptions, $question->seed);
$question->add_question_vars_to_session($cascontext); $question->add_question_vars_to_session($cascontext);
// Now add the expressions we want evaluated. // Now add the expressions we want evaluated.
$vars = array(); $vars = array();
foreach ($this->inputs as $name => $value) { foreach ($inputs as $name => $value) {
// GOCHA! A $value of zero never gets used....! if ('' !== $value) {
if (''!=$value) {
$cs = new stack_cas_casstring($value); $cs = new stack_cas_casstring($value);
$cs->validate('t'); $cs->validate('t');
$cs->set_key('testresponse_' . $name); $cs->set_key('testresponse_' . $name);
...@@ -124,7 +123,7 @@ class stack_question_test { ...@@ -124,7 +123,7 @@ class stack_question_test {
$cascontext->instantiate(); $cascontext->instantiate();
$response = array(); $response = array();
foreach ($this->inputs as $name => $notused) { foreach ($inputs as $name => $notused) {
$value = $question->inputs[$name]->maxima_to_raw_input($cascontext->get_value_key('testresponse_' . $name)); $value = $question->inputs[$name]->maxima_to_raw_input($cascontext->get_value_key('testresponse_' . $name));
$response[$name] = $value; $response[$name] = $value;
$response[$name . '_val'] = $value; $response[$name . '_val'] = $value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment