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