Created
August 21, 2009 21:57
-
-
Save clarkgrubb/172463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fog_factor' | |
require 'test/unit' | |
class FogFactorTest < Test::Unit::TestCase | |
EPSILON = 0.01 | |
def test_syllable_count | |
words = { | |
'tame' => 1, | |
'Adam' => 2, | |
'dysentery' => 4, | |
'hot' => 1, | |
'what' => 1, | |
'the' => 1, | |
'a' => 1, | |
'I' => 1, | |
'thousands' => 2, | |
'antidisestablishmentarianism' => 11, | |
'boat' => 1, | |
'friend' => 1, | |
'fried' => 1, | |
'international' => 5, | |
'yield' => 1, | |
'yoyo' => 2, | |
'millions' => 2, | |
'horticulture' => 4, | |
'Hawaii' => 3, | |
'team' => 1, | |
'measures' => 2, | |
} | |
words.each do |word, syllable_count| | |
assert(syllable_count == FogFactor.syllable_count(word), "Expected #{syllable_count} syllables in #{word}") | |
end | |
end | |
def test_fog_factor | |
sentence1 = "The 'fog factor' is a writer's yardstick to measure the acceptability of written work. It measures tautology, padded syllables, sentence length, multi-syllable words and other factors as a guide to meaningful writing. Simply put, it measures how easy and pleasant it is to read your message." | |
a1 = 46 | |
b1 = 3 | |
c1 = 5 | |
expected_fog1 = (a1.to_f/b1 + c1.to_f/a1) * 0.4 | |
fog1 = FogFactor.fog_factor(sentence1) | |
assert((expected_fog1 - fog1).abs < EPSILON, "Expected fog #{expected_fog1}, got fog #{fog1}") | |
sentence2 = "See Spot run. Run, Spot, Run!" | |
#words | |
a2 = 6 | |
#sentences | |
b2 = 2 | |
#trisyllabic or bigger words | |
c2 = 0 | |
expected_fog2 = (a2.to_f/b2 + c2.to_f/a2) * 0.4 | |
fog2 = FogFactor.fog_factor(sentence2) | |
assert((expected_fog2 - fog2).abs < EPSILON, "Expected fog #{expected_fog2}, got fog #{fog2}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment