Skip to content

Commit 6e34139

Browse files
authored
Align fuzzy equality with format precision (#239)
1 parent 5be339d commit 6e34139

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

lib/sass/value/fuzzy_math.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Sass
44
module Value
55
# Sass's {FuzzyMath} module.
66
module FuzzyMath
7-
PRECISION = 11
7+
PRECISION = 10
88

99
EPSILON = 10**-PRECISION
1010

spec/sass/value/number_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# @see https://github.com/sass/sass-spec/blob/main/js-api-spec/value/number.test.ts
66
describe Sass::Value::Number do
77
let(:precision) do
8-
10
8+
Sass::Value.const_get(:FuzzyMath)::PRECISION
99
end
1010

1111
describe 'unitless' do
@@ -74,15 +74,15 @@
7474
end
7575

7676
it 'equals the same number within precision tolerance' do
77-
expect(number).to eq(described_class.new(123 + 10.pow(-precision - 2)))
78-
expect(number).to eq(described_class.new(123 - 10.pow(-precision - 2)))
77+
expect(number).to eq(described_class.new(123 + 10.pow(-precision - 1)))
78+
expect(number).to eq(described_class.new(123 - 10.pow(-precision - 1)))
7979
end
8080

8181
it "doesn't equal a different number" do
8282
expect(number).not_to eq(described_class.new(122))
8383
expect(number).not_to eq(described_class.new(124))
84-
expect(number).not_to eq(described_class.new(123 + 10.pow(-precision - 1)))
85-
expect(number).not_to eq(described_class.new(123 - 10.pow(-precision - 1)))
84+
expect(number).not_to eq(described_class.new(123 + 10.pow(-precision)))
85+
expect(number).not_to eq(described_class.new(123 - 10.pow(-precision)))
8686
end
8787

8888
it "doesn't equal a number with units" do

spec/spec_helper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
supports_block_expectations
4545
end
4646

47-
precision = Sass::Value.const_get(:FuzzyMath)::PRECISION - 1
47+
precision = Sass::Value.const_get(:FuzzyMath)::PRECISION
4848

4949
RSpec::Matchers.matcher :fuzzy_eq do |expected|
5050
match do |actual|
@@ -55,8 +55,9 @@
5555
expect(actual.channels_or_nil).to fuzzy_match_array(expected.channels_or_nil)
5656
expect(actual.channel_missing?('alpha')).to eq(expected.channel_missing?('alpha'))
5757
expect(actual.alpha).to fuzzy_eq(expected.alpha)
58+
expect(actual).to eq(expected)
5859
when Numeric
59-
expect(actual).to be_within(((10**-precision) / 2)).of(expected.round(precision))
60+
expect(actual).to be_within((10**-precision) / 2).of(expected.round(precision))
6061
else
6162
expect(actual).to eq(expected)
6263
end

0 commit comments

Comments
 (0)