require 'test/unit' require 'FakeSentence' # to be tested # FakeSentence unit test class from hacking project # -- # Copyleft 2009 adric@adric.net, Artistic License class FakeSentenceTest < Test::Unit::TestCase LIST_SIZE = 234936 FS_LENGTH=8 def setup @fsf = FakeSentenceMaker.new @wah = @fsf.wordlist @sent = @fsf.get_sentence end def teardown @fsf = nil end ## Dummy test def test_something @expected,@actual = Math::PI,Math::PI assert_equal(@expected, @actual) end ## Should match if I'm keeping the constant up to date def test_wordlist_size assert_equal(LIST_SIZE,@fsf.wordlist.size) end ## We should always get a word pattern: word-boundry at least one non white space word-boundry def test_pick_word_returns_word assert @wah.pick_word.match /\w.+\w/ end ## Sentence length should default to class constant FS_LENGTH if none specified def test_fs_has_default_number_of_words assert_equal(FS_LENGTH,@sent.wc) end ## Sentence length should match requested length def test_fs_gives_correct_number_of_words 35.times do l = rand(144) sut = @fsf.get_sentence(l) assert_equal(l, sut.wc ) end end end