5 require_once '../../lib/Phrase.php';
7 class PhraseTest extends \PHPUnit_Framework_TestCase
9 private function serializeSets($aSets)
12 foreach ($aSets as $aSet) {
13 $aParts[] = '(' . join('|', $aSet) . ')';
15 return join(',', $aParts);
19 public function testEmptyPhrase()
21 $oPhrase = new Phrase('', '');
25 $oPhrase->getWordSets()
30 public function testSingleWordPhrase()
32 $oPhrase = new Phrase('a', '');
36 $this->serializeSets($oPhrase->getWordSets())
41 public function testMultiWordPhrase()
43 $oPhrase = new Phrase('a b', '');
46 $this->serializeSets($oPhrase->getWordSets())
49 $oPhrase = new Phrase('a b c', '');
51 '(a b c),(a|b c),(a|b|c),(a b|c)',
52 $this->serializeSets($oPhrase->getWordSets())
55 $oPhrase = new Phrase('a b c d', '');
57 '(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)',
58 $this->serializeSets($oPhrase->getWordSets())
63 public function testInverseWordSets()
65 $oPhrase = new Phrase('a b c', '');
66 $oPhrase->invertWordSets();
69 '(a b c),(c|a b),(c|b|a),(b c|a)',
70 $this->serializeSets($oPhrase->getWordSets())
75 public function testMaxDepth()
77 $oPhrase = new Phrase(join(' ', array_fill(0, 4, 'a')), '');
78 $this->assertEquals(8, count($oPhrase->getWordSets()));
79 $oPhrase->invertWordSets();
80 $this->assertEquals(8, count($oPhrase->getWordSets()));
82 $oPhrase = new Phrase(join(' ', array_fill(0, 18, 'a')), '');
83 $this->assertEquals(41226, count($oPhrase->getWordSets()));
84 $oPhrase->invertWordSets();
85 $this->assertEquals(41226, count($oPhrase->getWordSets()));