今さらなんですが、最近 eXtreme Programing (XP) をお勉強してます。そんなわけで、テストファーストプログラミングを導入してみました。
fukumotoは ruby 使いの端くれなので、もちろん ruby でテストファーストです。ruby の世界では、RubyUnitあたりが有名どころっぽいので、インストールして数週間使ってみました。
結論から言うと、非常に良いです。他への波及を気にせずにがしがし変更できるのは精神衛生上非常によろしい。それに、自分で書いてからちょっと間を置いたライブラリ (もちろんドキュメントなし) を使わねばならないとき、テストをみると実使用例が書いてあるというのは思いの外便利です。もう、これなしでは、大きめの部品づくりはできないかも。
使用方法なんですが、RubyUnitのページをみると一見面倒そうに見えますが、実際には雛形をコピーしてきて、assert_equal() と assert_exception() だけ知ってればとりあえず使えます。fukumotoもこの 2 つくらいしか使ってません。
ちなみに、comjong.com用の手牌ライブラリのテストはこんな感じ。実際には、もう少したくさんのテストパターンがあるし、例外のテストもあるけど省略。
#!/usr/local/bin/ruby
require 'runit/testcase'
require 'runit/cui/testrunner'
require 'Hand'
class TestHand < RUNIT::TestCase
def initialize(*args)
super
end
def setup
end
def test_hand
h = Hand.new "b2 b2 b2 b4 b4 b5 b5 b5 b6 b6 b6 b8 ww"
assert_equal(3, h.combination["sets"])
assert_equal(1, h.combination["pairs"])
assert_equal(3, h.combination["headed_sets"])
assert_equal(1, h.combination["headed_pairs"])
assert_equal(1, h.to_ready)
h = Hand.new "b2 b4 b5 b5 b6 b8 c4 c5 c6 d4 d5 d6 ww"
assert_equal(3, h.combination["sets"])
assert_equal(0, h.combination["pairs"])
assert_equal(2, h.combination["headed_sets"])
assert_equal(3, h.combination["headed_pairs"])
assert_equal(1, h.to_ready)
h = Hand.new "c1 c1 c1 c2 c3 c4 c5 c6 c7 c8 c9 c9 c9"
assert_equal(4, h.combination["sets"])
assert_equal(0, h.combination["pairs"])
assert_equal(3, h.combination["headed_sets"])
assert_equal(2, h.combination["headed_pairs"])
assert_equal(0, h.to_ready)
end
def teardown
end
end
RUNIT::CUI::TestRunner.run(TestHand.suite)
昨日の更新時、amazon.rbからamazon.co.jpの画像が引けなくなっていた。調べてみると、原因はamazon.co.jpの仕様変更らしい。
tdiary/plugin/ja/amazon.rbを1.3.2.1に更新することで解決。
ToDo/ToBuy
Before...
_ fukumoto [とりあえず銀林みのる先生の "鉄塔武蔵野線" を読むべし。映画も観るべし。話はそれからだ。 ちょっとだけ解説すると、..]
_ ながさわ [鉄塔・・・美しいか? 構造物としての美しさならばダムor橋梁だと思うが。 自分のなかではちょっとしたダムブーム。しか..]
_ fukumoto [ふっ。まだ大衆には理解されないか……。 ダムとか橋とかは、自転車でお手軽に行ける近所にないし、ちょっと敷居が高そう。]