fix: bound confirmed points and the attempt percentage

WR-05: Confirm clamps the grader's score to the question's current
points, so lowering a question's points no longer lets a confirm store
more than full marks, and Totals caps the percentage at 100 when a
question's points were raised after the attempt was scored.
This commit is contained in:
Jakub Zych
2026-11-09 22:50:26 +01:00
parent 1cba2c4d32
commit 09cf61e9e0
3 changed files with 15 additions and 4 deletions

View File

@@ -140,7 +140,8 @@ func Score(in ScoreInput, cfg ScoringConfig) ScoreResult {
}
// Totals sums the earned points of an attempt, floored at 0, and the
// percentage of maxPoints it is. With no points to earn the percentage is 0.
// percentage of maxPoints it is, capped at 100. With no points to earn the
// percentage is 0.
func Totals(points []float64, maxPoints int) (score, percent float64) {
for _, p := range points {
score += p
@@ -149,7 +150,9 @@ func Totals(points []float64, maxPoints int) (score, percent float64) {
if maxPoints <= 0 {
return score, 0
}
return score, round(score / float64(maxPoints) * 100)
// A question's points raised after the attempt was scored can push the
// score past the attempt's stored maximum; the percentage stays <= 100.
return score, round(math.Min(score/float64(maxPoints)*100, 100))
}
// ClampOpenPoints keeps a grader's score of an open question in