MediaWiki REL1_31
SearchSuggestionSetTest.php
Go to the documentation of this file.
1<?php
2
22class SearchSuggestionSetTest extends \PHPUnit\Framework\TestCase {
27 public function testAppend() {
29 $this->assertEquals( 0, $set->getSize() );
30 $set->append( new SearchSuggestion( 3 ) );
31 $this->assertEquals( 3, $set->getWorstScore() );
32 $this->assertEquals( 3, $set->getBestScore() );
33
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() );
39
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() );
45
46 $scores = $set->map( function ( $s ) {
47 return $s->getScore();
48 } );
49 $sorted = $scores;
50 asort( $sorted );
51 $this->assertEquals( $sorted, $scores );
52 }
53
58 public function testInsertBest() {
60 $this->assertEquals( 0, $set->getSize() );
61 $set->prepend( new SearchSuggestion( 3 ) );
62 $this->assertEquals( 3, $set->getWorstScore() );
63 $this->assertEquals( 3, $set->getBestScore() );
64
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() );
70
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() );
76
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() );
82
83 $scores = $set->map( function ( $s ) {
84 return $s->getScore();
85 } );
86 $sorted = $scores;
87 asort( $sorted );
88 $this->assertEquals( $sorted, $scores );
89 }
90
91 public function testShrink() {
93 for ( $i = 0; $i < 100; $i++ ) {
94 $set->append( new SearchSuggestion( 0 ) );
95 }
96 $set->shrink( 10 );
97 $this->assertEquals( 10, $set->getSize() );
98
99 $set->shrink( 0 );
100 $this->assertEquals( 0, $set->getSize() );
101 }
102
103 // TODO: test for fromTitles
104}
Test for filter utilities.
testAppend()
Test that adding a new suggestion at the end will keep proper score ordering.
testInsertBest()
Test that adding a new best suggestion will keep proper score ordering.
Search suggestion.