Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 Rubric grading strategy logic 19 * 20 * @package workshopform_rubric 21 * @category phpunit 22 * @copyright 2009 David Mudrak <david.mudrak@gmail.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 // Include the code to test 29 global $CFG; 30 require_once($CFG->dirroot . '/mod/workshop/locallib.php'); 31 require_once($CFG->dirroot . '/mod/workshop/form/rubric/lib.php'); 32 33 34 class workshopform_rubric_strategy_test extends advanced_testcase { 35 36 /** workshop instance emulation */ 37 protected $workshop; 38 39 /** instance of the strategy logic class being tested */ 40 protected $strategy; 41 42 /** 43 * Setup testing environment 44 */ 45 protected function setUp(): void { 46 parent::setUp(); 47 $this->resetAfterTest(); 48 $this->setAdminUser(); 49 $course = $this->getDataGenerator()->create_course(); 50 $workshop = $this->getDataGenerator()->create_module('workshop', array('strategy' => 'rubric', 'course' => $course)); 51 $cm = get_fast_modinfo($course)->instances['workshop'][$workshop->id]; 52 $this->workshop = new workshop($workshop, $cm, $course); 53 $this->strategy = new testable_workshop_rubric_strategy($this->workshop); 54 55 // prepare dimensions definition 56 $dim = new stdclass(); 57 $dim->id = 6; 58 $dim->levels[10] = (object)array('id' => 10, 'grade' => 0); 59 $dim->levels[13] = (object)array('id' => 13, 'grade' => 2); 60 $dim->levels[14] = (object)array('id' => 14, 'grade' => 6); 61 $dim->levels[16] = (object)array('id' => 16, 'grade' => 8); 62 $this->strategy->dimensions[$dim->id] = $dim; 63 64 $dim = new stdclass(); 65 $dim->id = 8; 66 $dim->levels[17] = (object)array('id' => 17, 'grade' => 0); 67 $dim->levels[18] = (object)array('id' => 18, 'grade' => 1); 68 $dim->levels[19] = (object)array('id' => 19, 'grade' => 2); 69 $dim->levels[20] = (object)array('id' => 20, 'grade' => 3); 70 $this->strategy->dimensions[$dim->id] = $dim; 71 72 $dim = new stdclass(); 73 $dim->id = 10; 74 $dim->levels[27] = (object)array('id' => 27, 'grade' => 10); 75 $dim->levels[28] = (object)array('id' => 28, 'grade' => 20); 76 $dim->levels[29] = (object)array('id' => 29, 'grade' => 30); 77 $dim->levels[30] = (object)array('id' => 30, 'grade' => 40); 78 $this->strategy->dimensions[$dim->id] = $dim; 79 80 } 81 82 protected function tearDown(): void { 83 $this->strategy = null; 84 $this->workshop = null; 85 parent::tearDown(); 86 } 87 88 public function test_calculate_peer_grade_null_grade() { 89 // fixture set-up 90 $grades = array(); 91 // exercise SUT 92 $suggested = $this->strategy->calculate_peer_grade($grades); 93 // validate 94 $this->assertNull($suggested); 95 } 96 97 public function test_calculate_peer_grade_worst_possible() { 98 // fixture set-up 99 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 0); 100 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 0); 101 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 10); 102 // exercise SUT 103 $suggested = $this->strategy->calculate_peer_grade($grades); 104 // validate 105 $this->assertEquals(grade_floatval($suggested), 0.00000); 106 } 107 108 public function test_calculate_peer_grade_best_possible() { 109 // fixture set-up 110 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 8); 111 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 3); 112 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 40); 113 // exercise SUT 114 $suggested = $this->strategy->calculate_peer_grade($grades); 115 // validate 116 $this->assertEquals(grade_floatval($suggested), 100.00000); 117 } 118 119 public function test_calculate_peer_grade_something() { 120 // fixture set-up 121 $grades[6] = (object)array('dimensionid' => 6, 'grade' => 2); 122 $grades[8] = (object)array('dimensionid' => 8, 'grade' => 2); 123 $grades[10] = (object)array('dimensionid' => 10, 'grade' => 30); 124 // exercise SUT 125 $suggested = $this->strategy->calculate_peer_grade($grades); 126 // validate 127 // minimal rubric score is 10, maximal is 51. We have 34 here 128 $this->assertEquals(grade_floatval($suggested), grade_floatval(100 * 24 / 41)); 129 } 130 } 131 132 133 /** 134 * Test subclass that makes all the protected methods we want to test public 135 */ 136 class testable_workshop_rubric_strategy extends workshop_rubric_strategy { 137 138 /** allows to set dimensions manually */ 139 public $dimensions = array(); 140 141 /** 142 * This is where the calculation of suggested grade for submission is done 143 */ 144 public function calculate_peer_grade(array $grades) { 145 return parent::calculate_peer_grade($grades); 146 } 147 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body