|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 // Include the code to test 00030 require_once($CFG->dirroot . '/mod/workshop/locallib.php'); 00031 require_once($CFG->dirroot . '/mod/workshop/form/rubric/lib.php'); 00032 00033 global $DB; 00034 Mock::generate(get_class($DB), 'mockDB'); 00035 00039 class testable_workshop_rubric_strategy extends workshop_rubric_strategy { 00040 00042 public $dimensions = array(); 00043 00047 public function calculate_peer_grade(array $grades) { 00048 return parent::calculate_peer_grade($grades); 00049 } 00050 } 00051 00052 class workshop_rubric_strategy_test extends UnitTestCase { 00053 00055 protected $realDB; 00056 00058 protected $workshop; 00059 00061 protected $strategy; 00062 00066 public function setUp() { 00067 global $DB; 00068 $this->realDB = $DB; 00069 $DB = new mockDB(); 00070 00071 $cm = new stdclass(); 00072 $course = new stdclass(); 00073 $context = new stdclass(); 00074 $workshop = (object)array('id' => 42, 'strategy' => 'rubric'); 00075 $this->workshop = new workshop($workshop, $cm, $course, $context); 00076 $DB->expectOnce('get_records_sql'); 00077 $DB->setReturnValue('get_records_sql', array()); 00078 $this->strategy = new testable_workshop_rubric_strategy($this->workshop); 00079 00080 // prepare dimensions definition 00081 $dim = new stdclass(); 00082 $dim->id = 6; 00083 $dim->levels[10] = (object)array('id' => 10, 'grade' => 0); 00084 $dim->levels[13] = (object)array('id' => 13, 'grade' => 2); 00085 $dim->levels[14] = (object)array('id' => 14, 'grade' => 6); 00086 $dim->levels[16] = (object)array('id' => 16, 'grade' => 8); 00087 $this->strategy->dimensions[$dim->id] = $dim; 00088 00089 $dim = new stdclass(); 00090 $dim->id = 8; 00091 $dim->levels[17] = (object)array('id' => 17, 'grade' => 0); 00092 $dim->levels[18] = (object)array('id' => 18, 'grade' => 1); 00093 $dim->levels[19] = (object)array('id' => 19, 'grade' => 2); 00094 $dim->levels[20] = (object)array('id' => 20, 'grade' => 3); 00095 $this->strategy->dimensions[$dim->id] = $dim; 00096 00097 $dim = new stdclass(); 00098 $dim->id = 10; 00099 $dim->levels[27] = (object)array('id' => 27, 'grade' => 10); 00100 $dim->levels[28] = (object)array('id' => 28, 'grade' => 20); 00101 $dim->levels[29] = (object)array('id' => 29, 'grade' => 30); 00102 $dim->levels[30] = (object)array('id' => 30, 'grade' => 40); 00103 $this->strategy->dimensions[$dim->id] = $dim; 00104 00105 } 00106 00107 public function tearDown() { 00108 global $DB; 00109 $DB = $this->realDB; 00110 00111 $this->strategy = null; 00112 $this->workshop = null; 00113 } 00114 00115 public function test_calculate_peer_grade_null_grade() { 00116 // fixture set-up 00117 $grades = array(); 00118 // exercise SUT 00119 $suggested = $this->strategy->calculate_peer_grade($grades); 00120 // validate 00121 $this->assertNull($suggested); 00122 } 00123 00124 public function test_calculate_peer_grade_worst_possible() { 00125 // fixture set-up 00126 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 0); 00127 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 0); 00128 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 10); 00129 // exercise SUT 00130 $suggested = $this->strategy->calculate_peer_grade($grades); 00131 // validate 00132 $this->assertEqual(grade_floatval($suggested), 0.00000); 00133 } 00134 00135 public function test_calculate_peer_grade_best_possible() { 00136 // fixture set-up 00137 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 8); 00138 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 3); 00139 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 40); 00140 // exercise SUT 00141 $suggested = $this->strategy->calculate_peer_grade($grades); 00142 // validate 00143 $this->assertEqual(grade_floatval($suggested), 100.00000); 00144 } 00145 00146 public function test_calculate_peer_grade_something() { 00147 // fixture set-up 00148 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 2); 00149 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 2); 00150 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 30); 00151 // exercise SUT 00152 $suggested = $this->strategy->calculate_peer_grade($grades); 00153 // validate 00154 // minimal rubric score is 10, maximal is 51. We have 34 here 00155 $this->assertEqual(grade_floatval($suggested), grade_floatval(100 * 24 / 41)); 00156 } 00157 }