Skip to content

Commit c4a39f8

Browse files
authored
Merge pull request #710 from wmde/removeDuplicates
Drop unused HashArray::removeDuplicates
2 parents 7b50afa + 2630523 commit c4a39f8

4 files changed

Lines changed: 47 additions & 117 deletions

File tree

src/HashArray.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -311,29 +311,6 @@ public function equals( $target ) {
311311
&& $this->getHash() === $target->getHash();
312312
}
313313

314-
/**
315-
* Removes duplicates bases on hash value.
316-
*
317-
* @since 0.3
318-
*/
319-
public function removeDuplicates() {
320-
$knownHashes = [];
321-
322-
/**
323-
* @var Hashable $hashable
324-
*/
325-
foreach ( iterator_to_array( $this ) as $hashable ) {
326-
$hash = $hashable->getHash();
327-
328-
if ( in_array( $hash, $knownHashes ) ) {
329-
$this->removeByElementHash( $hash );
330-
}
331-
else {
332-
$knownHashes[] = $hash;
333-
}
334-
}
335-
}
336-
337314
/**
338315
* @see ArrayObject::append
339316
*

tests/unit/HashArray/HashArrayTest.php

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,61 +41,6 @@ public function instanceProvider() {
4141
return $instances;
4242
}
4343

44-
/**
45-
* @dataProvider instanceProvider
46-
* @param HashArray $array
47-
*/
48-
public function testHasElement( HashArray $array ) {
49-
$array->removeDuplicates();
50-
51-
/**
52-
* @var Hashable $hashable
53-
*/
54-
foreach ( iterator_to_array( $array ) as $hashable ) {
55-
$this->assertTrue( $array->hasElement( $hashable ) );
56-
$this->assertTrue( $array->hasElementHash( $hashable->getHash() ) );
57-
$array->removeElement( $hashable );
58-
$this->assertFalse( $array->hasElement( $hashable ) );
59-
$this->assertFalse( $array->hasElementHash( $hashable->getHash() ) );
60-
}
61-
62-
$this->assertTrue( true );
63-
}
64-
65-
/**
66-
* @dataProvider instanceProvider
67-
* @param HashArray $array
68-
*/
69-
public function testRemoveElement( HashArray $array ) {
70-
$array->removeDuplicates();
71-
72-
$elementCount = $array->count();
73-
74-
/**
75-
* @var Hashable $element
76-
*/
77-
foreach ( iterator_to_array( $array ) as $element ) {
78-
$this->assertTrue( $array->hasElement( $element ) );
79-
80-
if ( $elementCount % 2 === 0 ) {
81-
$array->removeElement( $element );
82-
}
83-
else {
84-
$array->removeByElementHash( $element->getHash() );
85-
}
86-
87-
$this->assertFalse( $array->hasElement( $element ) );
88-
$this->assertEquals( --$elementCount, $array->count() );
89-
}
90-
91-
$element = new PropertyNoValueSnak( 42 );
92-
93-
$array->removeElement( $element );
94-
$array->removeByElementHash( $element->getHash() );
95-
96-
$this->assertTrue( true );
97-
}
98-
9944
/**
10045
* @dataProvider instanceProvider
10146
* @param HashArray $array

tests/unit/HashArray/HashArrayWithDuplicatesTest.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,6 @@ public function testAddElement( HashArray $array ) {
5858
$this->assertTrue( $array->addElement( $element ), 'Adding an element should always work' );
5959
}
6060

61-
/**
62-
* @dataProvider instanceProvider
63-
* @param HashArray $array
64-
*/
65-
public function testRemoveDuplicates( HashArray $array ) {
66-
$count = count( $array );
67-
$duplicateCount = 0;
68-
$hashes = [];
69-
70-
/**
71-
* @var Hashable $hashable
72-
*/
73-
foreach ( $array as $hashable ) {
74-
if ( in_array( $hashable->getHash(), $hashes ) ) {
75-
$duplicateCount++;
76-
}
77-
else {
78-
$hashes[] = $hashable->getHash();
79-
}
80-
}
81-
82-
$array->removeDuplicates();
83-
84-
$this->assertEquals(
85-
$count - $duplicateCount,
86-
count( $array ),
87-
'Count should decrease by the number of duplicates after removing duplicates'
88-
);
89-
}
90-
9161
/**
9262
* @dataProvider instanceProvider
9363
* @param HashArray $array

tests/unit/HashArray/HashArrayWithoutDuplicatesTest.php

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Wikibase\DataModel\Tests\HashArray;
44

5+
use Hashable;
56
use Wikibase\DataModel\Fixtures\HashArrayElement;
67
use Wikibase\DataModel\HashArray;
8+
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
79

810
/**
911
* @covers Wikibase\DataModel\HashArray
@@ -80,15 +82,51 @@ public function testAddElement( HashArray $array ) {
8082
* @dataProvider instanceProvider
8183
* @param HashArray $array
8284
*/
83-
public function testRemoveDuplicates( HashArray $array ) {
84-
$count = count( $array );
85-
$array->removeDuplicates();
86-
87-
$this->assertCount(
88-
$count,
89-
$array,
90-
'Count should be the same after removeDuplicates since there can be none'
91-
);
85+
public function testHasElement( HashArray $array ) {
86+
/**
87+
* @var Hashable $hashable
88+
*/
89+
foreach ( iterator_to_array( $array ) as $hashable ) {
90+
$this->assertTrue( $array->hasElement( $hashable ) );
91+
$this->assertTrue( $array->hasElementHash( $hashable->getHash() ) );
92+
$array->removeElement( $hashable );
93+
$this->assertFalse( $array->hasElement( $hashable ) );
94+
$this->assertFalse( $array->hasElementHash( $hashable->getHash() ) );
95+
}
96+
97+
$this->assertTrue( true );
98+
}
99+
100+
/**
101+
* @dataProvider instanceProvider
102+
* @param HashArray $array
103+
*/
104+
public function testRemoveElement( HashArray $array ) {
105+
$elementCount = $array->count();
106+
107+
/**
108+
* @var Hashable $element
109+
*/
110+
foreach ( iterator_to_array( $array ) as $element ) {
111+
$this->assertTrue( $array->hasElement( $element ) );
112+
113+
if ( $elementCount % 2 === 0 ) {
114+
$array->removeElement( $element );
115+
}
116+
else {
117+
$array->removeByElementHash( $element->getHash() );
118+
}
119+
120+
$this->assertFalse( $array->hasElement( $element ) );
121+
$this->assertEquals( --$elementCount, $array->count() );
122+
}
123+
124+
$element = new PropertyNoValueSnak( 42 );
125+
126+
$array->removeElement( $element );
127+
$array->removeByElementHash( $element->getHash() );
128+
129+
$this->assertTrue( true );
92130
}
93131

94132
/**

0 commit comments

Comments
 (0)