47 |
52 |
53 |
54 |
55 | -
56 | Overview
57 |
58 | -
59 | Class
60 |
61 |
63 |
65 |
66 |
67 |
1: <?php
68 | 2:
69 | 3: 4: 5:
72 | 6: class SentenceTest extends PHPUnit_Framework_TestCase {
73 | 7:
74 | 8: 9: 10:
77 | 11: protected $object;
78 | 12:
79 | 13: 14: 15: 16:
83 | 17: protected function setUp() {
84 | 18: $this->object = new Sentence;
85 | 19: }
86 | 20:
87 | 21: 22: 23:
90 | 24: public function testCountEmpty() {
91 | 25: $this->assertSame(0, $this->object->count(''));
92 | 26: $this->assertSame(0, $this->object->count(' '));
93 | 27: $this->assertSame(0, $this->object->count("\n"));
94 | 28: }
95 | 29:
96 | 30: 31: 32:
99 | 33: public function testCountWord() {
100 | 34: $this->assertSame(1, $this->object->count('Hello'));
101 | 35: $this->assertSame(1, $this->object->count('Hello.'));
102 | 36: $this->assertSame(1, $this->object->count('Hello...'));
103 | 37: $this->assertSame(1, $this->object->count('Hello!'));
104 | 38: $this->assertSame(1, $this->object->count('Hello?'));
105 | 39: $this->assertSame(1, $this->object->count('Hello?!'));
106 | 40: }
107 | 41:
108 | 42: 43: 44:
111 | 45: public function testCountTwoWords() {
112 | 46: $this->assertSame(1, $this->object->count('Hello world'));
113 | 47: $this->assertSame(1, $this->object->count('Hello world.'));
114 | 48: $this->assertSame(1, $this->object->count('Hello world...'));
115 | 49: $this->assertSame(1, $this->object->count('Hello world!'));
116 | 50: $this->assertSame(1, $this->object->count('Hello world?'));
117 | 51: $this->assertSame(1, $this->object->count('Hello world?!'));
118 | 52: }
119 | 53:
120 | 54: 55: 56:
123 | 57: public function testCountMultipleWords() {
124 | 58: $this->assertSame(2, $this->object->count('Hello world. Are you there'));
125 | 59: $this->assertSame(2, $this->object->count('Hello world. Are you there?'));
126 | 60: $this->assertSame(1, $this->object->count('Hello world, Are you there?'));
127 | 61: $this->assertSame(1, $this->object->count('Hello world: Are you there?'));
128 | 62: $this->assertSame(1, $this->object->count('Hello world... Are you there?'));
129 | 63: }
130 | 64:
131 | 65: 66: 67:
134 | 68: public function testCountLinebreaks() {
135 | 69: $this->assertSame(2, $this->object->count("Hello world...\rAre you there?"));
136 | 70: $this->assertSame(2, $this->object->count("Hello world...\nAre you there?"));
137 | 71: $this->assertSame(2, $this->object->count("Hello world...\r\nAre you there?"));
138 | 72: $this->assertSame(2, $this->object->count("Hello world...\r\n\rAre you there?"));
139 | 73: $this->assertSame(2, $this->object->count("Hello world...\n\r\nAre you there?"));
140 | 74: $this->assertSame(2, $this->object->count("Hello world...\n\nAre you there?"));
141 | 75: $this->assertSame(2, $this->object->count("Hello world...\r\rAre you there?"));
142 | 76: }
143 | 77:
144 | 78: 79: 80:
147 | 81: public function testCountAbreviations() {
148 | 82: $this->assertSame(1, $this->object->count("Hello mr. Smith."));
149 | 83: $this->assertSame(1, $this->object->count("Hello, OMG Kittens!"));
150 | 84: $this->assertSame(1, $this->object->count("Hello, abbrev. Kittens!"));
151 | 85: $this->assertSame(1, $this->object->count("Hello, O.M.G. Kittens!"));
152 | 86: }
153 | 87:
154 | 88: 89: 90:
157 | 91: public function testCountMultiplePunctuation() {
158 | 92: $this->assertSame(2, $this->object->count("Hello there. Brave new world."));
159 | 93: $this->assertSame(1, $this->object->count("Hello there... Brave new world."));
160 | 94: $this->assertSame(2, $this->object->count("Hello there?... Brave new world."));
161 | 95: $this->assertSame(2, $this->object->count("Hello there!... Brave new world."));
162 | 96: $this->assertSame(2, $this->object->count("Hello there!!! Brave new world."));
163 | 97: $this->assertSame(2, $this->object->count("Hello there??? Brave new world."));
164 | 98: }
165 | 99:
166 | 100: 101: 102:
169 | 103: public function testCountOneWordSentences() {
170 | 104: $this->assertSame(2, $this->object->count("You? Smith?"));
171 | 105: $this->assertSame(2, $this->object->count("You there? Smith?"));
172 | 106: $this->assertSame(1, $this->object->count("You mr. Smith?"));
173 | 107:
174 | 108: $this->assertSame(2, $this->object->count("Are you there. Smith, sir?"));
175 | 109: $this->assertSame(2, $this->object->count("Are you there. Mr. Smith?"));
176 | 110: }
177 | 111:
178 | 112: 113: 114:
181 | 115: public function testSplitEmpty() {
182 | 116: $this->assertSame(array(), $this->object->split(''));
183 | 117: $this->assertSame(array(), $this->object->split(' '));
184 | 118: $this->assertSame(array(), $this->object->split("\n"));
185 | 119: }
186 | 120:
187 | 121: 122: 123:
190 | 124: public function testSplitWord() {
191 | 125: $this->assertSame(array('Hello'), $this->object->split('Hello'));
192 | 126: $this->assertSame(array('Hello.'), $this->object->split('Hello.'));
193 | 127: $this->assertSame(array('Hello...'), $this->object->split('Hello...'));
194 | 128: $this->assertSame(array('Hello!'), $this->object->split('Hello!'));
195 | 129: $this->assertSame(array('Hello?'), $this->object->split('Hello?'));
196 | 130: $this->assertSame(array('Hello?!'), $this->object->split('Hello?!'));
197 | 131: }
198 | 132:
199 | 133: 134: 135:
202 | 136: public function testSplitMultipleWords() {
203 | 137: $this->assertSame(array('Hello world.', ' Are you there'), $this->object->split('Hello world. Are you there'));
204 | 138: $this->assertSame(array('Hello world.', ' Are you there?'), $this->object->split('Hello world. Are you there?'));
205 | 139: $this->assertSame(array('Hello world.', 'Are you there'), $this->object->split('Hello world. Are you there', Sentence::SPLIT_TRIM));
206 | 140: $this->assertSame(array('Hello world.', 'Are you there?'), $this->object->split('Hello world. Are you there?', Sentence::SPLIT_TRIM));
207 | 141: $this->assertSame(array('Hello world, Are you there?'), $this->object->split('Hello world, Are you there?'));
208 | 142: $this->assertSame(array('Hello world: Are you there?'), $this->object->split('Hello world: Are you there?'));
209 | 143: $this->assertSame(array('Hello world... Are you there?'), $this->object->split('Hello world... Are you there?'));
210 | 144: }
211 | 145:
212 | 146: 147: 148:
215 | 149: public function testSplitLinebreaks() {
216 | 150: $this->assertSame(array("Hello world...\r", "Are you there?"), $this->object->split("Hello world...\rAre you there?"));
217 | 151: $this->assertSame(array("Hello world...\n", " Are you there?"), $this->object->split("Hello world...\n Are you there?"));
218 | 152: $this->assertSame(array("Hello world...\n", "Are you there?"), $this->object->split("Hello world...\nAre you there?"));
219 | 153: $this->assertSame(array("Hello world...\r\n", "Are you there?"), $this->object->split("Hello world...\r\nAre you there?"));
220 | 154: $this->assertSame(array("Hello world...\r\n\r", "Are you there?"), $this->object->split("Hello world...\r\n\rAre you there?"));
221 | 155: $this->assertSame(array("Hello world...\n\r\n", "Are you there?"), $this->object->split("Hello world...\n\r\nAre you there?"));
222 | 156: $this->assertSame(array("Hello world...\n\n", "Are you there?"), $this->object->split("Hello world...\n\nAre you there?"));
223 | 157: $this->assertSame(array("Hello world...\r\r", "Are you there?"), $this->object->split("Hello world...\r\rAre you there?"));
224 | 158: }
225 | 159:
226 | 160: 161: 162:
229 | 163: public function testSplitAbreviations() {
230 | 164: $this->markTestIncomplete('This test has not been implemented yet.');
231 | 165: $this->assertSame(array('Hello mr. Smith.'), $this->object->split("Hello mr. Smith."));
232 | 166: $this->assertSame(array('Hello, OMG Kittens!'), $this->object->split("Hello, OMG Kittens!"));
233 | 167: $this->assertSame(array('Hello, abbrev. Kittens!'), $this->object->split("Hello, abbrev. Kittens!"));
234 | 168: $this->assertSame(array('Hello, O.M.G. Kittens!'), $this->object->split("Hello, O.M.G. Kittens!"));
235 | 169: }
236 | 170:
237 | 171: 172: 173:
240 | 174: public function testSplitOneWordSentences() {
241 | 175: $this->assertSame(array("You?", " Smith?"), $this->object->split("You? Smith?"));
242 | 176: $this->assertSame(array("You there?", " Smith?"), $this->object->split("You there? Smith?"));
243 | 177: $this->assertSame(array("You mr. Smith?"), $this->object->split("You mr. Smith?"));
244 | 178:
245 | 179: $this->assertSame(array("Are you there.", " Smith, sir?"), $this->object->split("Are you there. Smith, sir?"));
246 | 180: $this->assertSame(array("Are you there.", " Mr. Smith?"), $this->object->split("Are you there. Mr. Smith?"));
247 | 181: }
248 | 182: }
249 | 183:
250 |
251 |
254 |