Skip to content

Commit

Permalink
Revert fuzzy equal precision
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Oct 1, 2024
1 parent 6e34139 commit 5baf3d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/sass/value/fuzzy_math.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions spec/sass/value/number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5baf3d8

Please sign in to comment.