mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

By always passing around a single, unnested array rather than splatting and then defensively flattening and compacting things, we can avoid allocating a bunch of unnecessary arrays. This gives a performance boost of roughly 4% when enumerating 2500 formulae, and has the side effect of cleaning up the dependency API.
42 lines
1.1 KiB
Ruby
42 lines
1.1 KiB
Ruby
require 'testing_env'
|
|
require 'extend/set'
|
|
require 'requirements'
|
|
|
|
class ComparableSetTests < Test::Unit::TestCase
|
|
def setup
|
|
@set = ComparableSet.new
|
|
end
|
|
|
|
def test_merging_multiple_dependencies
|
|
@set << X11Dependency.new
|
|
@set << X11Dependency.new
|
|
assert_equal 1, @set.count
|
|
@set << Requirement.new
|
|
assert_equal 2, @set.count
|
|
end
|
|
|
|
def test_comparison_prefers_larger
|
|
@set << X11Dependency.new
|
|
@set << X11Dependency.new('x11', %w{2.6})
|
|
assert_equal 1, @set.count
|
|
assert_equal [X11Dependency.new('x11', %w{2.6})], @set.to_a
|
|
end
|
|
|
|
def test_comparison_does_not_merge_smaller
|
|
@set << X11Dependency.new('x11', %w{2.6})
|
|
@set << X11Dependency.new
|
|
assert_equal 1, @set.count
|
|
assert_equal [X11Dependency.new('x11', %w{2.6})], @set.to_a
|
|
end
|
|
|
|
def test_merging_sets
|
|
@set << X11Dependency.new
|
|
@set << Requirement.new
|
|
reqs = Set.new [X11Dependency.new('x11', %w{2.6}), Requirement.new]
|
|
assert_same @set, @set.merge(reqs)
|
|
|
|
assert_equal 2, @set.count
|
|
assert_equal X11Dependency.new('x11', %w{2.6}), @set.find {|r| r.is_a? X11Dependency}
|
|
end
|
|
end
|