5 require_once '../../lib/Phrase.php';
7 class PhraseTest extends \PHPUnit_Framework_TestCase
11 private function serializeSets($aSets)
14 foreach ($aSets as $aSet) {
15 $aParts[] = '(' . join('|', $aSet) . ')';
17 return join(',', $aParts);
21 public function testEmptyPhrase()
23 $oPhrase = new Phrase('', '');
27 $oPhrase->getWordSets()
32 public function testSingleWordPhrase()
34 $oPhrase = new Phrase('a', '');
38 $this->serializeSets($oPhrase->getWordSets())
43 public function testMultiWordPhrase()
45 $oPhrase = new Phrase('a b', '');
48 $this->serializeSets($oPhrase->getWordSets())
51 $oPhrase = new Phrase('a b c', '');
53 '(a b c),(a|b c),(a|b|c),(a b|c)',
54 $this->serializeSets($oPhrase->getWordSets())
57 $oPhrase = new Phrase('a b c d', '');
59 '(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)',
60 $this->serializeSets($oPhrase->getWordSets())
65 public function testInverseWordSets()
67 $oPhrase = new Phrase('a b c', '');
68 $oPhrase->invertWordSets();
71 '(a b c),(c|a b),(c|b|a),(b c|a)',
72 $this->serializeSets($oPhrase->getWordSets())
77 public function testMaxDepth()
79 $oPhrase = new Phrase(join(' ', array_fill(0, 4, 'a')), '');
80 $this->assertEquals(8, count($oPhrase->getWordSets()));
81 $oPhrase->invertWordSets();
82 $this->assertEquals(8, count($oPhrase->getWordSets()));
84 $oPhrase = new Phrase(join(' ', array_fill(0, 18, 'a')), '');
85 $this->assertEquals(41226, count($oPhrase->getWordSets()));
86 $oPhrase->invertWordSets();
87 $this->assertEquals(41226, count($oPhrase->getWordSets()));