2004-09-29 (Wed)
_ [Ruby] Hashを使ったコードのテスト
Hashを使ったコードは、繰り返しの順序が不定なため、テストを 書きにくい時がある。 そういう時は、テストコードでHash#eachを再定義してしまえばよい。
class Hash
def each(&block)
to_a.sort_by { |k,v| k.to_s }.each(&block)
end
end
テストの方に入れるのがポイント。
[TrackBack URL: http://shugo.net/jit/tb.rb/20040929]
本日のリンク元
- http://bloger.x0.com/result/ne-yo/ne-yo Ne-Yo ×30
- http://press.eek.jp/result/yo/yo king ×13
- http://sheepman.parfait.ne.jp/ ×12
- http://bloger.x0.com/result/yo/yo king ×11
- http://press.eek.jp/result/浅田真央/浅田真央 家族 ×11
- http://bloger.x0.com/result/ne-yo/ne-yo you ×10
- http://bloger.x0.com/result/yo/yo e..ne ×6
- http://mixi.jp/new_friend_diary.pl ×5
- http://search.live.com/results.aspx?q=result ×4
- http://sbs.mobile.yahoo.co.jp/p/sbs/mobilesite/sea... ×3
- http://blog.chew.jp/result/ne-yo/ne-yo live ×3
- http://bloger.x0.com/result/ne-yo/ne-yo live ×3
- http://sheepman.parfait.ne.jp/20040928.html ×2
- http://search.live.com/results.aspx?q=result&form=... ×2
- http://search.live.com/results.aspx?q=mobile&mrt=e... ×2
- http://search.live.com/results.aspx?q=result&mrt=e... ×2
- http://mixi.jp/home.pl ×1
- http://sbs.mobile.yahoo.co.jp/union/search?fr=m_to... ×1
- http://www.moneylending-navi.com/ ×1
- http://sheepman.parfait.ne.jp/200401.html ×1
- http://64.233.179.104/translate_c?hl=en&sl=ja&u=ht... ×1
- http://jig124.mobile.ogk.yahoo.co.jp/fweb/0309eMjJ... ×1
- http://looseend.ddo.jp/blog/9 ×1
- http://press.eek.jp/result/yo/yo ne- ×1
- http://sbs.mobile.yahoo.co.jp/p/sbs/mobilesite/sea... ×1
- http://bloger.x0.com/result/yo/ne yo ×1
- http://pinkey.dip.jp/diary2/浅田真央/浅田真央 グランプリ/200709... ×1
- http://209.85.175.104/search?q=cache:OdPhAW8ENsgJ:... ×1
- http://bloger.x0.com/result/king/yo king ×1
- http://www.moneylending-navi.com/クレジットカード キャッシング/ ×1
- http://search.live.com/images/results.aspx?q=誕生日ケー... ×1
- http://sbs.mobile.yahoo.co.jp/p/sbs/mobilesite/sea... ×1
- http://arton.no-ip.info/diary/20061129.html ×1
- http://www.yo.rim.or.jp/~nov/d/?200408a&to=2004080... ×1
- http://209.85.173.104/search?q=cache:OdPhAW8ENsgJ:... ×1
- http://sqs.cmr.sfc.keio.ac.jp/tdiary/20060823.html... ×1
- http://sbs.mobile.yahoo.co.jp/union/search?p=誕生日 コ... ×1
- http://209.85.173.104/search?q=cache:OdPhAW8ENsgJ:... ×1
- http://caojon.seesaa.net/article/128490.html ×1
- http://hsbt.que.ne.jp/hiki/hiki.cgi?ReferrerSPAM ×1
- http://jjjjjj.ddo.jp/www/yws_wd=ne-yo live|page=1.... ×1
- http://www.hsbt.org/hiki/hiki.cgi?ReferrerSPAM ×1
- http://www.food-prejudice-king.com/ ×1
- http://press.eek.jp/result/yo/yo ne ×1


なああああるほどぉぉぉ>Hash