jenkins-bot has submitted this change and it was merged.
Change subject: Add more tests to HashDedupeBagTest
......................................................................
Add more tests to HashDedupeBagTest
Change-Id: I6ed25fa0ac8e5ba82a895e19cb33f9e9f6b5c990
---
M repo/includes/rdf/HashDedupeBag.php
M repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
2 files changed, 24 insertions(+), 5 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/rdf/HashDedupeBag.php
b/repo/includes/rdf/HashDedupeBag.php
index 3b43f3e..1e6cce8 100644
--- a/repo/includes/rdf/HashDedupeBag.php
+++ b/repo/includes/rdf/HashDedupeBag.php
@@ -82,12 +82,13 @@
*/
public function alreadySeen( $hash, $namespace = '' ) {
$key = $namespace . substr( $hash, 0, $this->cutoff );
- if ( !isset( $this->bag[$key] ) || $this->bag[$key] !== $hash )
{
- $this->bag[$key] = $hash;
- return false;
+
+ if ( array_key_exists( $key, $this->bag ) && $this->bag[$key]
=== $hash ) {
+ return true;
}
- return true;
+ $this->bag[$key] = $hash;
+ return false;
}
}
diff --git a/repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
b/repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
index 8c83d6d..f18f81b 100644
--- a/repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
+++ b/repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
@@ -2,6 +2,7 @@
namespace Wikibase\Test\Rdf;
+use PHPUnit_Framework_TestCase;
use Wikibase\Rdf\HashDedupeBag;
/**
@@ -14,7 +15,7 @@
* @licence GNU GPL v2+
* @author Daniel Kinzler
*/
-class HashDedupeBagTest extends \PHPUnit_Framework_TestCase {
+class HashDedupeBagTest extends PHPUnit_Framework_TestCase {
public function testAlreadySeen() {
$bag = new HashDedupeBag( 2 );
@@ -25,5 +26,22 @@
$this->assertTrue( $bag->alreadySeen( 'XAB' ) );
}
+ public function testAlreadySeenWithNamespace() {
+ $bag = new HashDedupeBag( 2 );
+
+ $this->assertFalse( $bag->alreadySeen( 'XYZ', 'A' ) );
+ $this->assertFalse( $bag->alreadySeen( 'XYZ', 'B' ) );
+ $this->assertTrue( $bag->alreadySeen( 'XYZ', 'A' ) );
+ $this->assertTrue( $bag->alreadySeen( 'XYZ', 'B' ) );
+ }
+
+ public function
testGivenConflictingHashNamespaceCombinations_alreadySeenReturnsFalse() {
+ $bag = new HashDedupeBag( 2 );
+
+ $this->assertFalse( $bag->alreadySeen( 'YZ', 'X' ) );
+ $this->assertFalse( $bag->alreadySeen( 'Z', 'XY' ) );
+ $this->assertFalse( $bag->alreadySeen( 'YZ', 'X' ) );
+ $this->assertFalse( $bag->alreadySeen( 'Z', 'XY' ) );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/205860
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6ed25fa0ac8e5ba82a895e19cb33f9e9f6b5c990
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits