diff --git a/lib/sass/value/fuzzy_math.rb b/lib/sass/value/fuzzy_math.rb index f00aa34d..019cef70 100644 --- a/lib/sass/value/fuzzy_math.rb +++ b/lib/sass/value/fuzzy_math.rb @@ -6,9 +6,9 @@ module Value module FuzzyMath PRECISION = 10 - EPSILON = 10**-PRECISION + EPSILON = 10**(-PRECISION - 1) - INVERSE_EPSILON = 10**PRECISION + INVERSE_EPSILON = 10**(PRECISION + 1) module_function diff --git a/spec/sass/value/number_spec.rb b/spec/sass/value/number_spec.rb index aa204b19..6017ba6a 100644 --- a/spec/sass/value/number_spec.rb +++ b/spec/sass/value/number_spec.rb @@ -74,15 +74,15 @@ end it 'equals the same number within precision tolerance' do - expect(number).to eq(described_class.new(123 + 10.pow(-precision - 1))) - expect(number).to eq(described_class.new(123 - 10.pow(-precision - 1))) + expect(number).to eq(described_class.new(123 + 10.pow(-precision - 2))) + expect(number).to eq(described_class.new(123 - 10.pow(-precision - 2))) end it "doesn't equal a different number" do expect(number).not_to eq(described_class.new(122)) expect(number).not_to eq(described_class.new(124)) - expect(number).not_to eq(described_class.new(123 + 10.pow(-precision))) - expect(number).not_to eq(described_class.new(123 - 10.pow(-precision))) + expect(number).not_to eq(described_class.new(123 + 10.pow(-precision - 1))) + expect(number).not_to eq(described_class.new(123 - 10.pow(-precision - 1))) end it "doesn't equal a number with units" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d89947b7..1f9a83d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,9 +55,9 @@ expect(actual.channels_or_nil).to fuzzy_match_array(expected.channels_or_nil) expect(actual.channel_missing?('alpha')).to eq(expected.channel_missing?('alpha')) expect(actual.alpha).to fuzzy_eq(expected.alpha) - expect(actual).to eq(expected) + # expect(actual).to eq(expected) when Numeric - expect(actual).to be_within((10**-precision) / 2).of(expected.round(precision)) + expect(actual).to be_within(10**-precision).of(expected) else expect(actual).to eq(expected) end @@ -68,7 +68,7 @@ match do |actual| expect(actual).to match_array(expected.map do |obj| if obj.is_a?(Numeric) - a_value_within((10**-precision) / 2).of(obj.round(precision)) + a_value_within(10**-precision).of(obj) else obj end