MediaWiki REL1_33
SearchSuggestionSetTest.php
Go to the documentation of this file.
1<?php
2
22class SearchSuggestionSetTest extends \PHPUnit\Framework\TestCase {
28 public function testAppend() {
30 $this->assertEquals( 0, $set->getSize() );
31 $set->append( new SearchSuggestion( 3 ) );
32 $this->assertEquals( 3, $set->getWorstScore() );
33 $this->assertEquals( 3, $set->getBestScore() );
34
35 $suggestion = new SearchSuggestion( 4 );
36 $set->append( $suggestion );
37 $this->assertEquals( 2, $set->getWorstScore() );
38 $this->assertEquals( 3, $set->getBestScore() );
39 $this->assertEquals( 2, $suggestion->getScore() );
40
41 $suggestion = new SearchSuggestion( 2 );
42 $set->append( $suggestion );
43 $this->assertEquals( 1, $set->getWorstScore() );
44 $this->assertEquals( 3, $set->getBestScore() );
45 $this->assertEquals( 1, $suggestion->getScore() );
46
47 $scores = $set->map( function ( $s ) {
48 return $s->getScore();
49 } );
50 $sorted = $scores;
51 asort( $sorted );
52 $this->assertEquals( $sorted, $scores );
53 }
54
62 public function testInsertBest() {
64 $this->assertEquals( 0, $set->getSize() );
65 $set->prepend( new SearchSuggestion( 3 ) );
66 $this->assertEquals( 3, $set->getWorstScore() );
67 $this->assertEquals( 3, $set->getBestScore() );
68
69 $suggestion = new SearchSuggestion( 4 );
70 $set->prepend( $suggestion );
71 $this->assertEquals( 3, $set->getWorstScore() );
72 $this->assertEquals( 4, $set->getBestScore() );
73 $this->assertEquals( 4, $suggestion->getScore() );
74
75 $suggestion = new SearchSuggestion( 0 );
76 $set->prepend( $suggestion );
77 $this->assertEquals( 3, $set->getWorstScore() );
78 $this->assertEquals( 5, $set->getBestScore() );
79 $this->assertEquals( 5, $suggestion->getScore() );
80
81 $suggestion = new SearchSuggestion( 2 );
82 $set->prepend( $suggestion );
83 $this->assertEquals( 3, $set->getWorstScore() );
84 $this->assertEquals( 6, $set->getBestScore() );
85 $this->assertEquals( 6, $suggestion->getScore() );
86
87 $scores = $set->map( function ( $s ) {
88 return $s->getScore();
89 } );
90 $sorted = $scores;
91 asort( $sorted );
92 $this->assertEquals( $sorted, $scores );
93 }
94
98 public function testShrink() {
100 for ( $i = 0; $i < 100; $i++ ) {
101 $set->append( new SearchSuggestion( 0 ) );
102 }
103 $set->shrink( 10 );
104 $this->assertEquals( 10, $set->getSize() );
105
106 $set->shrink( 0 );
107 $this->assertEquals( 0, $set->getSize() );
108 }
109
110 // TODO: test for fromTitles
111}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
Test for filter utilities.
testAppend()
Test that adding a new suggestion at the end will keep proper score ordering SearchSuggestionSet::app...
testInsertBest()
Test that adding a new best suggestion will keep proper score ordering SearchSuggestionSet::getWorstS...
testShrink()
SearchSuggestionSet::shrink.
Search suggestion.