Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/49918


Change subject: Added tests for equality and getHash methods for collections of 
descriptions
......................................................................

Added tests for equality and getHash methods for collections of descriptions

Also fixed a cp error in the equals method of the DescriptionCollection class

Change-Id: Ie956df1de8c88c3341fafa9c7d65c039e80cfddd
---
M Ask.mw.php
M includes/Ask/Language/Description/DescriptionCollection.php
M tests/phpunit/Language/Description/ConjunctionTest.php
A tests/phpunit/Language/Description/DescriptionCollectionTest.php
M tests/phpunit/Language/Description/DisjunctionTest.php
5 files changed, 142 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Ask 
refs/changes/18/49918/1

diff --git a/Ask.mw.php b/Ask.mw.php
index 8712c5b..1179d2b 100644
--- a/Ask.mw.php
+++ b/Ask.mw.php
@@ -47,6 +47,9 @@
        $wgAutoloadClasses['Ask\Tests\AskTestCase']
                = __DIR__ . '/tests/phpunit/AskTestCase.php';
 
+       
$wgAutoloadClasses['Ask\Tests\Language\Description\DescriptionCollectionTest']
+               = __DIR__ . 
'/tests/phpunit/Language/Description/DescriptionCollectionTest.php';
+
        $wgAutoloadClasses['Ask\Tests\Language\Description\DescriptionTest']
                = __DIR__ . 
'/tests/phpunit/Language/Description/DescriptionTest.php';
 
diff --git a/includes/Ask/Language/Description/DescriptionCollection.php 
b/includes/Ask/Language/Description/DescriptionCollection.php
index 3b07e81..3632026 100644
--- a/includes/Ask/Language/Description/DescriptionCollection.php
+++ b/includes/Ask/Language/Description/DescriptionCollection.php
@@ -139,8 +139,8 @@
                        return false;
                }
 
-               $this->sortCollection( $this->descriptions );
-               $this->sortCollection( $this->descriptions );
+               $this->sortCollection( $descriptions );
+               $this->sortCollection( $moreDescriptions );
                reset( $moreDescriptions );
 
                foreach ( $descriptions as $description ) {
diff --git a/tests/phpunit/Language/Description/ConjunctionTest.php 
b/tests/phpunit/Language/Description/ConjunctionTest.php
index 9fb4199..0b245e9 100644
--- a/tests/phpunit/Language/Description/ConjunctionTest.php
+++ b/tests/phpunit/Language/Description/ConjunctionTest.php
@@ -1,8 +1,11 @@
 <?php
 
 namespace Ask\Tests\Language\Description;
+
 use Ask\Language\Description\Conjunction;
 use Ask\Language\Description\Disjunction;
+use Ask\Language\Description\Description;
+use Ask\Language\Description\DescriptionCollection;
 
 /**
  * Unit tests for the Ask\Language\Description\Intersection class.
@@ -33,7 +36,7 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
-class ConjunctionTest extends DescriptionTest {
+class ConjunctionTest extends DescriptionCollectionTest {
 
        /**
         * {@inheritdoc}
@@ -46,6 +49,10 @@
                $instances[] = new Conjunction( array( new Disjunction( array() 
), new Disjunction( array() ) ) );
                $instances[] = new Conjunction( array( new 
\Ask\Language\Description\AnyValue() ) );
                $instances[] = new Conjunction( array( new 
\Ask\Language\Description\ValueDescription( new \DataValues\StringValue( 'ohi' 
) ) ) );
+
+               foreach ( $this->descriptionsProvider() as $argList ) {
+                       $instances[] = new Conjunction( $argList[0] );
+               }
 
                return $instances;
        }
@@ -71,4 +78,15 @@
                $this->assertEquals( $descriptions, 
$newInstance->getDescriptions(), 'Descriptions are returned as it was passed to 
the constructor' );
        }
 
+       /**
+        * @see DescriptionCollectionTest::newFromDescriptions
+        *
+        * @param Description[] $descriptions
+        *
+        * @return DescriptionCollection
+        */
+       protected function newFromDescriptions( array $descriptions ) {
+               return new Conjunction( $descriptions );
+       }
+
 }
