See Release Notes
Long Term Support Release
Differences Between: [Versions 401 and 402] [Versions 401 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Test helpers for the calculated question type. 19 * 20 * @package qtype 21 * @subpackage calculatedmulti 22 * @copyright 2011 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 global $CFG; 30 require_once($CFG->dirroot . '/question/type/calculatedmulti/question.php'); 31 require_once($CFG->dirroot . '/question/type/calculated/tests/helper.php'); 32 33 /** 34 * Test helper class for the calculated multiple-choice question type. 35 * 36 * @copyright 2011 The Open University 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class qtype_calculatedmulti_test_helper extends question_test_helper { 40 public function get_test_questions() { 41 return array('singleresponse', 'multiresponse'); 42 } 43 44 /** 45 * Makes a calculated multiple-choice question about summing two numbers. 46 * @return qtype_calculatedmulti_single_question 47 */ 48 public function make_calculatedmulti_question_singleresponse() { 49 question_bank::load_question_definition_classes('calculated'); 50 $q = new qtype_calculatedmulti_single_question(); 51 test_question_maker::initialise_a_question($q); 52 $q->name = 'Simple sum'; 53 $q->questiontext = 'What is {a} + {b}?'; 54 $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; 55 $q->shuffleanswers = 0; 56 $q->answernumbering = 'abc'; 57 $q->layout = 1; 58 $q->correctfeedback = test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK; 59 $q->correctfeedbackformat = FORMAT_HTML; 60 $q->partiallycorrectfeedback = test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK; 61 $q->partiallycorrectfeedbackformat = FORMAT_HTML; 62 $q->shownumcorrect = 1; 63 $q->incorrectfeedback = test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK; 64 $q->incorrectfeedbackformat = FORMAT_HTML; 65 $q->shownumcorrect = 1; 66 $q->answers = array( 67 13 => new question_answer(13, '{={a} + {b}}', 1.0, 'Very good.', FORMAT_HTML), 68 14 => new question_answer(14, '{={a} - {b}}', 0.0, 'Add. not subtract!', FORMAT_HTML), 69 17 => new question_answer(17, '{={a} + 2 * {b}}', 0.0, 'Just add.', FORMAT_HTML), 70 ); 71 $q->answers[13]->correctanswerlength = 2; 72 $q->answers[13]->correctanswerformat = 1; 73 $q->answers[14]->correctanswerlength = 2; 74 $q->answers[14]->correctanswerformat = 1; 75 $q->answers[17]->correctanswerlength = 2; 76 $q->answers[17]->correctanswerformat = 1; 77 $q->qtype = question_bank::get_qtype('calculatedmulti'); 78 79 $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( 80 array('a' => 1, 'b' => 5), 81 array('a' => 3, 'b' => 4), 82 )); 83 84 return $q; 85 } 86 87 /** 88 * Makes a calculated multiple-choice question with multiple right answers. 89 * @return qtype_calculatedmulti_multi_question 90 */ 91 public function make_calculatedmulti_question_multiresponse() { 92 question_bank::load_question_definition_classes('calculated'); 93 $q = new qtype_calculatedmulti_multi_question(); 94 test_question_maker::initialise_a_question($q); 95 $q->name = 'Simple sum'; 96 $q->questiontext = 'What is {a} + {b}?'; 97 $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; 98 $q->shuffleanswers = 0; 99 $q->answernumbering = 'abc'; 100 $q->layout = 1; 101 $q->correctfeedback = test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK; 102 $q->correctfeedbackformat = FORMAT_HTML; 103 $q->partiallycorrectfeedback = test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK; 104 $q->partiallycorrectfeedbackformat = FORMAT_HTML; 105 $q->shownumcorrect = 1; 106 $q->incorrectfeedback = test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK; 107 $q->incorrectfeedbackformat = FORMAT_HTML; 108 $q->shownumcorrect = 1; 109 $q->answers = array( 110 13 => new qtype_numerical_answer(13, '{a} + {b}!', 0.5, 'Good', FORMAT_HTML, 0), 111 14 => new qtype_numerical_answer(14, '{={a} + {b}}', 0.5, 'Good', 112 FORMAT_HTML, 0), 113 17 => new qtype_numerical_answer(17, '{={a} - {b}}', -0.5, 'Wrong.', FORMAT_HTML, 0), 114 ); 115 $q->answers[13]->correctanswerlength = 2; 116 $q->answers[13]->correctanswerformat = 1; 117 $q->answers[14]->correctanswerlength = 2; 118 $q->answers[14]->correctanswerformat = 1; 119 $q->answers[17]->correctanswerlength = 2; 120 $q->answers[17]->correctanswerformat = 1; 121 $q->qtype = question_bank::get_qtype('calculatedmulti'); 122 123 $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( 124 array('a' => 1, 'b' => 5), 125 array('a' => 3, 'b' => 4), 126 )); 127 128 return $q; 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body