Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/205860
Change subject: Add more tests to HashDedupeBagTest
......................................................................
Add more tests to HashDedupeBagTest
Change-Id: I6ed25fa0ac8e5ba82a895e19cb33f9e9f6b5c990
---
M repo/includes/rdf/HashDedupeBag.php
M repo/includes/rdf/NullDedupeBag.php
M repo/tests/phpunit/includes/rdf/HashDedupeBagTest.php
3 files changed, 26 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/60/205860/1
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/includes/rdf/NullDedupeBag.php
b/repo/includes/rdf/NullDedupeBag.php
index 1a3cc4b..571aaec 100644
--- a/repo/includes/rdf/NullDedupeBag.php
+++ b/repo/includes/rdf/NullDedupeBag.php
@@ -15,11 +15,11 @@
/**
* @see DedupeBag::alreadySeen
*
- * Always returns false, indicating that the has has not be seen
before, and the associated
+ * Always returns false, indicating that the hash has not be seen
before, and the associated
* data needs to be processed again. This would generate a false
negative whenever the
* method is called twice with the same parameters. This is admissible
by the contract
* of the method, which explicitly allows false negatives. The
consequence may be that
- * the called redundantly processes data that had been processed before.
+ * the caller redundantly processes data that had been processed before.
*
* @param string $hash
* @param string $namespace
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: newchange
Gerrit-Change-Id: I6ed25fa0ac8e5ba82a895e19cb33f9e9f6b5c990
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits