|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php'); 00030 require_once($CFG->dirroot . '/question/type/multianswer/questiontype.php'); 00031 00032 00039 class qtype_multianswer_test extends UnitTestCase { 00041 protected $qtype; 00042 00043 public function setUp() { 00044 $this->qtype = new qtype_multianswer(); 00045 } 00046 00047 public function tearDown() { 00048 $this->qtype = null; 00049 } 00050 00051 protected function get_test_question_data() { 00052 global $USER; 00053 $q = new stdClass(); 00054 $q->id = 0; 00055 $q->name = 'Simple multianswer'; 00056 $q->category = 0; 00057 $q->contextid = 0; 00058 $q->parent = 0; 00059 $q->questiontext = 00060 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; 00061 $q->questiontextformat = FORMAT_HTML; 00062 $q->generalfeedback = 'Generalfeedback: It\'s from "The Owl and the Pussy-cat" by Lear: ' . 00063 '"The owl and the pussycat went to see'; 00064 $q->generalfeedbackformat = FORMAT_HTML; 00065 $q->defaultmark = 2; 00066 $q->penalty = 0.3333333; 00067 $q->length = 1; 00068 $q->stamp = make_unique_id_code(); 00069 $q->version = make_unique_id_code(); 00070 $q->hidden = 0; 00071 $q->timecreated = time(); 00072 $q->timemodified = time(); 00073 $q->createdby = $USER->id; 00074 $q->modifiedby = $USER->id; 00075 00076 $sadata = new stdClass(); 00077 $sadata->id = 1; 00078 $sadata->qtype = 'shortanswer'; 00079 $sadata->defaultmark = 1; 00080 $sadata->options->usecase = true; 00081 $sadata->options->answers[1] = (object) array('answer' => 'Bow-wow', 'fraction' => 0); 00082 $sadata->options->answers[2] = (object) array('answer' => 'Wiggly worm', 'fraction' => 0); 00083 $sadata->options->answers[3] = (object) array('answer' => 'Pussy-cat', 'fraction' => 1); 00084 00085 $mcdata = new stdClass(); 00086 $mcdata->id = 1; 00087 $mcdata->qtype = 'multichoice'; 00088 $mcdata->defaultmark = 1; 00089 $mcdata->options->single = true; 00090 $mcdata->options->answers[1] = (object) array('answer' => 'Dog', 'fraction' => 0); 00091 $mcdata->options->answers[2] = (object) array('answer' => 'Owl', 'fraction' => 1); 00092 $mcdata->options->answers[3] = (object) array('answer' => '*', 'fraction' => 0); 00093 00094 $q->options->questions = array( 00095 1 => $sadata, 00096 2 => $mcdata, 00097 ); 00098 00099 return $q; 00100 } 00101 00102 public function test_name() { 00103 $this->assertEqual($this->qtype->name(), 'multianswer'); 00104 } 00105 00106 public function test_can_analyse_responses() { 00107 $this->assertFalse($this->qtype->can_analyse_responses()); 00108 } 00109 00110 public function test_get_random_guess_score() { 00111 $q = test_question_maker::get_question_data('multianswer', 'twosubq'); 00112 $this->assertWithinMargin(0.1666667, $this->qtype->get_random_guess_score($q), 0.0000001); 00113 } 00114 }