From fc3e63714e28e4c66ab7541ccffafdfb0bb08134 Mon Sep 17 00:00:00 2001 From: asadazam93 <asadazam93@gmail.com> Date: Thu, 19 Mar 2020 16:59:21 +0500 Subject: [PATCH] Fixed comparison mismatch --- common/lib/xmodule/xmodule/graders.py | 2 +- .../lib/xmodule/xmodule/tests/test_graders.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/graders.py b/common/lib/xmodule/xmodule/graders.py index 2690618f47c..78347a0b05d 100644 --- a/common/lib/xmodule/xmodule/graders.py +++ b/common/lib/xmodule/xmodule/graders.py @@ -380,7 +380,7 @@ class AssignmentFormatGrader(CourseGrader): scores = list(grade_sheet.get(self.type, {}).values()) breakdown = [] labeler = get_short_labeler(self.short_label) - for i in range(max(self.min_count, len(scores))): + for i in range(max(int(float(self.min_count)), len(scores))): if i < len(scores) or generate_random_scores: if generate_random_scores: # for debugging! earned = random.randint(2, 15) diff --git a/common/lib/xmodule/xmodule/tests/test_graders.py b/common/lib/xmodule/xmodule/tests/test_graders.py index 1258efd13e4..c71b7e2d661 100644 --- a/common/lib/xmodule/xmodule/tests/test_graders.py +++ b/common/lib/xmodule/xmodule/tests/test_graders.py @@ -252,6 +252,40 @@ class GraderTest(unittest.TestCase): self.assertEqual(len(graded['section_breakdown']), 0) self.assertEqual(len(graded['grade_breakdown']), 0) + def test_grade_with_string_min_count(self): + """ + Test that the grading succeeds in case the min_count is set to a string + """ + weighted_grader = graders.grader_from_conf([ + { + 'type': "Homework", + 'min_count': '12', + 'drop_count': 2, + 'short_label': "HW", + 'weight': 0.25, + }, + { + 'type': "Lab", + 'min_count': '7', + 'drop_count': 3, + 'category': "Labs", + 'weight': 0.25 + }, + { + 'type': "Midterm", + 'min_count': '0', + 'drop_count': 0, + 'name': "Midterm Exam", + 'short_label': "Midterm", + 'weight': 0.5, + }, + ]) + + graded = weighted_grader.grade(self.test_gradesheet) + self.assertAlmostEqual(graded['percent'], 0.50812499999999994) + self.assertEqual(len(graded['section_breakdown']), (12 + 1) + (7 + 1) + 1) + self.assertEqual(len(graded['grade_breakdown']), 3) + def test_grader_from_conf(self): # Confs always produce a graders.WeightedSubsectionsGrader, so we test this by repeating the test -- GitLab