]> git.openstreetmap.org Git - nominatim.git/commitdiff
add simple test for result splitting with multiple ranks
authorSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Feb 2021 16:59:12 +0000 (17:59 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 16 Feb 2021 16:59:12 +0000 (17:59 +0100)
test/php/Nominatim/ResultTest.php [new file with mode: 0644]

diff --git a/test/php/Nominatim/ResultTest.php b/test/php/Nominatim/ResultTest.php
new file mode 100644 (file)
index 0000000..c18aa76
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace Nominatim;
+
+require_once(CONST_LibDir.'/Result.php');
+
+function mkRankedResult($iId, $iResultRank)
+{
+    $oResult = new Result($iId);
+    $oResult->iResultRank = $iResultRank;
+
+    return $oResult;
+}
+
+
+class ResultTest extends \PHPUnit\Framework\TestCase
+{
+    public function testSplitResults()
+    {
+        $aSplitResults = Result::splitResults(array(
+            mkRankedResult(1, 2),
+            mkRankedResult(2, 0),
+            mkRankedResult(3, 0),
+            mkRankedResult(4, 2),
+            mkRankedResult(5, 1)
+        ));
+
+
+        $aHead = array_keys($aSplitResults['head']);
+        $aTail = array_keys($aSplitResults['tail']);
+
+        $this->assertEquals($aHead, array(2, 3));
+        $this->assertEquals($aTail, array(1, 4, 5));
+    }
+}