00001 <?php
00002
00003
00004 require_once('PHPUnit/Framework.php');
00005
00006
00007 require_once('../TextStatistics.php');
00008
00009 class TextStatisticsTest extends PHPUnit_Framework_TestCase {
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 protected $TextStatistics = null;
00020
00021 public function setUp() {
00022 $this->TextStatistics = new TextStatistics();
00023 }
00024
00025 public function tearDown() {
00026 unset($this->objTextStatistics);
00027 }
00028
00029
00030
00031
00032 public function testSyllableCountBasicWords() {
00033 $this->assertEquals(1, $this->TextStatistics->syllable_count('a'));
00034 $this->assertEquals(1, $this->TextStatistics->syllable_count('was'));
00035 $this->assertEquals(1, $this->TextStatistics->syllable_count('the'));
00036 $this->assertEquals(1, $this->TextStatistics->syllable_count('and'));
00037 $this->assertEquals(2, $this->TextStatistics->syllable_count('foobar'));
00038 $this->assertEquals(2, $this->TextStatistics->syllable_count('hello'));
00039 $this->assertEquals(1, $this->TextStatistics->syllable_count('world'));
00040 $this->assertEquals(3, $this->TextStatistics->syllable_count('wonderful'));
00041 $this->assertEquals(2, $this->TextStatistics->syllable_count('simple'));
00042 $this->assertEquals(2, $this->TextStatistics->syllable_count('easy'));
00043 $this->assertEquals(1, $this->TextStatistics->syllable_count('hard'));
00044 $this->assertEquals(1, $this->TextStatistics->syllable_count('quick'));
00045 $this->assertEquals(1, $this->TextStatistics->syllable_count('brown'));
00046 $this->assertEquals(1, $this->TextStatistics->syllable_count('fox'));
00047 $this->assertEquals(1, $this->TextStatistics->syllable_count('jumped'));
00048 $this->assertEquals(2, $this->TextStatistics->syllable_count('over'));
00049 $this->assertEquals(2, $this->TextStatistics->syllable_count('lazy'));
00050 $this->assertEquals(1, $this->TextStatistics->syllable_count('dog'));
00051 $this->assertEquals(3, $this->TextStatistics->syllable_count('camera'));
00052 }
00053
00054 public function testSyllableCountComplexWords() {
00055 $this->assertEquals(12, $this->TextStatistics->syllable_count('antidisestablishmentarianism'));
00056 $this->assertEquals(14, $this->TextStatistics->syllable_count('supercalifragilisticexpialidocious'));
00057 $this->assertEquals(8, $this->TextStatistics->syllable_count('chlorofluorocarbonation'));
00058 $this->assertEquals(4, $this->TextStatistics->syllable_count('forethoughtfulness'));
00059 $this->assertEquals(4, $this->TextStatistics->syllable_count('phosphorescent'));
00060 $this->assertEquals(5, $this->TextStatistics->syllable_count('theoretician'));
00061 $this->assertEquals(5, $this->TextStatistics->syllable_count('promiscuity'));
00062 $this->assertEquals(4, $this->TextStatistics->syllable_count('unbutlering'));
00063 $this->assertEquals(5, $this->TextStatistics->syllable_count('continuity'));
00064 $this->assertEquals(1, $this->TextStatistics->syllable_count('craunched'));
00065 $this->assertEquals(1, $this->TextStatistics->syllable_count('squelched'));
00066 $this->assertEquals(1, $this->TextStatistics->syllable_count('scrounge'));
00067 $this->assertEquals(1, $this->TextStatistics->syllable_count('coughed'));
00068 $this->assertEquals(1, $this->TextStatistics->syllable_count('smile'));
00069 $this->assertEquals(4, $this->TextStatistics->syllable_count('monopoly'));
00070 $this->assertEquals(2, $this->TextStatistics->syllable_count('doughey'));
00071 $this->assertEquals(3, $this->TextStatistics->syllable_count('doughier'));
00072 $this->assertEquals(4, $this->TextStatistics->syllable_count('leguminous'));
00073 $this->assertEquals(3, $this->TextStatistics->syllable_count('thoroughbreds'));
00074 $this->assertEquals(2, $this->TextStatistics->syllable_count('special'));
00075 $this->assertEquals(3, $this->TextStatistics->syllable_count('delicious'));
00076 $this->assertEquals(2, $this->TextStatistics->syllable_count('spatial'));
00077 $this->assertEquals(4, $this->TextStatistics->syllable_count('pacifism'));
00078 $this->assertEquals(4, $this->TextStatistics->syllable_count('coagulant'));
00079 $this->assertEquals(2, $this->TextStatistics->syllable_count('shouldn\'t'));
00080 $this->assertEquals(3, $this->TextStatistics->syllable_count('mcdonald'));
00081 $this->assertEquals(3, $this->TextStatistics->syllable_count('audience'));
00082 $this->assertEquals(2, $this->TextStatistics->syllable_count('finance'));
00083 $this->assertEquals(3, $this->TextStatistics->syllable_count('prevalence'));
00084 $this->assertEquals(5, $this->TextStatistics->syllable_count('impropriety'));
00085 $this->assertEquals(3, $this->TextStatistics->syllable_count('alien'));
00086 $this->assertEquals(2, $this->TextStatistics->syllable_count('dreadnought'));
00087 $this->assertEquals(3, $this->TextStatistics->syllable_count('verandah'));
00088 $this->assertEquals(3, $this->TextStatistics->syllable_count('similar'));
00089 $this->assertEquals(4, $this->TextStatistics->syllable_count('similarly'));
00090 $this->assertEquals(2, $this->TextStatistics->syllable_count('central'));
00091 $this->assertEquals(1, $this->TextStatistics->syllable_count('cyst'));
00092 $this->assertEquals(1, $this->TextStatistics->syllable_count('term'));
00093 $this->assertEquals(2, $this->TextStatistics->syllable_count('order'));
00094 $this->assertEquals(1, $this->TextStatistics->syllable_count('fur'));
00095 $this->assertEquals(2, $this->TextStatistics->syllable_count('sugar'));
00096 $this->assertEquals(2, $this->TextStatistics->syllable_count('paper'));
00097 $this->assertEquals(1, $this->TextStatistics->syllable_count('make'));
00098 $this->assertEquals(1, $this->TextStatistics->syllable_count('gem'));
00099 $this->assertEquals(2, $this->TextStatistics->syllable_count('program'));
00100 $this->assertEquals(2, $this->TextStatistics->syllable_count('hopeless'));
00101 $this->assertEquals(3, $this->TextStatistics->syllable_count('hopelessly'));
00102 $this->assertEquals(2, $this->TextStatistics->syllable_count('careful'));
00103 $this->assertEquals(3, $this->TextStatistics->syllable_count('carefully'));
00104 $this->assertEquals(2, $this->TextStatistics->syllable_count('stuffy'));
00105 $this->assertEquals(2, $this->TextStatistics->syllable_count('thistle'));
00106 $this->assertEquals(2, $this->TextStatistics->syllable_count('teacher'));
00107 $this->assertEquals(3, $this->TextStatistics->syllable_count('unhappy'));
00108 $this->assertEquals(5, $this->TextStatistics->syllable_count('ambiguity'));
00109 $this->assertEquals(4, $this->TextStatistics->syllable_count('validity'));
00110 $this->assertEquals(4, $this->TextStatistics->syllable_count('ambiguous'));
00111 $this->assertEquals(2, $this->TextStatistics->syllable_count('deserve'));
00112 $this->assertEquals(2, $this->TextStatistics->syllable_count('blooper'));
00113 $this->assertEquals(1, $this->TextStatistics->syllable_count('scooped'));
00114 $this->assertEquals(2, $this->TextStatistics->syllable_count('deserve'));
00115 $this->assertEquals(1, $this->TextStatistics->syllable_count('deal'));
00116 $this->assertEquals(1, $this->TextStatistics->syllable_count('death'));
00117 $this->assertEquals(1, $this->TextStatistics->syllable_count('dearth'));
00118 $this->assertEquals(1, $this->TextStatistics->syllable_count('deign'));
00119 $this->assertEquals(1, $this->TextStatistics->syllable_count('reign'));
00120 $this->assertEquals(2, $this->TextStatistics->syllable_count('bedsore'));
00121 $this->assertEquals(5, $this->TextStatistics->syllable_count('anorexia'));
00122 $this->assertEquals(3, $this->TextStatistics->syllable_count('anymore'));
00123 $this->assertEquals(1, $this->TextStatistics->syllable_count('cored'));
00124 $this->assertEquals(1, $this->TextStatistics->syllable_count('sore'));
00125 $this->assertEquals(2, $this->TextStatistics->syllable_count('foremost'));
00126 $this->assertEquals(2, $this->TextStatistics->syllable_count('restore'));
00127 $this->assertEquals(2, $this->TextStatistics->syllable_count('minute'));
00128 $this->assertEquals(3, $this->TextStatistics->syllable_count('manticores'));
00129 $this->assertEquals(4, $this->TextStatistics->syllable_count('asparagus'));
00130 $this->assertEquals(3, $this->TextStatistics->syllable_count('unexplored'));
00131 $this->assertEquals(4, $this->TextStatistics->syllable_count('unexploded'));
00132 $this->assertEquals(3, $this->TextStatistics->syllable_count('CAPITALS'));
00133 }
00134
00135
00136
00137
00138
00139 public function testSyllableCountProgrammedExceptions() {
00140 $this->assertEquals(3, $this->TextStatistics->syllable_count('simile'));
00141
00142
00143 $this->assertEquals(2, $this->TextStatistics->syllable_count('shoreline'));
00144 $this->assertEquals(3, $this->TextStatistics->syllable_count('forever'));
00145 }
00146
00147 public function testAverageSyllablesPerWord() {
00148 $this->assertEquals(1, $this->TextStatistics->average_syllables_per_word('and then there was one'));
00149 $this->assertEquals(2, $this->TextStatistics->average_syllables_per_word('because special ducklings deserve rainbows'));
00150 $this->assertEquals(1.5, $this->TextStatistics->average_syllables_per_word('and then there was one because special ducklings deserve rainbows'));
00151 }
00152
00153
00154
00155
00156 public function testWordCount() {
00157 $this->assertEquals(9, $this->TextStatistics->word_count('The quick brown fox jumped over the lazy dog'));
00158 $this->assertEquals(9, $this->TextStatistics->word_count('The quick brown fox jumped over the lazy dog.'));
00159 $this->assertEquals(9, $this->TextStatistics->word_count('The quick brown fox jumped over the lazy dog. '));
00160 $this->assertEquals(9, $this->TextStatistics->word_count(' The quick brown fox jumped over the lazy dog. '));
00161 $this->assertEquals(9, $this->TextStatistics->word_count(' The quick brown fox jumped over the lazy dog. '));
00162 $this->assertEquals(2, $this->TextStatistics->word_count('Yes. No.'));
00163 $this->assertEquals(2, $this->TextStatistics->word_count('Yes.No.'));
00164 $this->assertEquals(2, $this->TextStatistics->word_count('Yes.No.'));
00165 $this->assertEquals(2, $this->TextStatistics->word_count('Yes . No.'));
00166 $this->assertEquals(2, $this->TextStatistics->word_count('Yes .No.'));
00167 $this->assertEquals(2, $this->TextStatistics->word_count('Yes - No. '));
00168 }
00169
00170 public function testCheckPercentageWordsWithThreeSyllables() {
00171 $this->assertEquals(9, number_format($this->TextStatistics->percentage_words_with_three_syllables('there is just one word with three syllables in this sentence')));
00172 $this->assertEquals(9, number_format($this->TextStatistics->percentage_words_with_three_syllables('there is just one word with three syllables in this sentence', true)));
00173 $this->assertEquals(0, number_format($this->TextStatistics->percentage_words_with_three_syllables('there are no valid words with three Syllables in this sentence', false)));
00174 $this->assertEquals(5, number_format($this->TextStatistics->percentage_words_with_three_syllables('there is one and only one word with three or more syllables in this long boring sentence of twenty words')));
00175 $this->assertEquals(10, number_format($this->TextStatistics->percentage_words_with_three_syllables('there are two and only two words with three or more syllables in this long sentence of exactly twenty words')));
00176 $this->assertEquals(5, number_format($this->TextStatistics->percentage_words_with_three_syllables('there is Actually only one valid word with three or more syllables in this long sentence of Exactly twenty words', false)));
00177 $this->assertEquals(0, number_format($this->TextStatistics->percentage_words_with_three_syllables('no long words in this sentence')));
00178 $this->assertEquals(0, number_format($this->TextStatistics->percentage_words_with_three_syllables('no long valid words in this sentence because the test ignores proper case words like this Behemoth', false)));
00179 }
00180
00181 public function testTextLengthCheck() {
00182 $this->assertEquals(1, $this->TextStatistics->letter_count('a'));
00183 $this->assertEquals(0, $this->TextStatistics->letter_count(''));
00184 $this->assertEquals(46, $this->TextStatistics->letter_count('this sentence has 30 characters, not including the digits'));
00185 }
00186
00187
00188
00189
00190 public function testSentenceCount() {
00191 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence'));
00192 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence.'));
00193 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence!'));
00194 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence?'));
00195 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence..'));
00196 $this->assertEquals(2, $this->TextStatistics->sentence_count('This is a sentence. So is this.'));
00197 $this->assertEquals(2, $this->TextStatistics->sentence_count("This is a sentence. \n\n So is this, but this is multi-line!"));
00198 $this->assertEquals(2, $this->TextStatistics->sentence_count('This is a sentence,. So is this.'));
00199 $this->assertEquals(2, $this->TextStatistics->sentence_count('This is a sentence!? So is this.'));
00200 $this->assertEquals(3, $this->TextStatistics->sentence_count('This is a sentence. So is this. And this one as well.'));
00201 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence - but just one.'));
00202 $this->assertEquals(1, $this->TextStatistics->sentence_count('This is a sentence (but just one).'));
00203 }
00204
00205 public function testAverageWordsPerSentence() {
00206 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This is a sentence'));
00207 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This is a sentence.'));
00208 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This is a sentence. '));
00209 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This is a sentence. This is a sentence'));
00210 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This is a sentence. This is a sentence.'));
00211 $this->assertEquals(4, $this->TextStatistics->average_words_per_sentence('This, is - a sentence . This is a sentence. '));
00212 $this->assertEquals(5.5, $this->TextStatistics->average_words_per_sentence('This is a sentence with extra text. This is a sentence. '));
00213 $this->assertEquals(6, $this->TextStatistics->average_words_per_sentence('This is a sentence with some extra text. This is a sentence. '));
00214 }
00215
00216
00217
00218
00219
00220
00221
00222 public function testFleschKincaidReadingEase() {
00223 $this->assertEquals(121.2, $this->TextStatistics->flesch_kincaid_reading_ease('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00224 $this->assertEquals(94.3, $this->TextStatistics->flesch_kincaid_reading_ease('The quick brown fox jumped over the lazy dog.'));
00225 $this->assertEquals(94.3, $this->TextStatistics->flesch_kincaid_reading_ease('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00226 $this->assertEquals(94.3, $this->TextStatistics->flesch_kincaid_reading_ease('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00227 $this->assertEquals(94.3, $this->TextStatistics->flesch_kincaid_reading_ease("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00228 $this->assertEquals(50.5, $this->TextStatistics->flesch_kincaid_reading_ease('Now it is time for a more complicated sentence, including several longer words.'));
00229 }
00230
00231 public function testFleschKincaidGradeLevel() {
00232 $this->assertEquals(-3.4, $this->TextStatistics->flesch_kincaid_grade_level('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00233 $this->assertEquals(2.3, $this->TextStatistics->flesch_kincaid_grade_level('The quick brown fox jumped over the lazy dog.'));
00234 $this->assertEquals(2.3, $this->TextStatistics->flesch_kincaid_grade_level('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00235 $this->assertEquals(2.3, $this->TextStatistics->flesch_kincaid_grade_level('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00236 $this->assertEquals(2.3, $this->TextStatistics->flesch_kincaid_grade_level("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00237 $this->assertEquals(9.4, $this->TextStatistics->flesch_kincaid_grade_level('Now it is time for a more complicated sentence, including several longer words.'));
00238 }
00239
00240 public function testGunningFogScore() {
00241 $this->assertEquals(0.4, $this->TextStatistics->gunning_fog_score('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00242 $this->assertEquals(3.6, $this->TextStatistics->gunning_fog_score('The quick brown fox jumped over the lazy dog.'));
00243 $this->assertEquals(3.6, $this->TextStatistics->gunning_fog_score('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00244 $this->assertEquals(3.6, $this->TextStatistics->gunning_fog_score("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00245 $this->assertEquals(3.6, $this->TextStatistics->gunning_fog_score('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00246 $this->assertEquals(14.4, $this->TextStatistics->gunning_fog_score('Now it is time for a more complicated sentence, including several longer words.'));
00247 $this->assertEquals(8.3, $this->TextStatistics->gunning_fog_score('Now it is time for a more Complicated sentence, including Several longer words.'));
00248 }
00249
00250 public function testColemanLiauIndex() {
00251 $this->assertEquals(3.0, $this->TextStatistics->coleman_liau_index('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00252 $this->assertEquals(7.7, $this->TextStatistics->coleman_liau_index('The quick brown fox jumped over the lazy dog.'));
00253 $this->assertEquals(7.7, $this->TextStatistics->coleman_liau_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00254 $this->assertEquals(7.7, $this->TextStatistics->coleman_liau_index("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00255 $this->assertEquals(7.7, $this->TextStatistics->coleman_liau_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00256 $this->assertEquals(13.6, $this->TextStatistics->coleman_liau_index('Now it is time for a more complicated sentence, including several longer words.'));
00257 }
00258
00259 public function testSMOGIndex() {
00260 $this->assertEquals(1.8, $this->TextStatistics->smog_index('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00261 $this->assertEquals(1.8, $this->TextStatistics->smog_index('The quick brown fox jumped over the lazy dog.'));
00262 $this->assertEquals(1.8, $this->TextStatistics->smog_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00263 $this->assertEquals(1.8, $this->TextStatistics->smog_index("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00264 $this->assertEquals(1.8, $this->TextStatistics->smog_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00265 $this->assertEquals(10.1, $this->TextStatistics->smog_index('Now it is time for a more complicated sentence, including several longer words.'));
00266 }
00267
00268 public function testAutomatedReadabilityIndex() {
00269 $this->assertEquals(-5.6, $this->TextStatistics->automated_readability_index('This. Is. A. Nice. Set. Of. Small. Words. Of. One. Part. Each.'));
00270 $this->assertEquals(1.9, $this->TextStatistics->automated_readability_index('The quick brown fox jumped over the lazy dog.'));
00271 $this->assertEquals(1.9, $this->TextStatistics->automated_readability_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.'));
00272 $this->assertEquals(1.9, $this->TextStatistics->automated_readability_index("The quick brown fox jumped over the lazy dog. \n\n The quick brown fox jumped over the lazy dog."));
00273 $this->assertEquals(1.9, $this->TextStatistics->automated_readability_index('The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog'));
00274 $this->assertEquals(8.6, $this->TextStatistics->automated_readability_index('Now it is time for a more complicated sentence, including several longer words.'));
00275 }
00276
00277 }
00278
00279 ?>