Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/calculated/simpletest/testquestiontype.php
Go to the documentation of this file.
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 
00026 defined('MOODLE_INTERNAL') || die();
00027 
00028 require_once($CFG->dirroot . '/question/type/calculated/questiontype.php');
00029 
00030 
00037 class qtype_calculated_test extends UnitTestCase {
00038     public static $includecoverage = array(
00039         'question/type/questiontypebase.php',
00040         'question/type/calculated/questiontype.php'
00041     );
00042 
00043     protected $tolerance = 0.00000001;
00044     protected $qtype;
00045 
00046     public function setUp() {
00047         $this->qtype = new qtype_calculated();
00048     }
00049 
00050     public function tearDown() {
00051         $this->qtype = null;
00052     }
00053 
00054     public function test_name() {
00055         $this->assertEqual($this->qtype->name(), 'calculated');
00056     }
00057 
00058     public function test_can_analyse_responses() {
00059         $this->assertTrue($this->qtype->can_analyse_responses());
00060     }
00061 
00062     public function test_get_random_guess_score() {
00063         $q = test_question_maker::get_question_data('calculated');
00064         $q->options->answers[17]->fraction = 0.1;
00065         $this->assertEqual(0.1, $this->qtype->get_random_guess_score($q));
00066     }
00067 
00068     protected function get_possible_response($ans, $tolerance, $type) {
00069         $a = new stdClass();
00070         $a->answer = $ans;
00071         $a->tolerance = $tolerance;
00072         $a->tolerancetype = get_string($type, 'qtype_numerical');
00073         return get_string('answerwithtolerance', 'qtype_calculated', $a);
00074     }
00075 
00076     public function test_get_possible_responses() {
00077         $q = test_question_maker::get_question_data('calculated');
00078 
00079         $this->assertEqual(array(
00080             $q->id => array(
00081                 13 => new question_possible_response(
00082                         $this->get_possible_response('{a} + {b}', 0.001, 'nominal'), 1.0),
00083                 14 => new question_possible_response(
00084                         $this->get_possible_response('{a} - {b}', 0.001, 'nominal'), 0.0),
00085                 17 => new question_possible_response('*', 0.0),
00086                 null => question_possible_response::no_response()
00087             ),
00088         ), $this->qtype->get_possible_responses($q));
00089     }
00090 
00091     public function test_get_possible_responses_no_star() {
00092         $q = test_question_maker::get_question_data('calculated');
00093         unset($q->options->answers[17]);
00094 
00095         $this->assertEqual(array(
00096             $q->id => array(
00097                 13 => new question_possible_response(
00098                         $this->get_possible_response('{a} + {b}', 0.001, 'nominal'), 1),
00099                 14 => new question_possible_response(
00100                         $this->get_possible_response('{a} - {b}', 0.001, 'nominal'), 0),
00101                 0  => new question_possible_response(
00102                         get_string('didnotmatchanyanswer', 'question'), 0),
00103                 null => question_possible_response::no_response()
00104             ),
00105         ), $this->qtype->get_possible_responses($q));
00106     }
00107 }
 All Data Structures Namespaces Files Functions Variables Enumerations