[前][次][番号順一覧][スレッド一覧]

ruby-changes:56720

From: Benoit <ko1@a...>
Date: Wed, 31 Jul 2019 18:05:14 +0900 (JST)
Subject: [ruby-changes:56720] Benoit Daloze: eab6c534ad (master): Attempt to fix Hash#rehash spec

https://git.ruby-lang.org/ruby.git/commit/?id=eab6c534ad

From eab6c534adb381b81291e871cd57c957cf786503 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Wed, 31 Jul 2019 11:04:35 +0200
Subject: Attempt to fix Hash#rehash spec


diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb
index 2af287c..1bf4753 100644
--- a/spec/ruby/core/hash/rehash_spec.rb
+++ b/spec/ruby/core/hash/rehash_spec.rb
@@ -3,23 +3,26 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/hash/rehash_spec.rb#L3
 
 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')
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]