5 require_once(CONST_LibDir.'/SimpleWordList.php');
9 public function containsAny($sTerm)
15 // phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
16 class TokensPartialSet
18 public function __construct($aTokens)
20 $this->aTokens = array_flip($aTokens);
23 public function containsAny($sTerm)
25 return isset($this->aTokens[$sTerm]);
29 // phpcs:ignore PSR1.Classes.ClassDeclaration.MultipleClasses
30 class SimpleWordListTest extends \PHPUnit\Framework\TestCase
34 private function serializeSets($aSets)
37 foreach ($aSets as $aSet) {
38 $aParts[] = '(' . join('|', $aSet) . ')';
40 return join(',', $aParts);
44 public function testEmptyPhrase()
46 $oList = new SimpleWordList('');
47 $this->assertNull($oList->getWordSets(new TokensFullSet()));
51 public function testSingleWordPhrase()
53 $oList = new SimpleWordList('a');
57 $this->serializeSets($oList->getWordSets(new TokensFullSet()))
62 public function testMultiWordPhrase()
64 $oList = new SimpleWordList('a b');
67 $this->serializeSets($oList->getWordSets(new TokensFullSet()))
70 $oList = new SimpleWordList('a b c');
72 '(a b c),(a|b c),(a b|c),(a|b|c)',
73 $this->serializeSets($oList->getWordSets(new TokensFullSet()))
76 $oList = new SimpleWordList('a b c d');
78 '(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)',
79 $this->serializeSets($oList->getWordSets(new TokensFullSet()))
84 public function testMaxWordSets()
86 $aWords = array_fill(0, 4, 'a');
87 $oList = new SimpleWordList(join(' ', $aWords));
88 $this->assertEquals(8, count($oList->getWordSets(new TokensFullSet())));
90 $aWords = array_fill(0, 18, 'a');
91 $oList = new SimpleWordList(join(' ', $aWords));
92 $this->assertEquals(100, count($oList->getWordSets(new TokensFullSet())));
96 public function testPartialTokensShortTerm()
98 $oList = new SimpleWordList('a b c d');
100 '(a|b c d),(a|b c|d)',
101 $this->serializeSets($oList->getWordSets(new TokensPartialSet(array('a', 'b', 'd', 'b c', 'b c d'))))
106 public function testPartialTokensLongTerm()
108 $aWords = array_fill(0, 18, 'a');
109 $oList = new SimpleWordList(join(' ', $aWords));
110 $this->assertEquals(80, count($oList->getWordSets(new TokensPartialSet(array('a', 'a a a a a')))));