/** * 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; }
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); }
/** * Does the basical initialisation of a new Stack question that all the test * questions will need. * @return qtype_stack_question the new question. */ protected static function make_a_stack_question() { question_bank::load_question_definition_classes('stack'); $q = new qtype_stack_question(); test_question_maker::initialise_a_question($q); $q->qtype = question_bank::get_qtype('stack'); $q->contextid = context_system::instance()->id; $q->questionvariables = ''; $q->specificfeedback = ''; $q->specificfeedbackformat = FORMAT_HTML; $q->penalty = 0.1; // The default. $q->prtcorrect = self::DEFAULT_CORRECT_FEEDBACK; $q->prtcorrectformat = FORMAT_HTML; $q->prtpartiallycorrect = self::DEFAULT_PARTIALLYCORRECT_FEEDBACK; $q->prtpartiallycorrectformat = FORMAT_HTML; $q->prtincorrect = self::DEFAULT_INCORRECT_FEEDBACK; $q->prtincorrectformat = FORMAT_HTML; $q->generalfeedback = ''; $q->variantsselectionseed = ''; $q->inputs = array(); $q->prts = array(); $q->options = new stack_options(); $q->questionnote = ''; return $q; }
/** * @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 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; }
/** * @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; }
/** * 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_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; }
private function make_sqr_user_type_prototype($fileAttachmentReqd = false) { global $DB; $q = $this->make_question('sqr'); $q->test_cases = array(); // No testcases in a prototype $q->customise = 1; $q->prototypetype = 2; $q->typename = "sqr_user_prototype"; $q->cputimelimitsecs = 179; // Silly test value $q->combinatortemplate = 'combinatortemplatevalue'; // Save the prototype to the DB so it has an accessible context for // retrieving associated files. All we need is its id and // its category, but the DB has other required fields so we dummy // up a minimal question containing the right category, at least. question_bank::load_question_definition_classes('coderunner'); $row = new qtype_coderunner_question(); test_question_maker::initialise_a_question($row); $catRow = $DB->get_record_select('question_categories', "contextid=1 limit 1"); $row->category = $catRow->id; $row->qtype = 'qtype_coderunner'; $row->contextid = 1; foreach (array('id', 'name', 'questiontext', 'generalfeedback') as $key) { $row->{$key} = $q->{$key}; } $q->id = $DB->insert_record('question', $row); $qtype = new qtype_coderunner(); $qtype->save_question_options($q); if ($fileAttachmentReqd) { // Attach a file. $fs = get_file_storage(); $fileinfo = array('contextid' => 1, 'component' => 'qtype_coderunner', 'filearea' => 'datafile', 'itemid' => $q->id, 'filepath' => '/', 'filename' => 'data.txt'); // Create file $fs->create_file_from_string($fileinfo, "This is data\nLine 2"); } return $q->id; }
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; }
/** * * @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; }
/** * 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; }
/** * 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 multianswer question about completing two blanks in some text. * @return qtype_multianswer_question */ public function make_multianswer_question_fourmc() { question_bank::load_question_definition_classes('multianswer'); $q = new qtype_multianswer_question(); test_question_maker::initialise_a_question($q); $q->name = 'Multianswer four multi-choice'; $q->questiontext = '<p>Match the following cities with the correct state:</p> <ul> <li>San Francisco: {#1}</li> <li>Tucson: {#2}</li> <li>Los Angeles: {#3}</li> <li>Phoenix: {#4}</li> </ul>'; $q->questiontextformat = FORMAT_HTML; $q->generalfeedback = ''; $q->qtype = question_bank::get_qtype('multianswer'); $q->textfragments = array('<p>Match the following cities with the correct state:</p> <ul> <li>San Francisco: ', '</li> <li>Tucson: ', '</li> <li>Los Angeles: ', '</li> <li>Phoenix: ', '</li> </ul>'); $q->places = array('1' => '1', '2' => '2', '3' => '3', '4' => '4'); $subqdata = array( 1 => array('qt' => '{1:MULTICHOICE:=California#OK~Arizona#Wrong}', 'California' => 'OK', 'Arizona' => 'Wrong'), 2 => array('qt' => '{1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}', 'California' => 'Wrong', 'Arizona' => 'OK'), 3 => array('qt' => '{1:MULTICHOICE:=California#OK~Arizona#Wrong}', 'California' => 'OK', 'Arizona' => 'Wrong'), 4 => array('qt' => '{1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}', 'California' => 'Wrong', 'Arizona' => 'OK'), ); foreach ($subqdata as $i => $data) { // 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 = 'Multianswer four multi-choice'; $mc->questiontext = $data['qt']; $mc->questiontextformat = FORMAT_HTML; $mc->generalfeedback = ''; $mc->generalfeedbackformat = FORMAT_HTML; $mc->shuffleanswers = 0; // TODO this is a cheat to make the unit tests easier to write. // In reality, multianswer questions always shuffle. $mc->answernumbering = 'none'; $mc->layout = qtype_multichoice_base::LAYOUT_DROPDOWN; $mc->answers = array( 10 * $i => new question_answer(13, 'California', $data['California'] == 'OK', $data['California'], FORMAT_HTML), 10 * $i + 1 => new question_answer(14, 'Arizona', $data['Arizona'] == 'OK', $data['Arizona'], FORMAT_HTML), ); $mc->qtype = question_bank::get_qtype('multichoice'); $mc->maxmark = 1; $q->subquestions[$i] = $mc; } 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 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 shortanswer question with just the correct ansewer 'frog', and * no other answer matching. * @return qtype_shortanswer_question */ public function make_shortanswer_question_frogonly() { question_bank::load_question_definition_classes('shortanswer'); $sa = new qtype_shortanswer_question(); test_question_maker::initialise_a_question($sa); $sa->name = 'Short answer question'; $sa->questiontext = 'Name the best amphibian: __________'; $sa->generalfeedback = 'Generalfeedback: you should have said frog.'; $sa->usecase = false; $sa->answers = array( 13 => new question_answer(13, 'frog', 1.0, 'Frog is right.', FORMAT_HTML), ); $sa->qtype = question_bank::get_qtype('shortanswer'); return $sa; }