fix tests

This commit is contained in:
Dennis Eichhorn 2023-10-24 18:39:14 +00:00
parent 999ec823b3
commit ec49bf2dc1
2 changed files with 15 additions and 15 deletions

View File

@ -247,7 +247,7 @@ class BinarySearchTree
}
$temp = null;
if ($node->right !== null) {
if ($node->left === null) {
$temp = $node->right->root;
if ($temp === null) {
return;
@ -272,7 +272,7 @@ class BinarySearchTree
return;
}
if ($node->left !== null) {
if ($node->right === null) {
$temp = $node->left->root;
if ($temp === null) {
return;
@ -306,11 +306,11 @@ class BinarySearchTree
/**
* To array
*
* @return array
* @return null|array
*
* @since 1.0.0
*/
public function toArray() : array
public function toArray() : ?array
{
return $this->root?->toArray() ?? null;
}

View File

@ -124,14 +124,15 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase
'key' => 'O',
0 => null,
1 => [
'key' => 'U',
0 => [
'key' => 'R',
0 => null,
1 => [
'key' => 'U',
0 => [
'key' => 'T',
0 => null,
1 => null
]
],
1 => [
'key' => 'Z',
@ -142,7 +143,6 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase
],
],
],
],
$bst->toArray()
);
}