\ No newline at end of file
diff --git a/tests/phpunit/Language/Description/DescriptionCollectionTest.php 
b/tests/phpunit/Language/Description/DescriptionCollectionTest.php
new file mode 100644
index 0000000..01c6af3
--- /dev/null
+++ b/tests/phpunit/Language/Description/DescriptionCollectionTest.php
@@ -0,0 +1,99 @@
+<?php
+
+namespace Ask\Tests\Language\Description;
+
+use Ask\Language\Description\Description;
+use Ask\Language\Description\DescriptionCollection;
+
+/**
+ * Base class for unit tests for the 
Ask\Language\Description\DescriptionCollection deriving classes.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup AskTests
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ */
+abstract class DescriptionCollectionTest extends DescriptionTest {
+
+       public function descriptionsProvider() {
+               $descriptionLists = array();
+
+               $descriptionLists[] = array();
+
+               $descriptionLists[] = array(
+                       new \Ask\Language\Description\AnyValue(),
+                       new \Ask\Language\Description\ValueDescription( new 
\DataValues\StringValue( 'nyan nyan' ) )
+               );
+
+               $descriptionList = array();
+               $numbers = range( 0, 3 );
+               shuffle( $numbers );
+
+               foreach ( $numbers as $number ) {
+                       $descriptionList[] = new 
\Ask\Language\Description\ValueDescription( new \DataValues\NumberValue( 
$number ) );
+               }
+
+               $descriptionLists[] = $descriptionList;
+
+               return $this->arrayWrap( $descriptionLists );
+       }
+
+       /**
+        * @param Description[] $descriptions
+        *
+        * @return DescriptionCollection
+        */
+       protected abstract function newFromDescriptions( array $descriptions );
+
+       /**
+        * @dataProvider descriptionsProvider
+        *
+        * @param Description[] $descriptions
+        */
+       public function testEqualsOrderInsensitivity( array $descriptions ) {
+               $sameDescriptions = $descriptions;
+               shuffle( $sameDescriptions );
+
+               $description = $this->newFromDescriptions( $descriptions );
+               $sameDescription = $this->newFromDescriptions( 
$sameDescriptions );
+
+               $message = 'Two collection descriptions with same sub 
descriptions should be equal';
+
+               $this->assertTrue( $description->equals( $sameDescription ), 
$message );
+               $this->assertTrue( $sameDescription->equals( $description ), 
$message );
+       }
+
+       /**
+        * @dataProvider descriptionsProvider
+        *
+        * @param Description[] $descriptions
+        */
+       public function testGetHashOrderInsensitivity( array $descriptions ) {
+               $sameDescriptions = $descriptions;
+               shuffle( $sameDescriptions );
+
+               $description = $this->newFromDescriptions( $descriptions );
+               $sameDescription = $this->newFromDescriptions( 
$sameDescriptions );
+
+               $this->assertEquals( $description->getHash(), 
$sameDescription->getHash() );
+       }
+
+}
diff --git a/tests/phpunit/Language/Description/DisjunctionTest.php 
b/tests/phpunit/Language/Description/DisjunctionTest.php
index 5bbeb6b..06894a3 100644
--- a/tests/phpunit/Language/Description/DisjunctionTest.php
+++ b/tests/phpunit/Language/Description/DisjunctionTest.php
@@ -1,7 +1,10 @@
 <?php
 
 namespace Ask\Tests\Language\Description;
+
 use Ask\Language\Description\Disjunction;
+use Ask\Language\Description\Description;
+use Ask\Language\Description\DescriptionCollection;
 
 /**
  * Unit tests for the Ask\Language\Description\Union class.
@@ -32,7 +35,7 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
  */
-class DisjunctionTest extends DescriptionTest {
+class DisjunctionTest extends DescriptionCollectionTest {
 
        /**
         * {@inheritdoc}
@@ -45,6 +48,10 @@
                $instances[] = new Disjunction( array( new Disjunction( array() 
), new Disjunction( array() ) ) );
                $instances[] = new Disjunction( array( new 
\Ask\Language\Description\AnyValue() ) );
                $instances[] = new Disjunction( array( new 
\Ask\Language\Description\ValueDescription( new \DataValues\StringValue( 'ohi' 
) ) ) );
+
+               foreach ( $this->descriptionsProvider() as $argList ) {
+                       $instances[] = new Disjunction( $argList[0] );
+               }
 
                return $instances;
        }
@@ -70,4 +77,15 @@
                $this->assertEquals( $descriptions, 
$newInstance->getDescriptions(), 'Descriptions are returned as it was passed to 
the constructor' );
        }
 
+       /**
+        * @see DescriptionCollectionTest::newFromDescriptions
+        *
+        * @param Description[] $descriptions
+        *
+        * @return DescriptionCollection
+        */
+       protected function newFromDescriptions( array $descriptions ) {
+               return new Disjunction( $descriptions );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/49918
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie956df1de8c88c3341fafa9c7d65c039e80cfddd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to