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

View File

@ -124,20 +124,20 @@ final class BinarySearchTreeTest extends \PHPUnit\Framework\TestCase
'key' => 'O', 'key' => 'O',
0 => null, 0 => null,
1 => [ 1 => [
'key' => 'R', 'key' => 'U',
0 => null, 0 => [
1 => [ 'key' => 'R',
'key' => 'U', 0 => null,
0 => [ 1 => [
'key' => 'T', 'key' => 'T',
0 => null, 0 => null,
1 => null 1 => null
], ]
1 => [ ],
'key' => 'Z', 1 => [
0 => null, 'key' => 'Z',
1 => null 0 => null,
], 1 => null
], ],
], ],
], ],