Skip to content

Commit

Permalink
Bug fix for SortedMap. When setting a value for a key that already ex…
Browse files Browse the repository at this point in the history
…isted, the value was not updated.
  • Loading branch information
morrisonlevi committed Feb 6, 2013
1 parent 0d8aea9 commit bec537e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Ardent/BinarySearchTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ protected function addRecursive($element, BinaryTree $node = NULL) {
$node->setLeft($this->addRecursive($element, $node->getLeft()));
} elseif ($comparisonResult > 0) {
$node->setRight($this->addRecursive($element, $node->getRight()));
} else {
$node->setValue($element);
}

return $node;
Expand Down
13 changes: 13 additions & 0 deletions test/Ardent/SortedMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ function testOffsetSet() {
$this->assertCount(3, $map);
}

/**
* @depends testOffsetSet
*/
function testOffsetSetAlreadySet() {
$map = new SortedMap();
$map[1] = 1;
$map[1] = 0;

$expected = 0;
$actual = $map[1];
$this->assertEquals($expected, $actual);
}

/**
* @depends testOffsetSet
* @covers \Ardent\SortedMap::offsetUnset
Expand Down

0 comments on commit bec537e

Please sign in to comment.