Commit 76866131 authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer

Merge branch 'score-calculator-rounding-fix' into 'score-calculator-rounding-fix'

Fix rounding error in ScoreBasedScoreCalculator

See merge request !1
parents cd570c65 a2abd868
Pipeline #10579 failed with stages
in 0 seconds
......@@ -48,7 +48,7 @@ public class ScoreBasedScoreCalculator extends VariantScoreCalculator {
if (courseMaximumValue == 0 || numUsers == 0) {
return 0;
}
final double courseAverageValue = userTotalValue / numUsers;
final double courseAverageValue = (double)userTotalValue / numUsers;
final double courseProgress = courseAverageValue / courseMaximumValue;
return (int) Math.min(100, Math.round(courseProgress * 100));
}
......
......@@ -91,18 +91,23 @@ public class ScoreBasedScoreCalculatorTest {
String q3 = this.addQuestion("lecture", 100);
User u1 = new TestUser("user1");
User u2 = new TestUser("user2");
User u3 = new TestUser("user3");
// Both users achieve 200 points
this.addAnswer(q1, u1, 100);
this.addAnswer(q1, u2, 100);
this.addAnswer(q1, u3, 0);
this.addAnswer(q2, u1, 0);
this.addAnswer(q2, u2, 0);
this.addAnswer(q2, u2, 100);
this.addAnswer(q2, u3, 0);
this.addAnswer(q3, u1, 100);
this.addAnswer(q3, u2, 100);
this.addAnswer(q3, u3, 0);
lp.setQuestionVariant("lecture");
ScoreStatistics u1LectureProgress = lp.getMyProgress(null, u1);
// 200 / 300 = 0,67
assertEquals(67, u1LectureProgress.getCourseProgress());
// (500/3) / 300 ~= 0,56.
assertEquals(56, u1LectureProgress.getCourseProgress());
// 200 / 300 ~= 0,67.
assertEquals(67, u1LectureProgress.getMyProgress());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment