4 * Test for filter utilities.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
22 class SearchSuggestionSetTest
extends \PHPUnit_Framework_TestCase
{
24 * Test that adding a new suggestion at the end
25 * will keep proper score ordering
27 public function testAppend() {
28 $set = SearchSuggestionSet
::emptySuggestionSet();
29 $this->assertEquals( 0, $set->getSize() );
30 $set->append( new SearchSuggestion( 3 ) );
31 $this->assertEquals( 3, $set->getWorstScore() );
32 $this->assertEquals( 3, $set->getBestScore() );
34 $suggestion = new SearchSuggestion( 4 );
35 $set->append( $suggestion );
36 $this->assertEquals( 2, $set->getWorstScore() );
37 $this->assertEquals( 3, $set->getBestScore() );
38 $this->assertEquals( 2, $suggestion->getScore() );
40 $suggestion = new SearchSuggestion( 2 );
41 $set->append( $suggestion );
42 $this->assertEquals( 1, $set->getWorstScore() );
43 $this->assertEquals( 3, $set->getBestScore() );
44 $this->assertEquals( 1, $suggestion->getScore() );
46 $scores = $set->map( function( $s ) {
47 return $s->getScore();
51 $this->assertEquals( $sorted, $scores );
55 * Test that adding a new best suggestion will keep proper score
58 public function testInsertBest() {
59 $set = SearchSuggestionSet
::emptySuggestionSet();
60 $this->assertEquals( 0, $set->getSize() );
61 $set->prepend( new SearchSuggestion( 3 ) );
62 $this->assertEquals( 3, $set->getWorstScore() );
63 $this->assertEquals( 3, $set->getBestScore() );
65 $suggestion = new SearchSuggestion( 4 );
66 $set->prepend( $suggestion );
67 $this->assertEquals( 3, $set->getWorstScore() );
68 $this->assertEquals( 4, $set->getBestScore() );
69 $this->assertEquals( 4, $suggestion->getScore() );
71 $suggestion = new SearchSuggestion( 0 );
72 $set->prepend( $suggestion );
73 $this->assertEquals( 3, $set->getWorstScore() );
74 $this->assertEquals( 5, $set->getBestScore() );
75 $this->assertEquals( 5, $suggestion->getScore() );
77 $suggestion = new SearchSuggestion( 2 );
78 $set->prepend( $suggestion );
79 $this->assertEquals( 3, $set->getWorstScore() );
80 $this->assertEquals( 6, $set->getBestScore() );
81 $this->assertEquals( 6, $suggestion->getScore() );
83 $scores = $set->map( function( $s ) {
84 return $s->getScore();
88 $this->assertEquals( $sorted, $scores );
91 public function testShrink() {
92 $set = SearchSuggestionSet
::emptySuggestionSet();
93 for ( $i = 0; $i < 100; $i++
) {
94 $set->append( new SearchSuggestion( 0 ) );
97 $this->assertEquals( 10, $set->getSize() );
100 $this->assertEquals( 0, $set->getSize() );
103 // TODO: test for fromTitles