|
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 require_once($CFG->dirroot . '/mod/quiz/lib.php'); 00030 00031 00036 class quiz_lib_test extends UnitTestCase { 00037 public static $includecoverage = array('mod/quiz/lib.php'); 00038 public function test_quiz_has_grades() { 00039 $quiz = new stdClass(); 00040 $quiz->grade = '100.0000'; 00041 $quiz->sumgrades = '100.0000'; 00042 $this->assertTrue(quiz_has_grades($quiz)); 00043 $quiz->sumgrades = '0.0000'; 00044 $this->assertFalse(quiz_has_grades($quiz)); 00045 $quiz->grade = '0.0000'; 00046 $this->assertFalse(quiz_has_grades($quiz)); 00047 $quiz->sumgrades = '100.0000'; 00048 $this->assertFalse(quiz_has_grades($quiz)); 00049 } 00050 00051 public function test_quiz_format_grade() { 00052 $quiz = new stdClass(); 00053 $quiz->decimalpoints = 2; 00054 $this->assertEqual(quiz_format_grade($quiz, 0.12345678), format_float(0.12, 2)); 00055 $this->assertEqual(quiz_format_grade($quiz, 0), format_float(0, 2)); 00056 $this->assertEqual(quiz_format_grade($quiz, 1.000000000000), format_float(1, 2)); 00057 $quiz->decimalpoints = 0; 00058 $this->assertEqual(quiz_format_grade($quiz, 0.12345678), '0'); 00059 } 00060 00061 public function test_quiz_format_question_grade() { 00062 $quiz = new stdClass(); 00063 $quiz->decimalpoints = 2; 00064 $quiz->questiondecimalpoints = 2; 00065 $this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.12, 2)); 00066 $this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 2)); 00067 $this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 2)); 00068 $quiz->decimalpoints = 3; 00069 $quiz->questiondecimalpoints = -1; 00070 $this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.123, 3)); 00071 $this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 3)); 00072 $this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 3)); 00073 $quiz->questiondecimalpoints = 4; 00074 $this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.1235, 4)); 00075 $this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 4)); 00076 $this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 4)); 00077 } 00078 }