Skip to content

Commit

Permalink
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions spec/std/hash_spec.cr
Original file line number Diff line number Diff line change
@@ -714,8 +714,20 @@ describe "Hash" do
items.uniq.size
end

# Check that Hash can be created with an initial capacity
typeof(Hash(Int32, Int32).new(initial_capacity: 1234))
typeof(Hash(Int32, Int32).new(0, initial_capacity: 1234))
typeof(Hash(Int32, Int32).new(initial_capacity: 1234) { |h, k| h[k] = 0 })
it "creates with initial capacity" do
hash = Hash(Int32, Int32).new(initial_capacity: 1234)
hash.@buckets_size.should eq(1234)
end

it "creates with initial capacity and default value" do
hash = Hash(Int32, Int32).new(default_value: 3, initial_capacity: 1234)
hash[1].should eq(3)
hash.@buckets_size.should eq(1234)
end

it "creates with initial capacity and block" do
hash = Hash(Int32, Int32).new(initial_capacity: 1234) { |h, k| h[k] = 3 }
hash[1].should eq(3)
hash.@buckets_size.should eq(1234)
end
end
2 changes: 1 addition & 1 deletion src/hash.cr
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class Hash(K, V)
end

def self.new(initial_capacity = nil, &block : (Hash(K, V), K -> V))
new block
new block, initial_capacity: initial_capacity
end

def self.new(default_value : V, initial_capacity = nil)

0 comments on commit c0b0e3f

Please sign in to comment.