found and fixed hashing bug

This commit is contained in:
Torsten Ruger 2016-12-31 14:04:04 +02:00
parent d6c503ecf4
commit 0fa7f54bcc
2 changed files with 9 additions and 4 deletions

View File

@ -47,7 +47,7 @@ module Parfait
def self.hash_code_for_hash( dict ) def self.hash_code_for_hash( dict )
index = 1 index = 1
hash_code = 5467 hash_code = str_hash(dict[:type])
dict.each do |name , type| dict.each do |name , type|
next if name == :type next if name == :type
item_hash = str_hash(name) + str_hash(type) item_hash = str_hash(name) + str_hash(type)

View File

@ -22,12 +22,12 @@ class TypeHash < MiniTest::Test
end end
def test_name def test_name
assert_equal "BinaryCode_Type" , @types.values.first.name assert_equal "Word_Type" , @types.values.first.name
end end
def test_to_hash def test_to_hash
assert_equal "BinaryCode_Type" , @first.name assert_equal "Word_Type" , @first.name
assert_equal :BinaryCode , @first.object_class.name assert_equal :Word , @first.object_class.name
hash = @first.to_hash hash = @first.to_hash
assert_equal :Type , @first.types.first assert_equal :Type , @first.types.first
assert_equal hash[:type] , :Type assert_equal hash[:type] , :Type
@ -51,4 +51,9 @@ class TypeHash < MiniTest::Test
assert @first.hash != type.hash assert @first.hash != type.hash
end 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 end