Corrected rounding function when letter grade is computed
A rounding error on 10 pt scale was causing 0.87 to display as a B instead of B+ fixes CNVS-11843 test plan: - Create assignment worth 10 total points and score it by letter grade - Use default grading scheme so B+ is >90% - 87% - Save the assignment and as the test student submit to it - In gradebook score it with an 8.7/10, should show B+ as grade - Update score to 8.69/10, should show B as grade Change-Id: I1c8abbaa53c49eb019cb19798ddc232bf65f9056 Reviewed-on: https://gerrit.instructure.com/38759 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Mike Nomitch <mnomitch@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com> Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
parent
a44b18b59c
commit
6e31c3c2c0
|
@ -18,6 +18,7 @@
|
|||
|
||||
require 'set'
|
||||
require 'canvas/draft_state_validations'
|
||||
require 'bigdecimal'
|
||||
|
||||
class Assignment < ActiveRecord::Base
|
||||
include Workflow
|
||||
|
@ -680,7 +681,7 @@ class Assignment < ActiveRecord::Base
|
|||
result = passed ? "complete" : "incomplete"
|
||||
when "letter_grade", "gpa_scale"
|
||||
if self.points_possible.to_f > 0.0
|
||||
score = score.to_f / self.points_possible.to_f
|
||||
score = (BigDecimal.new(score.to_s) / BigDecimal.new(points_possible.to_s)).to_f
|
||||
result = grading_standard_or_default.score_to_grade(score * 100)
|
||||
elsif given_grade
|
||||
# the score for a zero-point letter_grade assignment could be considered
|
||||
|
|
|
@ -474,6 +474,22 @@ describe Assignment do
|
|||
@submission.user_id.should eql(@user.id)
|
||||
end
|
||||
|
||||
it "should properly calculate letter grades" do
|
||||
@assignment.grading_type = 'letter_grade'
|
||||
@assignment.points_possible = 10
|
||||
@assignment.save!
|
||||
grade = @assignment.score_to_grade(8.7)
|
||||
grade.should eql("B+")
|
||||
end
|
||||
|
||||
it "should properly allow decimal points in grading" do
|
||||
@assignment.grading_type = 'letter_grade'
|
||||
@assignment.points_possible = 10
|
||||
@assignment.save!
|
||||
grade = @assignment.score_to_grade(8.6999)
|
||||
grade.should eql("B")
|
||||
end
|
||||
|
||||
it "should preserve letter grades grades with nil points possible" do
|
||||
@assignment.grading_type = 'letter_grade'
|
||||
@assignment.points_possible = nil
|
||||
|
|
Loading…
Reference in New Issue