Skip to content

Commit

Permalink
Remove CharTree::getBranchesAfterRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Stadly committed Apr 24, 2019
1 parent 5522ffa commit bf2c423
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 169 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

### Removed
- Possibility to get code map for root of character tree.
- `CharTree::getBranchesAfterRoot`. Use character treee cutter instead.

### Security
- Nothing
Expand Down
28 changes: 0 additions & 28 deletions src/CharTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,6 @@ public function getBranches(): array
return $this->branches;
}

/**
* @param string $root Root that comes before the brances.
* @return self Character tree containing the branches of this character tree that come after $root.
*/
public function getBranchesAfterRoot(string $root): self
{
if ($this->root === null || $root === '') {
return $this;
}

if ($this->root === $root) {
return self::fromString('', $this->branches);
}

if ($this->root !== mb_substr($root, 0, mb_strlen($this->root))) {
return self::fromNothing();
}

$rootTail = mb_substr($root, mb_strlen($this->root));
$rootHead = mb_substr($rootTail, 0, 1);

if (!isset($this->branches[$rootHead])) {
return self::fromNothing();
}

return $this->branches[$rootHead]->getBranchesAfterRoot($rootTail);
}

/**
* @param string $string String to check.
* @return bool Whether the character tree contains the string.
Expand Down
141 changes: 0 additions & 141 deletions tests/CharTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,147 +233,6 @@ public function testCanGetBranches(): void
], $charTree->getBranches(), '', 0, 10, true);
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterEmptyRoot(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]);

self::assertSame(CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]), $charTree->getBranchesAfterRoot(''));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterRootOfSingleCharacter(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]);

self::assertSame(CharTree::fromArray([
CharTree::fromString(''),
CharTree::fromString('b'),
CharTree::fromString('bc'),
CharTree::fromString('cd'),
]), $charTree->getBranchesAfterRoot('a'));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterRootOfMultipleCharacters(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]);

self::assertSame(CharTree::fromArray([
CharTree::fromString(''),
CharTree::fromString('c'),
]), $charTree->getBranchesAfterRoot('ab'));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterRootMatchingFullString(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foo'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]);

self::assertSame(CharTree::fromArray([
CharTree::fromString(''),
CharTree::fromString('bar'),
]), $charTree->getBranchesAfterRoot('foo'));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterRootOfSingleCharacterThatDoesNotExist(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
]);

self::assertSame(CharTree::fromArray([
]), $charTree->getBranchesAfterRoot('f'));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterRootOfMultipleCharactersThatDoesNotExist(): void
{
$charTree = CharTree::fromArray([
CharTree::fromString('a'),
CharTree::fromString('ab'),
CharTree::fromString('abc'),
CharTree::fromString('acd'),
CharTree::fromString('foobar'),
CharTree::fromString('k'),
]);

self::assertSame(CharTree::fromArray([
]), $charTree->getBranchesAfterRoot('fu'));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterEmptyRootWhenTreeIsEmpty(): void
{
$charTree = CharTree::fromNothing();

self::assertSame(CharTree::fromNothing(), $charTree->getBranchesAfterRoot(''));
}

/**
* @covers ::getBranchesAfterRoot
*/
public function testCanGetBranchesAfterEmptyRootWhenTreeIsEmptyString(): void
{
$charTree = CharTree::fromString('');

self::assertSame(CharTree::fromString(''), $charTree->getBranchesAfterRoot(''));
}

/**
* @covers ::contains
*/
Expand Down

0 comments on commit bf2c423

Please sign in to comment.