|
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/numerical/questiontype.php'); 00030 00031 00038 class qtype_numerical_test extends UnitTestCase { 00039 public static $includecoverage = array( 00040 'question/type/questiontypebase.php', 00041 'question/type/numerical/questiontype.php' 00042 ); 00043 00044 protected $tolerance = 0.00000001; 00045 protected $qtype; 00046 00047 public function setUp() { 00048 $this->qtype = new qtype_numerical(); 00049 } 00050 00051 public function tearDown() { 00052 $this->qtype = null; 00053 } 00054 00055 protected function get_test_question_data() { 00056 $q = new stdClass; 00057 $q->id = 1; 00058 $q->options->unitpenalty = 0; 00059 $q->options->answers[13] = (object) array( 00060 'id' => 13, 00061 'answer' => 42, 00062 'fraction' => 1, 00063 'feedback' => 'yes', 00064 'feedbackformat' => FORMAT_MOODLE, 00065 'tolerance' => 0.5 00066 ); 00067 $q->options->answers[14] = (object) array( 00068 'id' => 14, 00069 'answer' => '*', 00070 'fraction' => 0.1, 00071 'feedback' => 'no', 00072 'feedbackformat' => FORMAT_MOODLE, 00073 'tolerance' => '' 00074 ); 00075 00076 $q->options->units = array( 00077 (object) array('unit' => 'm', 'multiplier' => 1), 00078 (object) array('unit' => 'cm', 'multiplier' => 0.01) 00079 ); 00080 00081 return $q; 00082 } 00083 00084 public function test_name() { 00085 $this->assertEqual($this->qtype->name(), 'numerical'); 00086 } 00087 00088 public function test_can_analyse_responses() { 00089 $this->assertTrue($this->qtype->can_analyse_responses()); 00090 } 00091 00092 public function test_get_random_guess_score() { 00093 $q = $this->get_test_question_data(); 00094 $this->assertEqual(0.1, $this->qtype->get_random_guess_score($q)); 00095 } 00096 00097 public function test_get_possible_responses() { 00098 $q = $this->get_test_question_data(); 00099 00100 $this->assertEqual(array( 00101 $q->id => array( 00102 13 => new question_possible_response('42 m (41.5..42.5)', 1), 00103 14 => new question_possible_response('*', 0.1), 00104 null => question_possible_response::no_response() 00105 ), 00106 ), $this->qtype->get_possible_responses($q)); 00107 } 00108 00109 public function test_get_possible_responses_no_star() { 00110 $q = $this->get_test_question_data(); 00111 unset($q->options->answers[14]); 00112 00113 $this->assertEqual(array( 00114 $q->id => array( 00115 13 => new question_possible_response('42 m (41.5..42.5)', 1), 00116 0 => new question_possible_response( 00117 get_string('didnotmatchanyanswer', 'question'), 0), 00118 null => question_possible_response::no_response() 00119 ), 00120 ), $this->qtype->get_possible_responses($q)); 00121 } 00122 }