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