corrected rounding error when creating custom grade scheme
floating point math error caused errors with certain percentages fixes CNVS-1850 test plan: - create/edit an assignment and go to manage grading schemes - enter various percentages for grades (93.5, 87.6, 69.5, 69.6) and save - grades should reflect the percentage entered after saving and not mutate Change-Id: Ieaae9d5ea5f6436890794a029cf0a54749ccad18 Reviewed-on: https://gerrit.instructure.com/39662 Reviewed-by: Simon Williams <simon@instructure.com> Product-Review: Simon Williams <simon@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Trevor deHaan <tdehaan@instructure.com>
This commit is contained in:
parent
f1bdc8f7e4
commit
2fc50baa52
|
@ -116,7 +116,7 @@ class GradingStandard < ActiveRecord::Base
|
|||
# round values to the nearest 0.01 (0.0001 since e.g. 78 is stored as .78)
|
||||
# and dup the data while we're at it. (new_val.dup only dups one level, the
|
||||
# elements of new_val.dup are the same objects as the elements of new_val)
|
||||
new_val = new_val.map{ |grade_name, lower_bound| [ grade_name, (lower_bound * 10000).to_i / 10000.0 ] }
|
||||
new_val = new_val.map{ |grade_name, lower_bound| [ grade_name, lower_bound.round(4) ] }
|
||||
write_attribute(:data, new_val)
|
||||
@ordered_scheme = nil
|
||||
end
|
||||
|
|
|
@ -123,7 +123,7 @@ describe GradingStandard do
|
|||
|
||||
context "score_to_grade" do
|
||||
it "should compute correct grades" do
|
||||
input = [['A', 0.90], ['B', 0.80], ['C', 0.675], ['D', 0.55], ['M', 0.00]]
|
||||
input = [['A', 0.90], ['B+', 0.886], ['B', 0.80], ['C', 0.695], ['D', 0.55], ['M', 0.00]]
|
||||
standard = GradingStandard.new
|
||||
standard.data = input
|
||||
standard.score_to_grade(1005).should eql("A")
|
||||
|
@ -131,15 +131,16 @@ describe GradingStandard do
|
|||
standard.score_to_grade(100).should eql("A")
|
||||
standard.score_to_grade(99).should eql("A")
|
||||
standard.score_to_grade(90).should eql("A")
|
||||
standard.score_to_grade(89.999).should eql("B")
|
||||
standard.score_to_grade(89.001).should eql("B")
|
||||
standard.score_to_grade(89).should eql("B")
|
||||
standard.score_to_grade(88.999).should eql("B")
|
||||
standard.score_to_grade(89.999).should eql("B+")
|
||||
standard.score_to_grade(88.601).should eql("B+")
|
||||
standard.score_to_grade(88.6).should eql("B+")
|
||||
standard.score_to_grade(88.599).should eql("B")
|
||||
standard.score_to_grade(80).should eql("B")
|
||||
standard.score_to_grade(79.999).should eql("C")
|
||||
standard.score_to_grade(79).should eql("C")
|
||||
standard.score_to_grade(67.501).should eql("C")
|
||||
standard.score_to_grade(67.5).should eql("C")
|
||||
standard.score_to_grade(67.499).should eql("D")
|
||||
standard.score_to_grade(69.501).should eql("C")
|
||||
standard.score_to_grade(69.5).should eql("C")
|
||||
standard.score_to_grade(69.499).should eql("D")
|
||||
standard.score_to_grade(60).should eql("D")
|
||||
standard.score_to_grade(50).should eql("M")
|
||||
standard.score_to_grade(0).should eql("M")
|
||||
|
|
Loading…
Reference in New Issue