Skip to content

Commit c09c9eb

Browse files
committed
add first walkthrough test (deferred feedback)
1 parent 4d9b9d2 commit c09c9eb

File tree

2 files changed

+290
-0
lines changed

2 files changed

+290
-0
lines changed

tests/helper.php

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public function get_test_questions(): array {
4242
return [
4343
// Minimal formulas question: one part, not randomised, answer = 5.
4444
'testsinglenum',
45+
// Minimal formulas question: one part, not randomised, one answer = 1, one answer = empty.
46+
'testnumandempty',
4547
// Formulas question with algebraic answer.
4648
'testalgebraic',
4749
// Minimal formulas question: one part, two numbers, answer = 2 and 3.
@@ -404,6 +406,200 @@ public static function get_formulas_question_data_testsinglenum(): stdClass {
404406
return $qdata;
405407
}
406408

409+
/**
410+
* Create a single-part test question with one number and one empty field.
411+
*
412+
* @return qtype_formulas_question
413+
*/
414+
public static function make_formulas_question_testnumandempty() {
415+
$q = self::make_a_formulas_question();
416+
417+
$q->name = 'test-numandempty';
418+
$q->questiontext = '<p>This is a minimal question. The first answer is 1, the second is empty.</p>';
419+
420+
$q->penalty = 0.3; // Non-zero and not the default.
421+
$q->textfragments = [
422+
0 => '<p>This is a minimal question. The first answer is 1, the second is empty.</p>',
423+
1 => '',
424+
];
425+
$q->numparts = 1;
426+
$q->defaultmark = 2;
427+
$q->generalfeedback = '';
428+
$p = self::make_a_formulas_part();
429+
$p->questionid = $q->id;
430+
$p->id = 14;
431+
$p->placeholder = '';
432+
$p->numbox = 2;
433+
$p->answermark = 2;
434+
$p->answer = '[1, $EMPTY]';
435+
$p->answernotunique = '1';
436+
$p->emptyallowed = '1';
437+
$p->subqtext = '';
438+
$q->parts[0] = $p;
439+
440+
$q->hints = [
441+
new question_hint_with_parts(101, 'Hint 1.', FORMAT_HTML, 1, 0),
442+
new question_hint_with_parts(102, 'Hint 2.', FORMAT_HTML, 1, 1),
443+
];
444+
return $q;
445+
}
446+
447+
/**
448+
* Gets the question form data for the testnumandempty formulas question
449+
*
450+
* @return stdClass
451+
*/
452+
public function get_formulas_question_form_data_testnumandempty(): stdClass {
453+
$form = new stdClass();
454+
455+
$form->name = 'test-numandempty';
456+
$form->noanswers = 1;
457+
$form->answer = ['1', '$EMPTY'];
458+
$form->answernotunique = ['1'];
459+
$form->emptyallowed = ['1'];
460+
$form->answermark = [2];
461+
$form->answertype = ['0'];
462+
$form->correctness = ['_relerr < 0.01'];
463+
$form->numbox = [2];
464+
$form->placeholder = [''];
465+
$form->vars1 = [''];
466+
$form->vars2 = [''];
467+
$form->postunit = [''];
468+
$form->otherrule = [''];
469+
$form->subqtext = [
470+
['text' => '', 'format' => FORMAT_HTML],
471+
];
472+
$form->feedback = [
473+
['text' => '', 'format' => FORMAT_HTML],
474+
];
475+
$form->partcorrectfb = [
476+
['text' => self::DEFAULT_CORRECT_FEEDBACK, 'format' => FORMAT_HTML],
477+
];
478+
$form->partpartiallycorrectfb = [
479+
['text' => self::DEFAULT_PARTIALLYCORRECT_FEEDBACK, 'format' => FORMAT_HTML],
480+
];
481+
$form->partincorrectfb = [
482+
['text' => self::DEFAULT_INCORRECT_FEEDBACK, 'format' => FORMAT_HTML],
483+
];
484+
$form->questiontext = [
485+
'text' => '<p>This is a minimal question. The first answer is 1, the second is empty.</p>',
486+
'format' => FORMAT_HTML,
487+
];
488+
$form->generalfeedback = ['text' => '', 'format' => FORMAT_HTML];
489+
$form->defaultmark = 2;
490+
$form->penalty = 0.3;
491+
$form->varsrandom = '';
492+
$form->varsglobal = '';
493+
$form->answernumbering = 'abc';
494+
$form->globalunitpenalty = 1;
495+
$form->globalruleid = 1;
496+
$form->correctfeedback = [
497+
'text' => test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK,
498+
'format' => FORMAT_HTML,
499+
];
500+
$form->partiallycorrectfeedback = [
501+
'text' => test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK,
502+
'format' => FORMAT_HTML,
503+
];
504+
$form->incorrectfeedback = [
505+
'text' => test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK,
506+
'format' => FORMAT_HTML,
507+
];
508+
$form->shownumcorrect = '1';
509+
$form->hint = [
510+
['text' => 'Hint 1.', 'format' => FORMAT_HTML],
511+
['text' => 'Hint 2.', 'format' => FORMAT_HTML],
512+
];
513+
$form->hintclearwrong = [0, 1];
514+
$form->hintshownumcorrect = [1, 1];
515+
return $form;
516+
}
517+
518+
/**
519+
* Return question data for a single-part question with one number and an empty field.
520+
*
521+
* @return stdClass
522+
*/
523+
public static function get_formulas_question_data_testnumandempty(): stdClass {
524+
$qdata = new stdClass();
525+
test_question_maker::initialise_question_data($qdata);
526+
527+
$qdata->qtype = 'formulas';
528+
$qdata->name = 'test-numandempty';
529+
$qdata->questiontext = '<p>This is a minimal question. The first answer is 1, the second is empty.</p>';
530+
$qdata->generalfeedback = '';
531+
$qdata->defaultmark = 2;
532+
$qdata->penalty = 0.3;
533+
534+
$qdata->options = new stdClass();
535+
$qdata->contextid = context_system::instance()->id;
536+
$qdata->options->varsrandom = '';
537+
$qdata->options->varsglobal = '';
538+
$qdata->options->answernumbering = 'abc';
539+
$qdata->options->shownumcorrect = 1;
540+
$qdata->options->correctfeedback = test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK;
541+
$qdata->options->correctfeedbackformat = FORMAT_HTML;
542+
$qdata->options->partiallycorrectfeedback = test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK;
543+
$qdata->options->partiallycorrectfeedbackformat = FORMAT_HTML;
544+
$qdata->options->incorrectfeedback = test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK;
545+
$qdata->options->incorrectfeedbackformat = FORMAT_HTML;
546+
547+
$qdata->options->answers = [
548+
14 => (object) [
549+
'id' => 14,
550+
'questionid' => $qdata->id,
551+
'placeholder' => '',
552+
'answermark' => 2,
553+
'answertype' => '0',
554+
'numbox' => 2,
555+
'vars1' => '',
556+
'vars2' => '',
557+
'answer' => '[1, $EMPTY]',
558+
'answernotunique' => '1',
559+
'emptyallowed' => '1',
560+
'correctness' => '_relerr < 0.01',
561+
'unitpenalty' => 1,
562+
'postunit' => '',
563+
'ruleid' => 1,
564+
'otherrule' => '',
565+
'subqtext' => '',
566+
'subqtextformat' => FORMAT_HTML,
567+
'feedback' => '',
568+
'feedbackformat' => FORMAT_HTML,
569+
'partcorrectfb' => self::DEFAULT_CORRECT_FEEDBACK,
570+
'partcorrectfbformat' => FORMAT_HTML,
571+
'partpartiallycorrectfb' => self::DEFAULT_PARTIALLYCORRECT_FEEDBACK,
572+
'partpartiallycorrectfbformat' => FORMAT_HTML,
573+
'partincorrectfb' => self::DEFAULT_INCORRECT_FEEDBACK,
574+
'partincorrectfbformat' => FORMAT_HTML,
575+
'partindex' => 0,
576+
],
577+
];
578+
579+
$qdata->options->numparts = 1;
580+
581+
$qdata->hints = [
582+
(object) [
583+
'id' => '101',
584+
'hint' => 'Hint 1.',
585+
'hintformat' => FORMAT_HTML,
586+
'shownumcorrect' => 1,
587+
'clearwrong' => 0,
588+
'options' => 0,
589+
],
590+
(object) [
591+
'id' => '102',
592+
'hint' => 'Hint 2.',
593+
'hintformat' => FORMAT_HTML,
594+
'shownumcorrect' => 1,
595+
'clearwrong' => 1,
596+
'options' => 1,
597+
],
598+
];
599+
600+
return $qdata;
601+
}
602+
407603
/**
408604
* Return Formulas question with one part, one number with unit (combined), answer = 5 m/s.
409605
*

tests/walkthrough_adaptive_test.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,4 +1097,98 @@ public function test_separate_unit_field_with_micro(): void {
10971097
$this->process_submission(['0_0' => '1', '0_1' => 'µA', '-submit' => 1]);
10981098
$this->check_current_mark(1);
10991099
}
1100+
public function test_deferred_partially_answered_with_empty_allowed(): void {
1101+
// Create a question with one empty field.
1102+
$q = $this->get_test_formulas_question('testnumandempty');
1103+
$this->start_attempt_at_question($q, 'deferredfeedback', 2);
1104+
1105+
// Check the initial state.
1106+
$this->check_current_state(question_state::$todo);
1107+
$this->check_current_mark(null);
1108+
$this->render();
1109+
$this->check_output_contains_text_input('0_0');
1110+
$this->check_output_contains_text_input('0_1');
1111+
$this->check_current_output(
1112+
$this->get_contains_marked_out_of_summary(),
1113+
$this->get_does_not_contain_submit_button_expectation(),
1114+
$this->get_does_not_contain_feedback_expectation(),
1115+
);
1116+
1117+
// Submit the empty form. The question should be counted as "gave up" with no grade.
1118+
// The feedback should be "incorrect".
1119+
$this->finish();
1120+
$this->check_current_state(question_state::$gaveup);
1121+
$this->check_current_mark(null);
1122+
$this->render();
1123+
$this->check_output_contains_text_input('0_0', '', false);
1124+
$this->check_output_contains_text_input('0_1', '', false);
1125+
1126+
// Submit a partial answer, filling only the first field, but wrong. The question should be
1127+
// graded wrong due to the grading criterion. The student's response should be shown in the
1128+
// text field. All text fields should be disabled.
1129+
$this->start_attempt_at_question($q, 'deferredfeedback', 2);
1130+
$this->check_current_state(question_state::$todo);
1131+
$this->process_submission(['0_0' => '5', '0_1' => '']);
1132+
$this->finish();
1133+
$this->check_current_state(question_state::$gradedwrong);
1134+
$this->check_current_mark(0);
1135+
$this->render();
1136+
$this->check_output_contains_text_input('0_0', '5', false);
1137+
$this->check_output_contains_text_input('0_1', '', false);
1138+
$this->check_current_output(
1139+
$this->get_contains_mark_summary(0),
1140+
$this->get_contains_incorrect_expectation(),
1141+
);
1142+
1143+
// Submit an answer, filling only the first field, correct. The question should be
1144+
// graded correct. The student's response should be shown in the text field.
1145+
// All text fields should be disabled.
1146+
$this->start_attempt_at_question($q, 'deferredfeedback', 2);
1147+
$this->check_current_state(question_state::$todo);
1148+
$this->process_submission(['0_0' => '1', '0_1' => '']);
1149+
$this->finish();
1150+
$this->check_current_state(question_state::$gradedright);
1151+
$this->check_current_mark(2);
1152+
$this->render();
1153+
$this->check_output_contains_text_input('0_0', '1', false);
1154+
$this->check_output_contains_text_input('0_1', '', false);
1155+
$this->check_current_output(
1156+
$this->get_contains_mark_summary(2),
1157+
$this->get_contains_correct_expectation(),
1158+
);
1159+
1160+
// Submit an answer, filling only the second field, obviously wrong. The question should
1161+
// be graded wrong. The student's response should be shown in the text field.
1162+
// All text fields should be disabled.
1163+
$this->start_attempt_at_question($q, 'deferredfeedback', 2);
1164+
$this->check_current_state(question_state::$todo);
1165+
$this->process_submission(['0_0' => '', '0_1' => '1']);
1166+
$this->finish();
1167+
$this->check_current_state(question_state::$gradedwrong);
1168+
$this->check_current_mark(0);
1169+
$this->render();
1170+
$this->check_output_contains_text_input('0_0', '', false);
1171+
$this->check_output_contains_text_input('0_1', '1', false);
1172+
$this->check_current_output(
1173+
$this->get_contains_mark_summary(0),
1174+
$this->get_contains_incorrect_expectation(),
1175+
);
1176+
1177+
// Submit an answer, filling both fields. The question should be graded wrong.
1178+
// The student's response should be shown in the text field.
1179+
// All text fields should be disabled.
1180+
$this->start_attempt_at_question($q, 'deferredfeedback', 2);
1181+
$this->check_current_state(question_state::$todo);
1182+
$this->process_submission(['0_0' => '1', '0_1' => '2']);
1183+
$this->finish();
1184+
$this->check_current_state(question_state::$gradedwrong);
1185+
$this->check_current_mark(0);
1186+
$this->render();
1187+
$this->check_output_contains_text_input('0_0', '1', false);
1188+
$this->check_output_contains_text_input('0_1', '2', false);
1189+
$this->check_current_output(
1190+
$this->get_contains_mark_summary(0),
1191+
$this->get_contains_incorrect_expectation(),
1192+
);
1193+
}
11001194
}

0 commit comments

Comments
 (0)