From 1e4c22a03708968ec011edaf72a55a931a4204e0 Mon Sep 17 00:00:00 2001 From: Marc Tobias Metten Date: Sat, 22 Aug 2015 23:56:14 +0200 Subject: [PATCH 1/3] more tests for lib/lib.php --- tests-php/Nominatim/NominatimTest.php | 74 ++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/tests-php/Nominatim/NominatimTest.php b/tests-php/Nominatim/NominatimTest.php index 68519e48..a36c029e 100644 --- a/tests-php/Nominatim/NominatimTest.php +++ b/tests-php/Nominatim/NominatimTest.php @@ -1,7 +1,7 @@ assertEquals( + array(array('')), + getWordSets(array(),0) + ); + + $this->assertEquals( + '(a)', + serialize_sets( getWordSets(array("a"),0) ) + ); + + $this->assertEquals( + '(a b),(a|b)', + serialize_sets( getWordSets(array('a','b'),0) ) + ); + + $this->assertEquals( + '(a b c),(a|b c),(a|b|c),(a b|c)', + serialize_sets( getWordSets(array('a','b','c'),0) ) + ); + + $this->assertEquals( + '(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)', + serialize_sets( getWordSets(array('a','b','c','d'),0) ) + ); + + + // Inverse + $this->assertEquals( + '(a b c),(c|a b),(c|b|a),(b c|a)', + serialize_sets( getInverseWordSets(array('a','b','c'),0) ) + ); + + + // make sure we don't create too many sets + // 4 words => 8 sets + // 10 words => 511 sets + // 15 words => 12911 sets + // 20 words => 169766 sets + // 28 words => 397594 sets + $this->assertEquals( + 8, + count( getWordSets(array_fill( 0, 4, 'a'),0) ) + ); + + + $this->assertEquals( + 8, + count( getWordSets(array_fill( 0, 28, 'a'),0) ) + ); + + + + } + + } From 10a965c3ab6d1e2da2bf57be093084349cc401e7 Mon Sep 17 00:00:00 2001 From: Marc Tobias Metten Date: Sat, 22 Aug 2015 23:56:14 +0200 Subject: [PATCH 2/3] more tests for lib/lib.php --- tests-php/Nominatim/NominatimTest.php | 72 +++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests-php/Nominatim/NominatimTest.php b/tests-php/Nominatim/NominatimTest.php index 7ab68934..a36c029e 100644 --- a/tests-php/Nominatim/NominatimTest.php +++ b/tests-php/Nominatim/NominatimTest.php @@ -74,4 +74,76 @@ class NominatimTest extends \PHPUnit_Framework_TestCase } + + + public function test_getWordSets() + { + + // given an array of arrays like + // array( array('a','b'), array('c','d') ) + // returns a summary as string: '(a|b),(c|d)' + function serialize_sets($aSets) + { + $aParts = array(); + foreach($aSets as $aSet){ + $aParts[] = '(' . join('|', $aSet) . ')'; + } + return join(',', $aParts); + } + + $this->assertEquals( + array(array('')), + getWordSets(array(),0) + ); + + $this->assertEquals( + '(a)', + serialize_sets( getWordSets(array("a"),0) ) + ); + + $this->assertEquals( + '(a b),(a|b)', + serialize_sets( getWordSets(array('a','b'),0) ) + ); + + $this->assertEquals( + '(a b c),(a|b c),(a|b|c),(a b|c)', + serialize_sets( getWordSets(array('a','b','c'),0) ) + ); + + $this->assertEquals( + '(a b c d),(a|b c d),(a|b|c d),(a|b|c|d),(a|b c|d),(a b|c d),(a b|c|d),(a b c|d)', + serialize_sets( getWordSets(array('a','b','c','d'),0) ) + ); + + + // Inverse + $this->assertEquals( + '(a b c),(c|a b),(c|b|a),(b c|a)', + serialize_sets( getInverseWordSets(array('a','b','c'),0) ) + ); + + + // make sure we don't create too many sets + // 4 words => 8 sets + // 10 words => 511 sets + // 15 words => 12911 sets + // 20 words => 169766 sets + // 28 words => 397594 sets + $this->assertEquals( + 8, + count( getWordSets(array_fill( 0, 4, 'a'),0) ) + ); + + + $this->assertEquals( + 8, + count( getWordSets(array_fill( 0, 28, 'a'),0) ) + ); + + + + } + + } From 111444cd99d67a53d9d1d2658398a31527615e37 Mon Sep 17 00:00:00 2001 From: Marc Tobias Metten Date: Thu, 15 Oct 2015 02:28:16 +0200 Subject: [PATCH 3/3] more tests for libphp - incorporate lonvias feedback --- tests-php/Nominatim/NominatimTest.php | 8 +++++--- tests-php/README.txt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests-php/Nominatim/NominatimTest.php b/tests-php/Nominatim/NominatimTest.php index a36c029e..4c5638b1 100644 --- a/tests-php/Nominatim/NominatimTest.php +++ b/tests-php/Nominatim/NominatimTest.php @@ -128,8 +128,10 @@ class NominatimTest extends \PHPUnit_Framework_TestCase // 4 words => 8 sets // 10 words => 511 sets // 15 words => 12911 sets + // 18 words => 65536 sets // 20 words => 169766 sets - // 28 words => 397594 sets + // 22 words => 401930 sets + // 28 words => 3505699 sets (needs more than 4GB via 'phpunit -d memory_limit=' to run) $this->assertEquals( 8, count( getWordSets(array_fill( 0, 4, 'a'),0) ) @@ -137,8 +139,8 @@ class NominatimTest extends \PHPUnit_Framework_TestCase $this->assertEquals( - 8, - count( getWordSets(array_fill( 0, 28, 'a'),0) ) + 65536, + count( getWordSets(array_fill( 0, 18, 'a'),0) ) ); diff --git a/tests-php/README.txt b/tests-php/README.txt index 8aee5d8e..d551c1da 100644 --- a/tests-php/README.txt +++ b/tests-php/README.txt @@ -7,7 +7,7 @@ installed. To execute the test suite run $ cd tests-php -$ phpunit +$ phpunit ./ It will read phpunit.xml which points to the library, test path, bootstrap strip and set other parameters.