Commit | Line | Data |
---|---|---|
a3d5830a PS |
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) ../questionlib.php. | |
19 | * | |
20 | * @package core_question | |
21 | * @category phpunit | |
22 | * @copyright 2006 The Open University | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | defined('MOODLE_INTERNAL') || die(); | |
27 | ||
28 | ||
29 | /** | |
30 | * Unit tests for (some of) ../questionlib.php. | |
31 | * | |
32 | * @copyright 2006 The Open University | |
33 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
34 | */ | |
35 | class questionlib_testcase extends basic_testcase { | |
36 | ||
37 | public function test_question_reorder_qtypes() { | |
38 | global $CFG; | |
39 | require_once($CFG->libdir . '/questionlib.php'); | |
40 | ||
41 | $this->assertEquals(question_reorder_qtypes( | |
42 | array('t1' => '', 't2' => '', 't3' => ''), 't1', +1), | |
43 | array(0 => 't2', 1 => 't1', 2 => 't3')); | |
44 | $this->assertEquals(question_reorder_qtypes( | |
45 | array('t1' => '', 't2' => '', 't3' => ''), 't1', -1), | |
46 | array(0 => 't1', 1 => 't2', 2 => 't3')); | |
47 | $this->assertEquals(question_reorder_qtypes( | |
48 | array('t1' => '', 't2' => '', 't3' => ''), 't2', -1), | |
49 | array(0 => 't2', 1 => 't1', 2 => 't3')); | |
50 | $this->assertEquals(question_reorder_qtypes( | |
51 | array('t1' => '', 't2' => '', 't3' => ''), 't3', +1), | |
52 | array(0 => 't1', 1 => 't2', 2 => 't3')); | |
53 | $this->assertEquals(question_reorder_qtypes( | |
54 | array('t1' => '', 't2' => '', 't3' => ''), 'missing', +1), | |
55 | array(0 => 't1', 1 => 't2', 2 => 't3')); | |
56 | } | |
57 | ||
aa5f0511 TH |
58 | public function test_match_grade_options() { |
59 | $gradeoptions = question_bank::fraction_options_full(); | |
60 | ||
61 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'error')); | |
62 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.333333, 'error')); | |
63 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33333, 'error')); | |
64 | $this->assertFalse(match_grade_options($gradeoptions, 0.3333, 'error')); | |
65 | ||
66 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.3333333, 'nearest')); | |
67 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.333333, 'nearest')); | |
68 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33333, 'nearest')); | |
69 | $this->assertEquals(0.3333333, match_grade_options($gradeoptions, 0.33, 'nearest')); | |
70 | ||
71 | $this->assertEquals(-0.1428571, match_grade_options($gradeoptions, -0.15, 'nearest')); | |
72 | } | |
a3d5830a | 73 | } |