Skip to content

Commit

Permalink
Merge branch 'MDL-35667_extra_credit_loop' of git://github.com/andyjd…
Browse files Browse the repository at this point in the history
…avis/moodle
  • Loading branch information
Sam Hemelryk committed Oct 7, 2012
2 parents 4c5f42b + 97512dd commit 2a2d855
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/grade/grade_category.php
Expand Up @@ -913,7 +913,10 @@ public function apply_limit_rules(&$grade_values, $items) {
// We're looking for other grade items with the same grade value but a higher grademax
$i = 1;
while ($originalindex+$i < count($grade_keys)) {

$possibleitemid = $grade_keys[$originalindex+$i];
$i++;

if ($grade_values[$founditemid] != $grade_values[$possibleitemid]) {
// The next grade item has a different grade value. Stop looking.
break;
Expand All @@ -930,8 +933,6 @@ public function apply_limit_rules(&$grade_values, $items) {
$founditemid = $possibleitemid;
// Continue searching to see if there is an even higher grademax
}

$i++;
}

// Now drop whatever grade item we have found
Expand Down
15 changes: 15 additions & 0 deletions lib/grade/tests/grade_category_test.php
Expand Up @@ -516,6 +516,21 @@ protected function sub_test_grade_category_apply_limit_rules() {
$this->assertEquals(count($grades), 1);
$this->assertEquals($grades[$this->grade_items[2]->id], 6);

// MDL-35667 - There was an infinite loop if several items had the same grade and at least one was extra credit
$category = new grade_category();
$category->droplow = 1;
$category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN2; // simple weighted mean
$items[$this->grade_items[1]->id]->aggregationcoef = 1; // Mark grade item 1 as "extra credit"
$grades = array($this->grade_items[0]->id=>1, // 1 out of 110. Should be excluded from aggregation.
$this->grade_items[1]->id=>1, // 1 out of 100. Extra credit. Should be retained.
$this->grade_items[2]->id=>1, // 1 out of 6. Should be retained.
$this->grade_items[4]->id=>1);// 1 out of 100. Should be retained.
$category->apply_limit_rules($grades, $items);
$this->assertEquals(count($grades), 3);
$this->assertEquals($grades[$this->grade_items[1]->id], 1);
$this->assertEquals($grades[$this->grade_items[2]->id], 1);
$this->assertEquals($grades[$this->grade_items[4]->id], 1);

}

/**
Expand Down

0 comments on commit 2a2d855

Please sign in to comment.