Skip to content

Commit

Permalink
TPriorityMap exposing the getNextIntegerKey (#915)
Browse files Browse the repository at this point in the history
with unit tests
  • Loading branch information
belisoful authored Apr 27, 2023
1 parent a3198c1 commit 0d815ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions framework/Collections/TPriorityMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ private function getPriorityCombineStyle(): bool
return false;
}

/**
* @return int This is the key for the next appended item that doesn't have its
* own key.
*/
public function getNextIntegerKey(): int
{
return $this->_ic;
}

/**
* @return int the number of items in the map
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/Collections/TPriorityMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,24 @@ public function testArrayReadTPriorityMap()

public function testArrayWriteTPriorityMap()
{
$this->assertEquals(0, $this->map->getNextIntegerKey());
$this->map[] = $this->item1;
$this->assertEquals(1, $this->map->getNextIntegerKey());
$this->map->add(null, $this->item2, 15);
$this->assertEquals(2, $this->map->getNextIntegerKey());
$this->map[] = $this->item3;
$this->assertEquals(3, $this->map->getNextIntegerKey());
$this->map->add(null, $this->item4, 5);
$this->assertEquals(4, $this->map->getNextIntegerKey());
$this->assertEquals($this->item1, $this->map[0]);
$this->assertEquals($this->item2, $this->map[1]);
$this->assertEquals($this->item3, $this->map[2]);
$this->assertEquals($this->item4, $this->map[3]);
$this->assertNull($this->map[4]);

$this->map[11] = $this->item1;
$this->assertEquals($this->item1, $this->map[11]);
$this->assertEquals(12, $this->map->getNextIntegerKey());
}

// ** End TMap tests on TPriorityMap
Expand Down

0 comments on commit 0d815ff

Please sign in to comment.