Attempt to fix Hash#rehash spec

This commit is contained in:
Benoit Daloze 2019-07-31 11:04:35 +02:00
parent 14eede6e53
commit eab6c534ad

View File

@ -3,23 +3,26 @@ require_relative 'fixtures/classes'
describe "Hash#rehash" do
it "reorganizes the hash by recomputing all key hash codes" do
k1 = [1]
k2 = [2]
k1 = Object.new
k2 = Object.new
def k1.hash; 0; end
def k2.hash; 1; end
h = {}
h[k1] = 0
h[k2] = 1
h[k1] = :v1
h[k2] = :v2
k1 << 2
def k1.hash; 1; end
# if k1 is modified to k1', k1.hash and k1'.hash can be same.
# So this test has an issue. For the present, this line is commented out.
# h.key?(k1).should == false
# The key should no longer be found as the #hash changed.
# Hash values 0 and 1 should not conflict, even with 1-bit stored hash.
h.key?(k1).should == false
h.keys.include?(k1).should == true
h.rehash.should equal(h)
h.key?(k1).should == true
h[k1].should == 0
h[k1].should == :v1
k1 = mock('k1')
k2 = mock('k2')