public static function make_question($type, $answers = array("cat", "mat")) { question_bank::load_question_definition_classes($type); $question = new qtype_gapfill_question(); test_question_maker::initialise_a_question($question); $question->qtype = question_bank::get_qtype('gapfill'); $question->name = 'Gapfill Test Question'; $question->questiontext = "The [cat] sat on the [mat]"; $question->textfragments = array('The ', ' sat on the '); $question->displayanswers = '1'; $question->casesensitive = '1'; $question->generalfeedback = 'congratulations on your knowledge of pets and floor covering'; $question->places[1] = $answers[0]; $question->places[2] = $answers[1]; $answer1 = new question_answer(43, $answers[0], 4, 1, 1); $answer2 = new question_answer(44, $answers[1], 4, 1, 1); $question->answers = array($answer1, $answer2); $question->options = new stdClass(); $question->options->showanswers = false; $question->options->delimitchars = "[]"; $question->options->casesensitive = false; $question->options->correctfeedback = ""; $question->options->correctfeedbackformat = ""; $question->options->partiallycorrectfeedback = ""; $question->options->partiallycorrectfeedbackformat = ""; $question->options->incorrectfeedback = ""; $question->options->incorrectfeedbackformat = ""; $question->options->shuffledanswers = "mat,cat"; $question->options->wronganswers = "bat,dog"; $question->shuffledanswers = "mat,cat,bat,dog"; $answers = new stdClass(); $question->options->answers = array($answer1, $answer2); $question->hints = array(new question_hint(1, 'This is the first hint.', FORMAT_HTML), new question_hint(2, 'This is the second hint.', FORMAT_HTML)); return $question; }
public function test_grading_rounding_three_right() { question_bank::load_question_definition_classes('multichoice'); $mc = new qtype_multichoice_multi_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Odd numbers'; $mc->questiontext = 'Which are the odd numbers?'; $mc->generalfeedback = '1, 3 and 5 are the odd numbers.'; $mc->qtype = question_bank::get_qtype('multichoice'); $mc->shuffleanswers = 0; $mc->answernumbering = 'abc'; test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array( 11 => new question_answer(11, '1', 0.3333333, '', FORMAT_HTML), 12 => new question_answer(12, '2', -1, '', FORMAT_HTML), 13 => new question_answer(13, '3', 0.3333333, '', FORMAT_HTML), 14 => new question_answer(14, '4', -1, '', FORMAT_HTML), 15 => new question_answer(15, '5', 0.3333333, '', FORMAT_HTML), 16 => new question_answer(16, '6', -1, '', FORMAT_HTML), ); $mc->start_attempt(new question_attempt_step(), 1); list($grade, $state) = $mc->grade_response( array('choice0' => 1, 'choice2' => 1, 'choice4' => 1)); $this->assertEquals(1, $grade, '', 0.000001); $this->assertEquals(question_state::$gradedright, $state); }
/** * Makes a calculated question about summing two numbers. * @return qtype_calculated_question */ public function get_calculated_question_data_sum() { question_bank::load_question_definition_classes('calculated'); $qdata = new stdClass(); test_question_maker::initialise_question_data($qdata); $qdata->qtype = 'calculated'; $qdata->name = 'Simple sum'; $qdata->questiontext = 'What is {a} + {b}?'; $qdata->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $qdata->options = new stdClass(); $qdata->options->unitgradingtype = 0; $qdata->options->unitpenalty = 0.0; $qdata->options->showunits = qtype_numerical::UNITNONE; $qdata->options->unitsleft = 0; $qdata->options->synchronize = 0; $qdata->options->answers = array( 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0.001), 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0.001), 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), ); foreach ($qdata->options->answers as $answer) { $answer->correctanswerlength = 2; $answer->correctanswerformat = 1; } $qdata->options->units = array(); return $qdata; }
/** * Makes a calculated question about summing two numbers. * @return qtype_calculated_question */ public function make_calculated_question_sum() { question_bank::load_question_definition_classes('calculated'); $q = new qtype_calculated_question(); test_question_maker::initialise_a_question($q); $q->name = 'Simple sum'; $q->questiontext = 'What is {a} + {b}?'; $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $q->answers = array( 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0), 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0), 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), ); foreach ($q->answers as $answer) { $answer->correctanswerlength = 2; $answer->correctanswerformat = 1; } $q->qtype = question_bank::get_qtype('calculated'); $q->unitdisplay = qtype_numerical::UNITNONE; $q->unitgradingtype = 0; $q->unitpenalty = 0; $q->ap = new qtype_numerical_answer_processor(array()); $q->synchronised = false; $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( array('a' => 1, 'b' => 5), array('a' => 3, 'b' => 4), )); return $q; }
protected function make_question_instance($questiondata) { question_bank::load_question_definition_classes($this->name()); $class = get_class($this); if ($questiondata->options->single) { $class = $class . '_single_question'; } else { $class = $class . '_multi_question'; } return new $class(); }
/** * Makes a REGEXP question with (first) correct answer "it's blue, white and red" * partially correct answer must match "(it('s| is) |they are )?blue, white, red" * @return qtype_regexp_question */ public static function make_a_regexp_question() { question_bank::load_question_definition_classes('regexp'); $pm = new qtype_regexp_question(); self::initialise_a_question($pm); $pm->name = 'Regular expression short answer question'; $pm->questiontext = 'French flag colors : __________'; // generalfeedback is not needed in the REGEXP question type //$pm->generalfeedback = 'Generalfeedback: '; //$pm->regexpoptions = new regexp_options(); $pm->answers = array(13 => new question_answer(13, "it's blue, white and red", 1.0, 'ok', FORMAT_HTML), 14 => new question_answer(14, "(it('s| is) |they are )?blue, white, red", 0.8, 'yes', FORMAT_HTML), 15 => new question_answer(15, '--.*blue.*', 0.0, 'Missing blue!', FORMAT_HTML), 15 => new question_answer(15, '.*', 0.0, 'No, no, no! Try again', FORMAT_HTML)); $pm->qtype = question_bank::get_qtype('regexp'); return $pm; }
/** * @return qtype_linkerdesc_question */ public static function make_linkerdesc_question_info() { question_bank::load_question_definition_classes('linkerdesc'); $q = new qtype_linkerdesc_question(); test_question_maker::initialise_a_question($q); $q->defaultmark = 0; $q->penalty = 0; $q->length = 0; $q->name = 'Description'; $q->questiontext = 'Here is some information about the questions you are about to attempt.'; $q->generalfeedback = 'And here is some more text shown only on the review page.'; $q->qtype = question_bank::get_qtype('linkerdesc'); return $q; }
/** * Makes a turmultiplechoice question with choices 'A', 'B', 'C' and 'D' shuffled. * 'A' and 'C' is correct, defaultmark 1. * @return qtype_turmultiplechoice_multi_question */ public static function make_a_turmultiplechoice_multi_question() { question_bank::load_question_definition_classes('turmultiplechoice'); $mc = new qtype_turmultiplechoice_multi_question(); self::initialise_a_question($mc); $mc->name = 'Multi-choice question, multiple response'; $mc->questiontext = 'The answer is A and C.'; $mc->generalfeedback = 'You should have selected A and C.'; $mc->qtype = question_bank::get_qtype('turmultiplechoice'); $mc->shuffleanswers = 1; $mc->qdifficulty = '0'; self::set_standard_combined_feedback_fields($mc); $mc->answers = array(13 => new question_answer(13, 'A', 0.5, 'A is part of the right answer', FORMAT_HTML), 14 => new question_answer(14, 'B', -1, 'B is wrong', FORMAT_HTML), 15 => new question_answer(15, 'C', 0.5, 'C is part of the right answer', FORMAT_HTML), 16 => new question_answer(16, 'D', -1, 'D is wrong', FORMAT_HTML)); return $mc; }
/** * Makes a multichoice all or nothing question with choices 'A', 'B', 'C' and 'D' shuffled. * 'A' and 'C' is correct, defaultmark 1. * @return qtype_multichoiceset_question */ public static function make_a_multichoiceset_question() { question_bank::load_question_definition_classes('multichoiceset'); $mc = new qtype_multichoiceset_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Multi-choice all or nothing question'; $mc->questiontext = 'The answer is A and C.'; $mc->generalfeedback = 'You should have selected A and C.'; $mc->qtype = question_bank::get_qtype('multichoiceset'); $mc->shuffleanswers = 1; $mc->answernumbering = 'abc'; test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array(13 => new question_answer(13, 'A', 0.5, 'A is part of the right answer', FORMAT_HTML), 14 => new question_answer(14, 'B', 0, 'B is wrong', FORMAT_HTML), 15 => new question_answer(15, 'C', 0.5, 'C is part of the right answer', FORMAT_HTML), 16 => new question_answer(16, 'D', 0, 'D is wrong', FORMAT_HTML)); return $mc; }
/** * Make a mathematical ddimageortext question. * * @return qtype_ddimageortext_question */ public function make_ddimageortext_question_maths() { question_bank::load_question_definition_classes('ddimageortext'); $dd = new qtype_ddimageortext_question(); test_question_maker::initialise_a_question($dd); $dd->name = 'Drag-and-drop onto image question'; $dd->questiontext = 'Fill in the operators to make this equation work: ' . '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; $dd->generalfeedback = 'This sentence uses each letter of the alphabet.'; $dd->qtype = question_bank::get_qtype('ddimageortext'); $dd->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($dd); $dd->choices = $this->make_choice_structure(array(new qtype_ddimageortext_drag_item('+', 1, 1), new qtype_ddimageortext_drag_item('-', 2, 1))); $dd->places = $this->make_place_structure(array(new qtype_ddimageortext_drop_zone('', 1, 1), new qtype_ddimageortext_drop_zone('', 2, 1), new qtype_ddimageortext_drop_zone('', 3, 1), new qtype_ddimageortext_drop_zone('', 4, 1))); $dd->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); return $dd; }
/** * @return qtype_ddmarker_question */ public function make_ddmarker_question_maths() { question_bank::load_question_definition_classes('ddmarker'); $dd = new qtype_ddmarker_question(); test_question_maker::initialise_a_question($dd); $dd->name = 'Drag-and-drop markers question'; $dd->questiontext = 'Fill in the operators to make this equation work: '; $dd->generalfeedback = 'Hmmmm...'; $dd->qtype = question_bank::get_qtype('ddmarker'); $dd->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($dd); $dd->choices = $this->make_choice_structure(array(new qtype_ddmarker_drag_item('+', 1, 1), new qtype_ddmarker_drag_item('-', 2, 1), new qtype_ddmarker_drag_item('*', 3, 1), new qtype_ddmarker_drag_item('/', 4, 1))); $dd->places = $this->make_place_structure(array(new qtype_ddmarker_drop_zone(1, 'circle', '50,50;50'), new qtype_ddmarker_drop_zone(2, 'rectangle', '100,0;100,100'), new qtype_ddmarker_drop_zone(3, 'polygon', '0,100;100,100;100,200;0,200'))); $dd->rightchoices = array(1 => 1, 2 => 1, 3 => 1); return $dd; }
/** * Helper method to reduce duplication. * @return qtype_essay_question */ protected function initialise_essay_question() { question_bank::load_question_definition_classes('essay'); $q = new qtype_essay_question(); test_question_maker::initialise_a_question($q); $q->name = 'Essay question (HTML editor)'; $q->questiontext = 'Please write a story about a frog.'; $q->generalfeedback = 'I hope your story had a beginning, a middle and an end.'; $q->responseformat = 'editor'; $q->responsefieldlines = 10; $q->attachments = 0; $q->graderinfo = ''; $q->graderinfoformat = FORMAT_HTML; $q->qtype = question_bank::get_qtype('essay'); return $q; }
/** * @return qtype_gapselect_question */ public static function make_a_maths_gapselect_question() { question_bank::load_question_definition_classes('gapselect'); $gapselect = new qtype_gapselect_question(); test_question_maker::initialise_a_question($gapselect); $gapselect->name = 'Selection from drop down list question'; $gapselect->questiontext = 'Fill in the operators to make this equation work: ' . '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; $gapselect->qtype = question_bank::get_qtype('gapselect'); $gapselect->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($gapselect); $gapselect->choices = array(1 => array(1 => new qtype_gapselect_choice('+', 1, true), 2 => new qtype_gapselect_choice('-', 1, true), 3 => new qtype_gapselect_choice('*', 1, true), 4 => new qtype_gapselect_choice('/', 1, true))); $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1); $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3'); return $gapselect; }
/** * Makes a randomsamatch question similar to the match question returned * by {@link make_a_matching_question}, but with no 'insect' distractor. * @return qtype_randomsamatch_question */ public function make_randomsamatch_question_animals() { question_bank::load_question_definition_classes('randomsamatch'); $q = new qtype_randomsamatch_question(); test_question_maker::initialise_a_question($q); $q->name = 'Random shortanswer matching question'; $q->questiontext = 'Classify the animals.'; $q->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.'; $q->qtype = question_bank::get_qtype('randomsamatch'); test_question_maker::set_standard_combined_feedback_fields($q); $q->shufflestems = false; $q->stems = array(); $q->choices = array(); $q->right = array(); // Now we create 4 shortanswers question, // but we just fill the needed fields. question_bank::load_question_definition_classes('shortanswer'); $sa1 = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa1); $sa1->id = 25; $sa1->questiontext = 'Dog'; $sa1->answers = array(13 => new question_answer(13, 'Mammal', 1.0, 'Correct.', FORMAT_HTML), 14 => new question_answer(14, 'Animal', 0.5, 'There is a betterresponse.', FORMAT_HTML), 15 => new question_answer(15, '*', 0.0, 'That is a bad answer.', FORMAT_HTML)); $sa1->qtype = question_bank::get_qtype('shortanswer'); $sa2 = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa2); $sa2->id = 26; $sa2->questiontext = 'Frog'; $sa2->answers = array(16 => new question_answer(16, 'Amphibian', 1.0, 'Correct.', FORMAT_HTML), 17 => new question_answer(17, 'A Prince', 1.0, 'Maybe.', FORMAT_HTML), 18 => new question_answer(18, '*', 0.0, 'That is a bad answer.', FORMAT_HTML)); $sa2->qtype = question_bank::get_qtype('shortanswer'); $sa3 = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa3); $sa3->id = 27; $sa3->questiontext = 'Toad'; $sa3->answers = array(19 => new question_answer(19, 'Amphibian', 1.0, 'Correct.', FORMAT_HTML), 20 => new question_answer(20, '*', 0.0, 'That is a bad answer.', FORMAT_HTML)); $sa3->qtype = question_bank::get_qtype('shortanswer'); $sa4 = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa4); $sa4->id = 28; $sa4->questiontext = 'Cat'; $sa4->answers = array(21 => new question_answer(21, 'Mammal', 1.0, 'Correct.', FORMAT_HTML)); $sa4->qtype = question_bank::get_qtype('shortanswer'); $q->questionsloader = new qtype_randomsamatch_test_question_loader(array(), 4, array($sa1, $sa2, $sa3, $sa4)); return $q; }
/** * Makes a truefalse question with correct answer false. * @return qtype_truefalse_question */ public function make_truefalse_question_false() { question_bank::load_question_definition_classes('truefalse'); $tf = new qtype_truefalse_question(); test_question_maker::initialise_a_question($tf); $tf->name = 'True/false question'; $tf->questiontext = 'The answer is false.'; $tf->generalfeedback = 'You should have selected false.'; $tf->penalty = 1; $tf->qtype = question_bank::get_qtype('truefalse'); $tf->rightanswer = false; $tf->truefeedback = 'This is the wrong answer.'; $tf->falsefeedback = 'This is the right answer.'; $tf->truefeedbackformat = FORMAT_HTML; $tf->falsefeedbackformat = FORMAT_HTML; $tf->trueanswerid = 13; $tf->falseanswerid = 14; return $tf; }
/** * Makes a multianswer question about summing two numbers. * @return qtype_multianswer_question */ public function make_multianswer_question_twosubq() { question_bank::load_question_definition_classes('multianswer'); $q = new qtype_multianswer_question(); test_question_maker::initialise_a_question($q); $q->name = 'Simple multianswer'; $q->questiontext = 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; $q->generalfeedback = 'Generalfeedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' . '"The owl and the pussycat went to see'; $q->questiontextformat = FORMAT_HTML; $q->generalfeedbackformat = FORMAT_HTML; // Shortanswer subquestion. question_bank::load_question_definition_classes('shortanswer'); $sa = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa); $sa->name = 'Simple multianswer'; $sa->questiontext = '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}'; $sa->questiontextformat = FORMAT_HTML; $sa->generalfeedback = ''; $sa->generalfeedbackformat = FORMAT_HTML; $sa->usecase = true; $sa->answers = array(13 => new question_answer(13, 'Dog', 0.0, 'Wrong, silly!', FORMAT_HTML), 14 => new question_answer(14, 'Owl', 1.0, 'Well done!', FORMAT_HTML), 15 => new question_answer(15, '*', 0.0, 'Wrong answer', FORMAT_HTML)); $sa->qtype = question_bank::get_qtype('shortanswer'); $sa->maxmark = 1; // Multiple-choice subquestion. question_bank::load_question_definition_classes('multichoice'); $mc = new qtype_multichoice_single_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Simple multianswer'; $mc->questiontext = '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!' . '~Wiggly worm#Now you are just being rediculous!~=Pussy-cat#Well done!}'; $mc->questiontextformat = FORMAT_HTML; $mc->generalfeedback = ''; $mc->generalfeedbackformat = FORMAT_HTML; $mc->shuffleanswers = 1; $mc->answernumbering = 'none'; $mc->layout = qtype_multichoice_base::LAYOUT_DROPDOWN; $mc->answers = array(13 => new question_answer(13, 'Bow-wow', 0, 'You seem to have a dog obsessions!', FORMAT_HTML), 14 => new question_answer(14, 'Wiggly worm', 0, 'Now you are just being rediculous!', FORMAT_HTML), 15 => new question_answer(15, 'Pussy-cat', 1, 'Well done!', FORMAT_HTML)); $mc->qtype = question_bank::get_qtype('multichoice'); $mc->maxmark = 1; $q->subquestions = array(1 => $sa, 2 => $mc); return $q; }
/** * Makes a matching question to classify 'Dog', 'Frog', 'Toad' and 'Cat' as * 'Mammal', 'Amphibian' or 'Insect'. * defaultmark 1. Stems are shuffled by default. * @return qtype_match_question */ public static function make_a_ddmatching_question() { question_bank::load_question_definition_classes('ddmatch'); $ddmatch = new qtype_ddmatch_question(); test_question_maker::initialise_a_question($ddmatch); $ddmatch->name = 'Drag and drop matching question'; $ddmatch->questiontext = 'Classify the animals.'; $ddmatch->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.'; $ddmatch->qtype = question_bank::get_qtype('ddmatch'); $ddmatch->shufflestems = 1; test_question_maker::set_standard_combined_feedback_fields($ddmatch); // Using unset to get 1-based arrays. $ddmatch->stems = array('', 'Dog', 'Frog', 'Toad', 'Cat'); $ddmatch->stemformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML, FORMAT_HTML); $ddmatch->choices = array('', 'Mammal', 'Amphibian', 'Insect'); $ddmatch->choiceformat = array('', FORMAT_HTML, FORMAT_HTML, FORMAT_HTML); $ddmatch->right = array('', 1, 2, 2, 1); unset($ddmatch->stems[0]); unset($ddmatch->stemformat[0]); unset($ddmatch->choices[0]); unset($ddmatch->right[0]); return $ddmatch; }
public function make_deleted_instance($questionid, $maxmark) { question_bank::load_question_definition_classes('missingtype'); $question = new qtype_missingtype_question(); $question->id = $questionid; $question->category = null; $question->parent = 0; $question->qtype = question_bank::get_qtype('missingtype'); $question->name = get_string('deletedquestion', 'qtype_missingtype'); $question->questiontext = get_string('deletedquestiontext', 'qtype_missingtype'); $question->questiontextformat = FORMAT_HTML; $question->generalfeedback = ''; $question->defaultmark = $maxmark; $question->length = 1; $question->penalty = 0; $question->stamp = ''; $question->version = 0; $question->hidden = 0; $question->timecreated = null; $question->timemodified = null; $question->createdby = null; $question->modifiedby = null; return $question; }
/** * Create a fake question to be displayed in place of a question that is blocked * until the previous question has been answered. * * @param int $slot int slot number of the question to replace. * @return question_definition the placeholde question. */ protected function make_blocked_question_placeholder($slot) { $replacedquestion = $this->get_question_attempt($slot)->get_question(); question_bank::load_question_definition_classes('description'); $question = new qtype_description_question(); $question->id = $replacedquestion->id; $question->category = null; $question->parent = 0; $question->qtype = question_bank::get_qtype('description'); $question->name = ''; $question->questiontext = get_string('questiondependsonprevious', 'quiz'); $question->questiontextformat = FORMAT_HTML; $question->generalfeedback = ''; $question->defaultmark = $this->quba->get_question_max_mark($slot); $question->length = $replacedquestion->length; $question->penalty = 0; $question->stamp = ''; $question->version = 0; $question->hidden = 0; $question->timecreated = null; $question->timemodified = null; $question->createdby = null; $question->modifiedby = null; $placeholderqa = new question_attempt($question, $this->quba->get_id(), null, $this->quba->get_question_max_mark($slot)); $placeholderqa->set_slot($slot); $placeholderqa->start($this->get_quiz()->preferredbehaviour, 1); $placeholderqa->set_flagged($this->is_question_flagged($slot)); return $placeholderqa; }
public function test_export_numerical() { question_bank::load_question_definition_classes('numerical'); $qdata = new stdClass(); $qdata->id = 123; $qdata->contextid = 0; $qdata->qtype = 'numerical'; $qdata->name = 'Numerical question'; $qdata->questiontext = 'What is the answer?'; $qdata->questiontextformat = FORMAT_HTML; $qdata->generalfeedback = 'General feedback: Think Hitch-hikers guide to the Galaxy.'; $qdata->generalfeedbackformat = FORMAT_HTML; $qdata->defaultmark = 1; $qdata->length = 1; $qdata->penalty = 0.1; $qdata->hidden = 0; $qdata->options = new stdClass(); $qdata->options->answers = array( 13 => new qtype_numerical_answer(13, '42', 1, 'Well done!', FORMAT_HTML, 0.001), 14 => new qtype_numerical_answer(14, '13', 0, 'What were you thinking?!', FORMAT_HTML, 1), 15 => new qtype_numerical_answer(15, '*', 0, 'Completely wrong.', FORMAT_HTML, ''), ); $qdata->options->units = array(); $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); $expectedxml = '<!-- question: 123 --> <question type="numerical"> <name> <text>Numerical question</text> </name> <questiontext format="html"> <text>What is the answer?</text> </questiontext> <generalfeedback format="html"> <text>General feedback: Think Hitch-hikers guide to the Galaxy.</text> </generalfeedback> <defaultgrade>1</defaultgrade> <penalty>0.1</penalty> <hidden>0</hidden> <answer fraction="100" format="plain_text"> <text>42</text> <feedback format="html"> <text>Well done!</text> </feedback> <tolerance>0.001</tolerance> </answer> <answer fraction="0" format="plain_text"> <text>13</text> <feedback format="html"> <text>What were you thinking?!</text> </feedback> <tolerance>1</tolerance> </answer> <answer fraction="0" format="plain_text"> <text>*</text> <feedback format="html"> <text>Completely wrong.</text> </feedback> <tolerance>0</tolerance> </answer> </question> '; $this->assert_same_xml($expectedxml, $xml); }
/** * * @return qtype_matrix_question */ protected function make_matrix_question() { question_bank::load_question_definition_classes('matrix'); $result = new qtype_matrix_question(); test_question_maker::initialise_a_question($result); $result->name = 'Matrix question'; $result->questiontext = 'K prime graded question.'; $result->generalfeedback = 'First column is true.'; $result->penalty = 1; $result->qtype = question_bank::get_qtype('matrix'); $result->rows = array(); $result->cols = array(); $result->weights = array(); for ($r = 0; $r < 4; $r++) { $row = (object) array(); $row->id = $r; $row->shorttext = "Row {$r}"; $row->description = "Description {$r}"; $row->feedback = "Feedback {$r}"; $result->rows[$r] = $row; for ($c = 0; $c < 4; $c++) { $col = (object) array(); $col->id = $c; $col->shortext = "Column {$c}"; $col->description = "Description {$c}"; $result->cols[$c] = $col; $result->weights[$r][$c] = $c == 0 ? 1 : 0; } } $result->grademethod = 'kprime'; $result->multiple = true; return $result; }
/** * Create an appropriate question_definition for the question of this type * using data loaded from the database. * @param object $questiondata the question data loaded from the database. * @return question_definition an instance of the appropriate question_definition subclass. * Still needs to be initialised. */ protected function make_question_instance($questiondata) { question_bank::load_question_definition_classes($this->name()); $class = 'qtype_' . $this->name() . '_question'; return new $class(); }
/** * Makes a truefalse question with correct ansewer true, defaultmark 1. * @return qtype_essay_question */ public static function make_an_essay_question() { question_bank::load_question_definition_classes('essay'); $essay = new qtype_essay_question(); self::initialise_a_question($essay); $essay->name = 'Essay question'; $essay->questiontext = 'Write an essay.'; $essay->generalfeedback = 'I hope you wrote an interesting essay.'; $essay->penalty = 0; $essay->qtype = question_bank::get_qtype('essay'); $essay->responseformat = 'editor'; $essay->responserequired = 1; $essay->responsefieldlines = 15; $essay->attachments = 0; $essay->attachmentsrequired = 0; $essay->responsetemplate = ''; $essay->responsetemplateformat = FORMAT_MOODLE; $essay->graderinfo = ''; $essay->graderinfoformat = FORMAT_MOODLE; return $essay; }
/** * Makes a numerical question with correct ansewer 3.14, and various incorrect * answers with different feedback. * @return qtype_numerical_question */ public function make_numerical_question_currency() { question_bank::load_question_definition_classes('numerical'); $num = new qtype_numerical_question(); test_question_maker::initialise_a_question($num); $num->name = 'Add money'; $num->questiontext = 'What is $666 + $666?'; $num->generalfeedback = 'Generalfeedback: $1,332 is the right answer.'; $num->answers = array(13 => new qtype_numerical_answer(13, '1332', 1.0, 'Very good.', FORMAT_HTML, 0), 14 => new qtype_numerical_answer(14, '*', 0.0, 'Wrong.', FORMAT_HTML, 0)); $num->qtype = question_bank::get_qtype('numerical'); $num->unitdisplay = qtype_numerical::UNITINPUT; $num->unitgradingtype = qtype_numerical::UNITGRADEDOUTOFMAX; $num->unitpenalty = 0.2; $num->ap = new qtype_numerical_answer_processor(array('$' => 1), true); return $num; }
/** * Makes a multianswer question with multichoice_multiple questions in it. * @return qtype_multianswer_question */ public function make_multianswer_question_multiple() { question_bank::load_question_definition_classes('multianswer'); $q = new qtype_multianswer_question(); test_question_maker::initialise_a_question($q); $q->name = 'Multichoice multiple'; $q->questiontext = 'Please select the fruits {#1} and vegetables {#2}'; $q->generalfeedback = 'You should know which foods are fruits or vegetables.'; $q->qtype = question_bank::get_qtype('multianswer'); $q->textfragments = array('Please select the fruits ', ' and vegetables ', ''); $q->places = array('1' => '1', '2' => '2'); // Multiple-choice subquestion. question_bank::load_question_definition_classes('multichoice'); $mc = new qtype_multichoice_multi_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Multianswer 1'; $mc->questiontext = '{1:MULTIRESPONSE:=Apple#Good~%-50%Burger~%-50%Hot dog#Not a fruit~%-50%Pizza' . '~=Orange#Correct~=Banana}'; $mc->questiontextformat = FORMAT_HTML; $mc->generalfeedback = ''; $mc->generalfeedbackformat = FORMAT_HTML; $mc->shuffleanswers = 0; $mc->answernumbering = 'none'; $mc->layout = qtype_multichoice_base::LAYOUT_VERTICAL; $mc->single = 0; $mc->answers = array(16 => new question_answer(16, 'Apple', 0.3333333, 'Good', FORMAT_HTML), 17 => new question_answer(17, 'Burger', -0.5, '', FORMAT_HTML), 18 => new question_answer(18, 'Hot dog', -0.5, 'Not a fruit', FORMAT_HTML), 19 => new question_answer(19, 'Pizza', -0.5, '', FORMAT_HTML), 20 => new question_answer(20, 'Orange', 0.3333333, 'Correct', FORMAT_HTML), 21 => new question_answer(21, 'Banana', 0.3333333, '', FORMAT_HTML)); $mc->qtype = question_bank::get_qtype('multichoice'); $mc->maxmark = 1; // Multiple-choice subquestion. question_bank::load_question_definition_classes('multichoice'); $mc2 = new qtype_multichoice_multi_question(); test_question_maker::initialise_a_question($mc2); $mc2->name = 'Multichoice 2'; $mc2->questiontext = '{1:MULTIRESPONSE:=Raddish#Good~%-50%Chocolate~%-50%Biscuit#Not a vegetable~%-50%Cheese' . '~=Carrot#Correct}'; $mc2->questiontextformat = FORMAT_HTML; $mc2->generalfeedback = ''; $mc2->generalfeedbackformat = FORMAT_HTML; $mc2->shuffleanswers = 0; $mc2->answernumbering = 'none'; $mc2->layout = qtype_multichoice_base::LAYOUT_VERTICAL; $mc2->single = 0; $mc2->answers = array(22 => new question_answer(22, 'Raddish', 0.5, 'Good', FORMAT_HTML), 23 => new question_answer(23, 'Chocolate', -0.5, '', FORMAT_HTML), 24 => new question_answer(24, 'Biscuit', -0.5, 'Not a vegetable', FORMAT_HTML), 25 => new question_answer(25, 'Cheese', -0.5, '', FORMAT_HTML), 26 => new question_answer(26, 'Carrot', 0.5, 'Correct', FORMAT_HTML)); $mc2->qtype = question_bank::get_qtype('multichoice'); $mc2->maxmark = 1; $q->subquestions = array(1 => $mc, 2 => $mc2); return $q; }
private function make_coderunner_question($type, $name = '', $questionText = '', $testcases, $otherOptions = array()) { question_bank::load_question_definition_classes('coderunner'); $coderunner = new qtype_coderunner_question(); test_question_maker::initialise_a_question($coderunner); $coderunner->qtype = question_bank::get_qtype('coderunner'); $coderunner->coderunnertype = $type; $coderunner->prototypetype = 0; $coderunner->name = $name; $coderunner->useace = true; $coderunner->questiontext = $questionText; $coderunner->allornothing = true; $coderunner->showsource = false; $coderunner->generalfeedback = 'No feedback available for coderunner questions.'; $coderunner->unitpenalty = 0.2; $coderunner->customise = false; $coderunner->testcases = self::make_test_cases($testcases); $coderunner->options = array(); $coderunner->isnew = true; // Extra field normally added by save_question $coderunner->context = context_system::instance(); // Use system context for testing foreach ($otherOptions as $key => $value) { $coderunner->options[$key] = $value; } $this->get_options($coderunner); return $coderunner; }
/** * Makes a multianswer question with one numerical subquestion, right answer 0. * This is used for testing the MDL-35370 bug. * @return qtype_multianswer_question */ public function make_multianswer_question_numericalzero() { question_bank::load_question_definition_classes('multianswer'); $q = new qtype_multianswer_question(); test_question_maker::initialise_a_question($q); $q->name = 'Numerical zero'; $q->questiontext = 'Enter zero: {#1}.'; $q->generalfeedback = ''; $q->qtype = question_bank::get_qtype('multianswer'); $q->textfragments = array('Enter zero: ', '.'); $q->places = array('1' => '1'); // Numerical subquestion. question_bank::load_question_definition_classes('numerical'); $sub = new qtype_numerical_question(); test_question_maker::initialise_a_question($sub); $sub->name = 'Numerical zero'; $sub->questiontext = '{1:NUMERICAL:=0:0}'; $sub->questiontextformat = FORMAT_HTML; $sub->generalfeedback = ''; $sub->generalfeedbackformat = FORMAT_HTML; $sub->answers = array(13 => new qtype_numerical_answer(13, '0', 1.0, '', FORMAT_HTML, 0)); $sub->qtype = question_bank::get_qtype('numerical'); $sub->ap = new qtype_numerical_answer_processor(array()); $sub->maxmark = 1; $q->subquestions = array(1 => $sub); return $q; }
/** * Makes a transcription question with just the correct ansewer 'frog', and * no other answer matching. * @return qtype_transcription_question */ public function make_transcription_question_escapedwildcards() { question_bank::load_question_definition_classes('transcription'); $sa = new qtype_transcription_question(); test_question_maker::initialise_a_question($sa); $sa->name = 'Question with escaped * in the answer.'; $sa->questiontext = 'How to you write x times y in C? __________'; $sa->generalfeedback = 'In C, this expression is written x * y.'; $sa->usecase = false; $sa->answers = array(13 => new question_answer(13, '*x\\*y*', 1.0, 'Well done.', FORMAT_HTML)); $sa->qtype = question_bank::get_qtype('transcription'); return $sa; }
/** * Makes a calculated question about summing two numbers. * @return qtype_calculated_question */ public function get_calculated_question_form_data_sum() { question_bank::load_question_definition_classes('calculated'); $fromform = new stdClass(); $fromform->name = 'Simple sum'; $fromform->questiontext = 'What is {a} + {b}?'; $fromform->defaultmark = 1.0; $fromform->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $fromform->unitrole = '3'; $fromform->unitpenalty = 0.1; $fromform->unitgradingtypes = '1'; $fromform->unitsleft = '0'; $fromform->nounits = 1; $fromform->multiplier = array(); $fromform->multiplier[0] = '1.0'; $fromform->synchronize = 0; $fromform->answernumbering = 0; $fromform->shuffleanswers = 0; $fromform->noanswers = 6; $fromform->answer = array(); $fromform->answer[0] = '{a} + {b}'; $fromform->answer[1] = '{a} - {b}'; $fromform->answer[2] = '*'; $fromform->fraction = array(); $fromform->fraction[0] = '1.0'; $fromform->fraction[1] = '0.0'; $fromform->fraction[2] = '0.0'; $fromform->tolerance = array(); $fromform->tolerance[0] = 0.001; $fromform->tolerance[1] = 0.001; $fromform->tolerance[2] = 0; $fromform->tolerancetype[0] = 1; $fromform->tolerancetype[1] = 1; $fromform->tolerancetype[2] = 1; $fromform->correctanswerlength[0] = 2; $fromform->correctanswerlength[1] = 2; $fromform->correctanswerlength[2] = 2; $fromform->correctanswerformat[0] = 1; $fromform->correctanswerformat[1] = 1; $fromform->correctanswerformat[2] = 1; $fromform->feedback = array(); $fromform->feedback[0] = array(); $fromform->feedback[0]['format'] = FORMAT_HTML; $fromform->feedback[0]['text'] = 'Very good.'; $fromform->feedback[1] = array(); $fromform->feedback[1]['format'] = FORMAT_HTML; $fromform->feedback[1]['text'] = 'Add. not subtract!'; $fromform->feedback[2] = array(); $fromform->feedback[2]['format'] = FORMAT_HTML; $fromform->feedback[2]['text'] = 'Completely wrong.'; return $fromform; }
protected function make_question_instance($questiondata) { question_bank::load_question_definition_classes($this->name()); if ($questiondata->options->single) { $class = 'qtype_turmultiplechoice_single_question'; } else { $class = 'qtype_turmultiplechoice_multi_question'; } return new $class(); }