From: walter@... Date: 2004-04-15T23:37:30+09:00 Subject: Re: Hash == not always working? Or am I missing something? > >>>>> "w" == walter writes: > > w> results = Hash.new{|h,k| h[k] = 0} > > [...] > > w> expected = {} > > your 2 Hash are not the same : they don't use the same default value > > > Guy Decoux > > > Thanks for the response Guy, I changed both hashes to be created by Hash.new{|h,k| h[k] = 0} but I still get the error..... module ShipToCleanUp def notes results = [] 1.upto(6) do |i| results << send("note#{i}") end results.join(" ").strip end def word_counts results = Hash.new{|h,k| h[k] = 0} notes.split(/\s+/).each{|word| results[word]+=1} results end end if __FILE__ == $0 require 'test/unit' class ShipToCleanUpTester < Test::Unit::TestCase class ShipTo include ShipToCleanUp attr_accessor :note1, :note2, :note3, :note4, :note5, :note6 def initialize(n1='', n2='', n3='', n4='', n5='', n6='') @note1, @note2, @note3, @note4, @note5, @note6 = n1, n2, n3, n4, n5, n6 end end def setup @shipTo1 = ShipTo.new('LINE 1 AND SOME MORE ON LINE 1 ', ' ***** LINE 2 ***** ', '', '', 'LINE 5 ', 'AND LINE 6') end def test_word_counts expected = Hash.new{|h,k| h[k] = 0} expected['LINE'] = 5 expected['1'] = 2 expected['AND'] = 2 expected['SOME'] = 1 expected['MORE'] = 1 expected['ON'] = 1 expected['*****'] = 2 expected['2'] = 1 expected['5'] = 1 expected['6'] = 1 assert_equal(expected, @shipTo1.word_counts) end def test_notes_some_empty expected = "1 6" assert_equal(expected, ShipTo.new("1", '', '', '', '', '6').notes) end def test_notes_empty expected = "" assert_equal(expected, ShipTo.new.notes) end def test_notes expected = "LINE 1 AND SOME MORE ON LINE 1 ***** LINE 2 ***** LINE 5 AND LINE 6" assert_equal(expected, @shipTo1.notes) end end end Loaded suite C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/rbC.tmp Started ...F Finished in 0.04 seconds. 1) Failure: test_word_counts(ShipToCleanUpTester) [C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/rbC.tmp:46]: <{"6"=>1, "AND"=>2, "LINE"=>5, "*****"=>2, "1"=>2, "2"=>1, "ON"=>1, "SOME"=>1, "5"=>1, "MORE"=>1}> expected but was <{"6"=>1, "AND"=>2, "LINE"=>5, "*****"=>2, "1"=>2, "2"=>1, "ON"=>1, "SOME"=>1, "5"=>1, "MORE"=>1}>. 4 tests, 4 assertions, 1 failures, 0 errors ***************************************************** Walter Szewelanczyk IS Director M.W. Sewall & CO. email : walter@mwsewall.com 259 Front St. Phone : (207) 442-7994 x 128 Bath, ME 04530 Fax : (207) 443-6284 *****************************************************