Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/engine/simpletest/testquestionutils.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 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once(dirname(__FILE__) . '/../lib.php');
00030 
00031 
00038 class question_utils_test extends UnitTestCase {
00039     public function test_arrays_have_same_keys_and_values() {
00040         $this->assertTrue(question_utils::arrays_have_same_keys_and_values(
00041                 array(),
00042                 array()));
00043         $this->assertTrue(question_utils::arrays_have_same_keys_and_values(
00044                 array('key' => 1),
00045                 array('key' => '1')));
00046         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
00047                 array(),
00048                 array('key' => 1)));
00049         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
00050                 array('key' => 2),
00051                 array('key' => 1)));
00052         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
00053                 array('key' => 1),
00054                 array('otherkey' => 1)));
00055         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
00056                 array('sub0' => '2', 'sub1' => '2', 'sub2' => '3', 'sub3' => '1'),
00057                 array('sub0' => '1', 'sub1' => '2', 'sub2' => '3', 'sub3' => '1')));
00058     }
00059 
00060     public function test_arrays_same_at_key() {
00061         $this->assertTrue(question_utils::arrays_same_at_key(
00062                 array(),
00063                 array(),
00064                 'key'));
00065         $this->assertFalse(question_utils::arrays_same_at_key(
00066                 array(),
00067                 array('key' => 1),
00068                 'key'));
00069         $this->assertFalse(question_utils::arrays_same_at_key(
00070                 array('key' => 1),
00071                 array(),
00072                 'key'));
00073         $this->assertTrue(question_utils::arrays_same_at_key(
00074                 array('key' => 1),
00075                 array('key' => 1),
00076                 'key'));
00077         $this->assertFalse(question_utils::arrays_same_at_key(
00078                 array('key' => 1),
00079                 array('key' => 2),
00080                 'key'));
00081         $this->assertTrue(question_utils::arrays_same_at_key(
00082                 array('key' => 1),
00083                 array('key' => '1'),
00084                 'key'));
00085         $this->assertFalse(question_utils::arrays_same_at_key(
00086                 array('key' => 0),
00087                 array('key' => ''),
00088                 'key'));
00089         $this->assertFalse(question_utils::arrays_same_at_key(
00090                 array(),
00091                 array('key' => ''),
00092                 'key'));
00093     }
00094 
00095     public function test_arrays_same_at_key_missing_is_blank() {
00096         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
00097                 array(),
00098                 array(),
00099                 'key'));
00100         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
00101                 array(),
00102                 array('key' => 1),
00103                 'key'));
00104         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
00105                 array('key' => 1),
00106                 array(),
00107                 'key'));
00108         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
00109                 array('key' => 1),
00110                 array('key' => 1),
00111                 'key'));
00112         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
00113                 array('key' => 1),
00114                 array('key' => 2),
00115                 'key'));
00116         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
00117                 array('key' => 1),
00118                 array('key' => '1'),
00119                 'key'));
00120         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
00121                 array('key' => '0'),
00122                 array('key' => ''),
00123                 'key'));
00124         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
00125                 array(),
00126                 array('key' => ''),
00127                 'key'));
00128     }
00129 
00130     public function test_arrays_same_at_key_integer() {
00131         $this->assertTrue(question_utils::arrays_same_at_key_integer(
00132                 array(),
00133                 array(),
00134                 'key'));
00135         $this->assertFalse(question_utils::arrays_same_at_key_integer(
00136                 array(),
00137                 array('key' => 1),
00138                 'key'));
00139         $this->assertFalse(question_utils::arrays_same_at_key_integer(
00140                 array('key' => 1),
00141                 array(),
00142                 'key'));
00143         $this->assertTrue(question_utils::arrays_same_at_key_integer(
00144                 array('key' => 1),
00145                 array('key' => 1),
00146                 'key'));
00147         $this->assertFalse(question_utils::arrays_same_at_key_integer(
00148                 array('key' => 1),
00149                 array('key' => 2),
00150                 'key'));
00151         $this->assertTrue(question_utils::arrays_same_at_key_integer(
00152                 array('key' => 1),
00153                 array('key' => '1'),
00154                 'key'));
00155         $this->assertTrue(question_utils::arrays_same_at_key_integer(
00156                 array('key' => '0'),
00157                 array('key' => ''),
00158                 'key'));
00159         $this->assertTrue(question_utils::arrays_same_at_key_integer(
00160                 array(),
00161                 array('key' => 0),
00162                 'key'));
00163     }
00164 
00165     public function test_int_to_roman() {
00166         $this->assertIdentical('i', question_utils::int_to_roman(1));
00167         $this->assertIdentical('iv', question_utils::int_to_roman(4));
00168         $this->assertIdentical('v', question_utils::int_to_roman(5));
00169         $this->assertIdentical('vi', question_utils::int_to_roman(6));
00170         $this->assertIdentical('ix', question_utils::int_to_roman(9));
00171         $this->assertIdentical('xi', question_utils::int_to_roman(11));
00172         $this->assertIdentical('xlviii', question_utils::int_to_roman(48));
00173         $this->assertIdentical('lxxxvii', question_utils::int_to_roman(87));
00174         $this->assertIdentical('c', question_utils::int_to_roman(100));
00175         $this->assertIdentical('mccxxxiv', question_utils::int_to_roman(1234));
00176         $this->assertIdentical('mmmcmxcix', question_utils::int_to_roman(3999));
00177     }
00178 
00179     public function test_int_to_roman_too_small() {
00180         $this->expectException();
00181         question_utils::int_to_roman(0);
00182     }
00183 
00184     public function test_int_to_roman_too_big() {
00185         $this->expectException();
00186         question_utils::int_to_roman(4000);
00187     }
00188 
00189     public function test_int_to_roman_not_int() {
00190         $this->expectException();
00191         question_utils::int_to_roman(1.5);
00192     }
00193 }
 All Data Structures Namespaces Files Functions Variables Enumerations