From 0fa7f54bcc50c212543a8b1f3511cf32e401aef9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 31 Dec 2016 14:04:04 +0200 Subject: [PATCH] found and fixed hashing bug --- lib/typed/parfait/type.rb | 2 +- test/typed/type/test_hash.rb | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/typed/parfait/type.rb b/lib/typed/parfait/type.rb index 8f4b48fe..2ba9c334 100644 --- a/lib/typed/parfait/type.rb +++ b/lib/typed/parfait/type.rb @@ -47,7 +47,7 @@ module Parfait def self.hash_code_for_hash( dict ) index = 1 - hash_code = 5467 + hash_code = str_hash(dict[:type]) dict.each do |name , type| next if name == :type item_hash = str_hash(name) + str_hash(type) diff --git a/test/typed/type/test_hash.rb b/test/typed/type/test_hash.rb index 92e01791..610f1aba 100644 --- a/test/typed/type/test_hash.rb +++ b/test/typed/type/test_hash.rb @@ -22,12 +22,12 @@ class TypeHash < MiniTest::Test end def test_name - assert_equal "BinaryCode_Type" , @types.values.first.name + assert_equal "Word_Type" , @types.values.first.name end def test_to_hash - assert_equal "BinaryCode_Type" , @first.name - assert_equal :BinaryCode , @first.object_class.name + assert_equal "Word_Type" , @first.name + assert_equal :Word , @first.object_class.name hash = @first.to_hash assert_equal :Type , @first.types.first assert_equal hash[:type] , :Type @@ -51,4 +51,9 @@ class TypeHash < MiniTest::Test assert @first.hash != type.hash end + def test_hash_for_no_ivars + h1 = Parfait::Type.hash_code_for_hash( type: :NewInt) + h2 = Parfait::Type.hash_code_for_hash( type: :NewObj) + assert h1 != h2 , "Hashes should differ" + end end