|
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/edit_numerical_form.php'); 00030 00031 00038 class test_qtype_numerical_edit_form extends qtype_numerical_edit_form { 00039 public function __construct() { 00040 // Warning, avoid running the parent constructor. That means the form is 00041 // not properly tested but for now that is OK, we are only testing a few 00042 // methods. 00043 $this->ap = new qtype_numerical_answer_processor(array(), false, ',', ' '); 00044 } 00045 public function is_valid_number($x) { 00046 return parent::is_valid_number($x); 00047 } 00048 } 00049 00050 00057 class qtype_numerical_form_test extends UnitTestCase { 00058 public static $includecoverage = array( 00059 'question/type/numerical/edit_numerical_form.php' 00060 ); 00061 00062 protected $form; 00063 00064 public function setUp() { 00065 $this->form = new test_qtype_numerical_edit_form(); 00066 } 00067 00068 public function tearDown() { 00069 $this->form = null; 00070 } 00071 00072 public function test_is_valid_number() { 00073 $this->assertTrue($this->form->is_valid_number('1,001')); 00074 $this->assertTrue($this->form->is_valid_number('1.001')); 00075 $this->assertTrue($this->form->is_valid_number('1')); 00076 $this->assertTrue($this->form->is_valid_number('1,e8')); 00077 $this->assertFalse($this->form->is_valid_number('1001 xxx')); 00078 $this->assertTrue($this->form->is_valid_number('1.e8')); 00079 } 00080 }