[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Unit tests for (some of) question/type/calculated/questiontype.php. 19 * 20 * @package qtype_calculated 21 * @copyright 2012 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->dirroot . '/question/type/calculated/questiontype.php'); 30 require_once($CFG->dirroot . '/question/type/calculated/tests/helper.php'); 31 32 33 /** 34 * Unit tests for question/type/calculated/questiontype.php. 35 * 36 * @copyright 2012 The Open University 37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 38 */ 39 class qtype_calculated_test extends advanced_testcase { 40 public static $includecoverage = array( 41 'question/type/questiontypebase.php', 42 'question/type/calculated/questiontype.php' 43 ); 44 45 protected $tolerance = 0.00000001; 46 protected $qtype; 47 48 protected function setUp() { 49 $this->qtype = new qtype_calculated(); 50 } 51 52 protected function tearDown() { 53 $this->qtype = null; 54 } 55 56 public function test_name() { 57 $this->assertEquals($this->qtype->name(), 'calculated'); 58 } 59 60 public function test_can_analyse_responses() { 61 $this->assertTrue($this->qtype->can_analyse_responses()); 62 } 63 64 public function test_get_random_guess_score() { 65 $q = test_question_maker::get_question_data('calculated'); 66 $q->options->answers[17]->fraction = 0.1; 67 $this->assertEquals(0.1, $this->qtype->get_random_guess_score($q)); 68 } 69 70 protected function get_possible_response($ans, $tolerance, $type) { 71 $a = new stdClass(); 72 $a->answer = $ans; 73 $a->tolerance = $tolerance; 74 $a->tolerancetype = get_string($type, 'qtype_numerical'); 75 return get_string('answerwithtolerance', 'qtype_calculated', $a); 76 } 77 78 public function test_get_possible_responses() { 79 $q = test_question_maker::get_question_data('calculated'); 80 81 $this->assertEquals(array( 82 $q->id => array( 83 13 => new question_possible_response( 84 $this->get_possible_response('{a} + {b}', 0.001, 'nominal'), 1.0), 85 14 => new question_possible_response( 86 $this->get_possible_response('{a} - {b}', 0.001, 'nominal'), 0.0), 87 17 => new question_possible_response('*', 0.0), 88 null => question_possible_response::no_response() 89 ), 90 ), $this->qtype->get_possible_responses($q)); 91 } 92 93 public function test_get_possible_responses_no_star() { 94 $q = test_question_maker::get_question_data('calculated'); 95 unset($q->options->answers[17]); 96 97 $this->assertEquals(array( 98 $q->id => array( 99 13 => new question_possible_response( 100 $this->get_possible_response('{a} + {b}', 0.001, 'nominal'), 1), 101 14 => new question_possible_response( 102 $this->get_possible_response('{a} - {b}', 0.001, 'nominal'), 0), 103 0 => new question_possible_response( 104 get_string('didnotmatchanyanswer', 'question'), 0), 105 null => question_possible_response::no_response() 106 ), 107 ), $this->qtype->get_possible_responses($q)); 108 } 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |