X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f3c4196c758a7720aefc26a7043bf1c6553028e2..f3c557bf684a0079e4bc54b622cc5d766f3a6b56:/test/php/Nominatim/SimpleWordListTest.php diff --git a/test/php/Nominatim/SimpleWordListTest.php b/test/php/Nominatim/SimpleWordListTest.php index 5c993668..69cb5180 100644 --- a/test/php/Nominatim/SimpleWordListTest.php +++ b/test/php/Nominatim/SimpleWordListTest.php @@ -1,4 +1,12 @@ assertEquals( - '(a b c),(a|b c),(a b|c),(a|b|c)', + '(a b c),(a b|c),(a|b c),(a|b|c)', $this->serializeSets($oList->getWordSets(new TokensFullSet())) ); @@ -80,6 +88,22 @@ class SimpleWordListTest extends \PHPUnit\Framework\TestCase ); } + public function testCmpByArraylen() + { + // Array elements are phrases, we want to sort so longest phrases are first + $aList1 = array('hackney', 'bridge', 'london', 'england'); + $aList2 = array('hackney', 'london', 'bridge'); + $aList3 = array('bridge', 'hackney', 'london', 'england'); + + $this->assertEquals(0, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList1)); + + // list2 "wins". Less array elements + $this->assertEquals(1, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList2)); + $this->assertEquals(-1, \Nominatim\SimpleWordList::cmpByArraylen($aList2, $aList3)); + + // list1 "wins". Same number of array elements but longer first element + $this->assertEquals(-1, \Nominatim\SimpleWordList::cmpByArraylen($aList1, $aList3)); + } public function testMaxWordSets() {