|
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 global $CFG; 00030 00031 require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); // Include the code to test 00032 00033 00040 class question_reportlib_test extends UnitTestCase { 00041 public static $includecoverage = array('mod/quiz/report/reportlib.php'); 00042 00043 public function test_quiz_report_index_by_keys() { 00044 $datum = array(); 00045 $object = new stdClass(); 00046 $object->qid = 3; 00047 $object->aid = 101; 00048 $object->response = ''; 00049 $object->grade = 3; 00050 $datum[] = $object; 00051 00052 $indexed = quiz_report_index_by_keys($datum, array('aid', 'qid')); 00053 00054 $this->assertEqual($indexed[101][3]->qid, 3); 00055 $this->assertEqual($indexed[101][3]->aid, 101); 00056 $this->assertEqual($indexed[101][3]->response, ''); 00057 $this->assertEqual($indexed[101][3]->grade, 3); 00058 00059 $indexed = quiz_report_index_by_keys($datum, array('aid', 'qid'), false); 00060 00061 $this->assertEqual($indexed[101][3][0]->qid, 3); 00062 $this->assertEqual($indexed[101][3][0]->aid, 101); 00063 $this->assertEqual($indexed[101][3][0]->response, ''); 00064 $this->assertEqual($indexed[101][3][0]->grade, 3); 00065 } 00066 00067 public function test_quiz_report_scale_summarks_as_percentage() { 00068 $quiz = new stdClass(); 00069 $quiz->sumgrades = 10; 00070 $quiz->decimalpoints = 2; 00071 00072 $this->assertEqual('12.34567%', 00073 quiz_report_scale_summarks_as_percentage(1.234567, $quiz, false)); 00074 $this->assertEqual('12.35%', 00075 quiz_report_scale_summarks_as_percentage(1.234567, $quiz, true)); 00076 $this->assertEqual('-', 00077 quiz_report_scale_summarks_as_percentage('-', $quiz, true)); 00078 } 00079 }