-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLowestCommonAncestorOfABinarySearchTreeTest.php
51 lines (41 loc) · 1.53 KB
/
LowestCommonAncestorOfABinarySearchTreeTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace leetcode\tests;
use leetcode\LowestCommonAncestorOfABinarySearchTree;
use leetcode\util\TreeNode;
use PHPUnit\Framework\TestCase;
class LowestCommonAncestorOfABinarySearchTreeTest extends TestCase
{
private $root;
public function setUp(): void
{
$this->root = new TreeNode(6);
$this->root->left = new TreeNode(2);
$this->root->right = new TreeNode(8);
$this->root->left->left = new TreeNode(0);
$this->root->left->right = new TreeNode(4);
$this->root->right->left = new TreeNode(7);
$this->root->right->right = new TreeNode(9);
$this->root->left->right->left = new TreeNode(3);
$this->root->left->right->right = new TreeNode(5);
parent::setUp();
}
public function testLowestCommonAncestorOfABinarySearchTree1(): void
{
$p = new TreeNode(2);
$q = new TreeNode(8);
$expect = get_class($this->root);
$actual = LowestCommonAncestorOfABinarySearchTree::lowestCommonAncestor($this->root, $p, $q);
self::assertInstanceOf($expect, $actual);
self::assertEquals(6, $actual->val);
}
public function testLowestCommonAncestorOfABinarySearchTree2(): void
{
$p = new TreeNode(2);
$q = new TreeNode(4);
$expect = get_class($this->root);
$actual = LowestCommonAncestorOfABinarySearchTree::lowestCommonAncestor($this->root, $p, $q);
self::assertInstanceOf($expect, $actual);
self::assertEquals(2, $actual->val);
}
}