Page MenuHomeDevCentral

D2508.id6326.diff
No OneTemporary

D2508.id6326.diff

diff --git a/src/Collections/BaseCollection.php b/src/Collections/BaseCollection.php
--- a/src/Collections/BaseCollection.php
+++ b/src/Collections/BaseCollection.php
@@ -23,4 +23,6 @@
public function count () : int;
+ public function isEmpty () : bool;
+
}
diff --git a/src/Collections/HashMap.php b/src/Collections/HashMap.php
--- a/src/Collections/HashMap.php
+++ b/src/Collections/HashMap.php
@@ -79,6 +79,10 @@
return count($this->map);
}
+ public function isEmpty () : bool {
+ return $this->count() === 0;
+ }
+
public function clear () : self {
$this->map = [];
diff --git a/src/Collections/Vector.php b/src/Collections/Vector.php
--- a/src/Collections/Vector.php
+++ b/src/Collections/Vector.php
@@ -100,6 +100,10 @@
return count($this->items);
}
+ public function isEmpty () : bool {
+ return $this->count() === 0;
+ }
+
public function clear () : self {
$this->items = [];
diff --git a/tests/Collections/HashMapTest.php b/tests/Collections/HashMapTest.php
--- a/tests/Collections/HashMapTest.php
+++ b/tests/Collections/HashMapTest.php
@@ -127,6 +127,12 @@
$this->assertSame(0, $this->map->count());
}
+ public function testIsEmpty () : void {
+ $this->map->clear();
+
+ $this->assertTrue($this->map->isEmpty());
+ }
+
public function testMerge () {
$iterable = [
"The Culture" => "Iain M. Banks", // existing key
diff --git a/tests/Collections/VectorTest.php b/tests/Collections/VectorTest.php
--- a/tests/Collections/VectorTest.php
+++ b/tests/Collections/VectorTest.php
@@ -76,6 +76,12 @@
$this->assertEquals(0, $this->vector->count());
}
+ public function testIsEmpty () : void {
+ $this->vector->clear();
+
+ $this->assertTrue($this->vector->isEmpty());
+ }
+
public function testAppend () : void {
$this->vector->append([6, 7, 8]);

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 11:02 (12 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2246403
Default Alt Text
D2508.id6326.diff (1 KB)

Event Timeline