@@ -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 *
0 commit comments