use bigdecimal() instead of bigdecimal.new
removed in 2.6 Change-Id: I092b437c6e51f4279bd113e6a57422b3a4f2d99c Reviewed-on: https://gerrit.instructure.com/174638 Tested-by: Jenkins Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: James Williams <jamesw@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
66eee60398
commit
7fd45d3691
|
@ -1244,7 +1244,7 @@ class Assignment < ActiveRecord::Base
|
|||
result = passed ? "complete" : "incomplete"
|
||||
when "letter_grade", "gpa_scale"
|
||||
if self.points_possible.to_f > 0.0
|
||||
score = BigDecimal.new(score.to_s.presence || '0.0') / BigDecimal.new(points_possible.to_s)
|
||||
score = BigDecimal(score.to_s.presence || '0.0') / BigDecimal(points_possible.to_s)
|
||||
result = grading_standard_or_default.score_to_grade((score * 100).to_f)
|
||||
elsif given_grade
|
||||
# the score for a zero-point letter_grade assignment could be considered
|
||||
|
|
|
@ -80,7 +80,7 @@ class GradingStandard < ActiveRecord::Base
|
|||
def ordered_scheme
|
||||
# Convert to BigDecimal so we don't get weird float behavior: 0.545 * 100 (gives 54.50000000000001 with floats)
|
||||
@ordered_scheme ||= grading_scheme.to_a.
|
||||
map { |grade_letter, percent| [grade_letter, BigDecimal.new(percent.to_s)] }.
|
||||
map { |grade_letter, percent| [grade_letter, BigDecimal(percent.to_s)] }.
|
||||
sort_by { |_, percent| -percent }
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,7 @@ class GradingStandard < ActiveRecord::Base
|
|||
score = 0 if score < 0
|
||||
# assign the highest grade whose min cutoff is less than the score
|
||||
# if score is less than all scheme cutoffs, assign the lowest grade
|
||||
score = BigDecimal.new(score.to_s) # Cast this to a BigDecimal too or comparisons get wonky
|
||||
score = BigDecimal(score.to_s) # Cast this to a BigDecimal too or comparisons get wonky
|
||||
ordered_scheme.max_by {|_, lower_bound| score >= lower_bound * 100 ? lower_bound : -lower_bound }[0]
|
||||
end
|
||||
|
||||
|
|
|
@ -42,9 +42,9 @@ module Quizzes::QuizQuestion::AnswerSerializers
|
|||
#
|
||||
# @return [BigDecimal]
|
||||
def to_decimal(value)
|
||||
BigDecimal.new(value.to_s)
|
||||
BigDecimal(value.to_s)
|
||||
rescue ArgumentError
|
||||
BigDecimal.new('0.0')
|
||||
BigDecimal('0.0')
|
||||
end
|
||||
|
||||
def to_boolean(flag)
|
||||
|
|
|
@ -21,7 +21,7 @@ require 'bigdecimal'
|
|||
class Quizzes::QuizQuestion::NumericalQuestion < Quizzes::QuizQuestion::Base
|
||||
class FlexRange
|
||||
def initialize(a, b)
|
||||
numbers = [ BigDecimal.new(a.to_s), BigDecimal.new(b.to_s) ].sort
|
||||
numbers = [ BigDecimal(a.to_s), BigDecimal(b.to_s) ].sort
|
||||
@range = numbers[0]..numbers[1]
|
||||
end
|
||||
|
||||
|
@ -42,27 +42,27 @@ class Quizzes::QuizQuestion::NumericalQuestion < Quizzes::QuizQuestion::Base
|
|||
# we use BigDecimal here to avoid rounding errors at the edge of the tolerance
|
||||
# e.g. in floating point, -11.7 with margin of 0.02 isn't inclusive of the answer -11.72
|
||||
begin
|
||||
answer_number = BigDecimal.new(answer_text.to_s)
|
||||
answer_number = BigDecimal(answer_text.to_s)
|
||||
rescue ArgumentError
|
||||
answer_number = BigDecimal.new('0.0')
|
||||
answer_number = BigDecimal('0.0')
|
||||
end
|
||||
|
||||
match = answers.find do |answer|
|
||||
if answer[:numerical_answer_type] == "exact_answer"
|
||||
val = BigDecimal.new(answer[:exact].to_s.presence || '0.0')
|
||||
val = BigDecimal(answer[:exact].to_s.presence || '0.0')
|
||||
|
||||
# calculate margin value using percentage
|
||||
if answer[:margin].to_s.ends_with?("%")
|
||||
answer[:margin] = (answer[:margin].to_f / 100.0 * val).abs
|
||||
end
|
||||
|
||||
margin = BigDecimal.new(answer[:margin].to_s.presence || '0.0')
|
||||
margin = BigDecimal(answer[:margin].to_s.presence || '0.0')
|
||||
min = val - margin
|
||||
max = val + margin
|
||||
answer_number >= min && answer_number <= max
|
||||
elsif answer[:numerical_answer_type] == "precision_answer"
|
||||
submission = answer_number.split
|
||||
expected = BigDecimal.new(answer[:approximate].to_s.presence || '0.0').split
|
||||
expected = BigDecimal(answer[:approximate].to_s.presence || '0.0').split
|
||||
precision = answer[:precision].to_i
|
||||
|
||||
# compare sign
|
||||
|
|
|
@ -345,8 +345,8 @@
|
|||
matched_answer = a if hash_get(a, :numerical_answer_type) == 'exact_answer' && val <= (hash_get(a, :exact) + hash_get(a, :margin, 0)) && val >= (hash_get(a, :exact) - hash_get(a, :margin, 0))
|
||||
matched_answer = a if hash_get(a, :numerical_answer_type) == 'range_answer' && val <= hash_get(a, :end) && val >= hash_get(a, :start)
|
||||
if hash_get(a, :numerical_answer_type) == 'precision_answer'
|
||||
submission = BigDecimal.new(val, 16).split
|
||||
expected = BigDecimal.new(a[:approximate].to_s, 16).split
|
||||
submission = BigDecimal(val, 16).split
|
||||
expected = BigDecimal(a[:approximate].to_s, 16).split
|
||||
precision = a[:precision].to_i
|
||||
matched_answer = a if submission[0] == expected[0] && submission[1][0, precision] == expected[1][0, precision] && submission[3] == expected[3]
|
||||
end
|
||||
|
|
|
@ -91,7 +91,7 @@ class NumericInteraction < AssessmentItemConverter
|
|||
if upper = or_node.at_css('and customOperator[class=varlte] baseValue')
|
||||
# do margin computation with BigDecimal to avoid rounding errors
|
||||
# (this is also used when _scoring_ numeric range questions)
|
||||
margin = BigDecimal.new(upper.text) - BigDecimal.new(exact) rescue "0.0"
|
||||
margin = BigDecimal(upper.text) - BigDecimal(exact) rescue "0.0"
|
||||
answer[:margin] = margin.to_f
|
||||
end
|
||||
end
|
||||
|
|
|
@ -357,8 +357,8 @@ module CC
|
|||
or_node.varequal exact, :respident => 'response1'
|
||||
unless answer['margin'].blank?
|
||||
or_node.and do |and_node|
|
||||
exact = BigDecimal.new(answer['exact'].to_s)
|
||||
margin = BigDecimal.new(answer['margin'].to_s)
|
||||
exact = BigDecimal(answer['exact'].to_s)
|
||||
margin = BigDecimal(answer['margin'].to_s)
|
||||
and_node.vargte((exact - margin).to_f, :respident => 'response1')
|
||||
and_node.varlte((exact + margin).to_f, :respident => 'response1')
|
||||
end
|
||||
|
|
|
@ -193,7 +193,7 @@ YAML
|
|||
end
|
||||
|
||||
it "should be able to dump and load BigDecimals" do
|
||||
hash = {blah: BigDecimal.new("1.2")}
|
||||
hash = {blah: BigDecimal("1.2")}
|
||||
expect(YAML.load(YAML.dump(hash))).to eq hash
|
||||
end
|
||||
|
||||
|
|
|
@ -77,32 +77,32 @@ describe LatePolicy do
|
|||
describe 'rounding' do
|
||||
it 'only keeps 2 digits after the decimal for late_submission_minimum_percent' do
|
||||
policy = LatePolicy.new(late_submission_minimum_percent: 25.223)
|
||||
expect(policy.late_submission_minimum_percent).to eql BigDecimal.new('25.22')
|
||||
expect(policy.late_submission_minimum_percent).to eql BigDecimal('25.22')
|
||||
end
|
||||
|
||||
it 'rounds late_submission_minimum_percent' do
|
||||
policy = LatePolicy.new(late_submission_minimum_percent: 25.225)
|
||||
expect(policy.late_submission_minimum_percent).to eql BigDecimal.new('25.23')
|
||||
expect(policy.late_submission_minimum_percent).to eql BigDecimal('25.23')
|
||||
end
|
||||
|
||||
it 'only keeps 2 digits after the decimal for missing_submission_deduction' do
|
||||
policy = LatePolicy.new(missing_submission_deduction: 25.223)
|
||||
expect(policy.missing_submission_deduction).to eql BigDecimal.new('25.22')
|
||||
expect(policy.missing_submission_deduction).to eql BigDecimal('25.22')
|
||||
end
|
||||
|
||||
it 'rounds missing_submission_deduction' do
|
||||
policy = LatePolicy.new(missing_submission_deduction: 25.225)
|
||||
expect(policy.missing_submission_deduction).to eql BigDecimal.new('25.23')
|
||||
expect(policy.missing_submission_deduction).to eql BigDecimal('25.23')
|
||||
end
|
||||
|
||||
it 'only keeps 2 digits after the decimal for late_submission_deduction' do
|
||||
policy = LatePolicy.new(late_submission_deduction: 25.223)
|
||||
expect(policy.late_submission_deduction).to eql BigDecimal.new('25.22')
|
||||
expect(policy.late_submission_deduction).to eql BigDecimal('25.22')
|
||||
end
|
||||
|
||||
it 'rounds late_submission_deduction' do
|
||||
policy = LatePolicy.new(late_submission_deduction: 25.225)
|
||||
expect(policy.late_submission_deduction).to eql BigDecimal.new('25.23')
|
||||
expect(policy.late_submission_deduction).to eql BigDecimal('25.23')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue