]> git.openstreetmap.org Git - nominatim.git/blobdiff - test/php/Nominatim/SimpleWordListTest.php
enable CI tests for Ubuntu 24
[nominatim.git] / test / php / Nominatim / SimpleWordListTest.php
index fe543b3faaaaabc09d757e3de698f9f8445523a5..69cb51809178352d99bbe4df94599d281934f8ed 100644 (file)
@@ -77,7 +77,7 @@ class SimpleWordListTest extends \PHPUnit\Framework\TestCase
 
         $oList = new SimpleWordList('a b c');
         $this->assertEquals(
 
         $oList = new SimpleWordList('a b c');
         $this->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()))
         );
 
             $this->serializeSets($oList->getWordSets(new TokensFullSet()))
         );
 
@@ -88,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()
     {
 
     public function testMaxWordSets()
     {