2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Unit tests for (some of) ../questionlib.php.
20 * @package core_question
22 * @copyright 2006 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
30 * Unit tests for (some of) ../questionlib.php.
32 * @copyright 2006 The Open University
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class questionlib_testcase extends basic_testcase {
37 public function test_question_reorder_qtypes() {
39 require_once($CFG->libdir . '/questionlib.php');
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'));
58 public function test_match_grade_options() {
59 $gradeoptions = question_bank::fraction_options_full();
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'));
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'));
71 $this->assertEquals(-0.1428571, match_grade_options($gradeoptions, -0.15, 'nearest'));