Commit ca5ba6d1 authored by Christoph Thelen's avatar Christoph Thelen
Browse files

Fix Divide by Zero error

Cherry picked from master
parent 3be662f1
......@@ -36,7 +36,11 @@ public class PointBasedLearningProgress extends VariantLearningProgress {
lpv.setCourseProgress(coursePercentage());
lpv.setNumQuestions(courseScore.getQuestionCount());
lpv.setNumUsers(courseScore.getTotalUserCount());
lpv.setNumerator(courseScore.getTotalUserScore() / courseScore.getTotalUserCount());
if (courseScore.getTotalUserCount() == 0) {
lpv.setNumerator(0);
} else {
lpv.setNumerator(courseScore.getTotalUserScore() / courseScore.getTotalUserCount());
}
lpv.setDenominator(courseScore.getMaximumScore());
return lpv;
}
......
......@@ -154,4 +154,9 @@ public class PointBasedLearningProgressTest {
assertEquals(10, numerator);
assertEquals(20, denominator);
}
@Test
public void shouldNotDivideByZeroInNumerator() {
assertEquals(0, lp.getCourseProgress(null).getNumerator());
}
}
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