|
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/type/shortanswer/questiontype.php'); 00030 require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php'); 00031 00032 00039 class qtype_shortanswer_test extends UnitTestCase { 00040 public static $includecoverage = array( 00041 'question/type/questiontypebase.php', 00042 'question/type/shortanswer/questiontype.php', 00043 ); 00044 00045 protected $qtype; 00046 00047 public function setUp() { 00048 $this->qtype = new qtype_shortanswer(); 00049 } 00050 00051 public function tearDown() { 00052 $this->qtype = null; 00053 } 00054 00055 protected function get_test_question_data() { 00056 return test_question_maker::get_question_data('shortanswer'); 00057 } 00058 00059 public function test_name() { 00060 $this->assertEqual($this->qtype->name(), 'shortanswer'); 00061 } 00062 00063 public function test_can_analyse_responses() { 00064 $this->assertTrue($this->qtype->can_analyse_responses()); 00065 } 00066 00067 public function test_get_random_guess_score() { 00068 $q = test_question_maker::get_question_data('shortanswer'); 00069 $q->options->answers[15]->fraction = 0.1; 00070 $this->assertEqual(0.1, $this->qtype->get_random_guess_score($q)); 00071 } 00072 00073 public function test_get_possible_responses() { 00074 $q = test_question_maker::get_question_data('shortanswer'); 00075 00076 $this->assertEqual(array( 00077 $q->id => array( 00078 13 => new question_possible_response('frog', 1), 00079 14 => new question_possible_response('toad', 0.8), 00080 15 => new question_possible_response('*', 0), 00081 null => question_possible_response::no_response() 00082 ), 00083 ), $this->qtype->get_possible_responses($q)); 00084 } 00085 00086 public function test_get_possible_responses_no_star() { 00087 $q = test_question_maker::get_question_data('shortanswer', 'frogonly'); 00088 00089 $this->assertEqual(array( 00090 $q->id => array( 00091 13 => new question_possible_response('frog', 1), 00092 0 => new question_possible_response(get_string('didnotmatchanyanswer', 'question'), 0), 00093 null => question_possible_response::no_response() 00094 ), 00095 ), $this->qtype->get_possible_responses($q)); 00096 } 00097 }