Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/numerical/simpletest/testanswer.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 
00017 
00027 require_once($CFG->dirroot . '/question/type/numerical/question.php');
00028 
00029 class qtype_numerical_answer_test extends UnitTestCase {
00030     public function test_within_tolerance_nominal() {
00031         $answer = new qtype_numerical_answer(13, 7.0, 1.0, '', FORMAT_MOODLE, 1.0);
00032 
00033         $this->assertFalse($answer->within_tolerance(5.99));
00034         $this->assertTrue($answer->within_tolerance(6));
00035         $this->assertTrue($answer->within_tolerance(7));
00036         $this->assertTrue($answer->within_tolerance(8));
00037         $this->assertFalse($answer->within_tolerance(8.01));
00038     }
00039 
00040     public function test_within_tolerance_blank() {
00041         $answer = new qtype_numerical_answer(13, 1234, 1.0, '', FORMAT_MOODLE, '');
00042         $this->assertTrue($answer->within_tolerance(1234));
00043         $this->assertFalse($answer->within_tolerance(1234.000001));
00044         $this->assertFalse($answer->within_tolerance(0));
00045 
00046         $answer = new qtype_numerical_answer(13, 0, 1.0, '', FORMAT_MOODLE, '');
00047         $this->assertTrue($answer->within_tolerance(0));
00048         $this->assertFalse($answer->within_tolerance(pow(10, -1 * ini_get('precision') + 1)));
00049         $this->assertTrue($answer->within_tolerance(pow(10, -1 * ini_get('precision'))));
00050     }
00051 
00052     public function test_within_tolerance_relative() {
00053         $answer = new qtype_numerical_answer(13, 7.0, 1.0, '', FORMAT_MOODLE, 0.1);
00054         $answer->tolerancetype = 1;
00055 
00056         $this->assertFalse($answer->within_tolerance(6.29));
00057         $this->assertTrue($answer->within_tolerance(6.3));
00058         $this->assertTrue($answer->within_tolerance(7));
00059         $this->assertTrue($answer->within_tolerance(7.7));
00060         $this->assertFalse($answer->within_tolerance(7.71));
00061     }
00062 
00063     public function test_within_tolerance_geometric() {
00064         $answer = new qtype_numerical_answer(13, 7.0, 1.0, '', FORMAT_MOODLE, 1.0);
00065         $answer->tolerancetype = 3;
00066 
00067         $this->assertFalse($answer->within_tolerance(3.49));
00068         $this->assertTrue($answer->within_tolerance(3.5));
00069         $this->assertTrue($answer->within_tolerance(7));
00070         $this->assertTrue($answer->within_tolerance(14));
00071         $this->assertFalse($answer->within_tolerance(14.01));
00072     }
00073 }
 All Data Structures Namespaces Files Functions Variables Enumerations