Skip to content

Commit be28b27

Browse files
authored
Sync binary-search-tree (#848)
[no important files changed]
1 parent 2e55e9b commit be28b27

File tree

4 files changed

+82
-45
lines changed

4 files changed

+82
-45
lines changed

exercises/practice/binary-search-tree/.meta/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
".meta/example.php"
1414
]
1515
},
16-
"blurb": "Insert and search for numbers in a binary tree."
16+
"blurb": "Insert and search for numbers in a binary tree.",
17+
"source": "Josh Cheek"
1718
}

exercises/practice/binary-search-tree/.meta/example.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
class BinarySearchTree
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[e9c93a78-c536-4750-a336-94583d23fafa]
13+
description = "data is retained"
14+
15+
[7a95c9e8-69f6-476a-b0c4-4170cb3f7c91]
16+
description = "insert data at proper node -> smaller number at left node"
17+
18+
[22b89499-9805-4703-a159-1a6e434c1585]
19+
description = "insert data at proper node -> same number at left node"
20+
21+
[2e85fdde-77b1-41ed-b6ac-26ce6b663e34]
22+
description = "insert data at proper node -> greater number at right node"
23+
24+
[dd898658-40ab-41d0-965e-7f145bf66e0b]
25+
description = "can create complex tree"
26+
27+
[9e0c06ef-aeca-4202-b8e4-97f1ed057d56]
28+
description = "can sort data -> can sort single number"
29+
30+
[425e6d07-fceb-4681-a4f4-e46920e380bb]
31+
description = "can sort data -> can sort if second number is smaller than first"
32+
33+
[bd7532cc-6988-4259-bac8-1d50140079ab]
34+
description = "can sort data -> can sort if second number is same as first"
35+
36+
[b6d1b3a5-9d79-44fd-9013-c83ca92ddd36]
37+
description = "can sort data -> can sort if second number is greater than first"
38+
39+
[d00ec9bd-1288-4171-b968-d44d0808c1c8]
40+
description = "can sort data -> can sort complex tree"

exercises/practice/binary-search-tree/BinarySearchTreeTest.php

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
11
<?php
22

3-
/*
4-
* By adding type hints and enabling strict type checking, code can become
5-
* easier to read, self-documenting and reduce the number of potential bugs.
6-
* By default, type declarations are non-strict, which means they will attempt
7-
* to change the original type to match the type specified by the
8-
* type-declaration.
9-
*
10-
* In other words, if you pass a string to a function requiring a float,
11-
* it will attempt to convert the string value to a float.
12-
*
13-
* To enable strict mode, a single declare directive must be placed at the top
14-
* of the file.
15-
* This means that the strictness of typing is configured on a per-file basis.
16-
* This directive not only affects the type declarations of parameters, but also
17-
* a function's return type.
18-
*
19-
* For more info review the Concept on strict type checking in the PHP track
20-
* <link>.
21-
*
22-
* To disable strict typing, comment out the directive below.
23-
*/
24-
253
declare(strict_types=1);
264

275
class BinarySearchTreeTest extends PHPUnit\Framework\TestCase
@@ -31,12 +9,20 @@ public static function setUpBeforeClass(): void
319
require_once 'BinarySearchTree.php';
3210
}
3311

12+
/**
13+
* uuid e9c93a78-c536-4750-a336-94583d23fafa
14+
* @testdox data is retained
15+
*/
3416
public function testDataIsRetained(): void
3517
{
3618
$tree = new BinarySearchTree(4);
3719
$this->assertEquals(4, $tree->data);
3820
}
3921

22+
/**
23+
* uuid 7a95c9e8-69f6-476a-b0c4-4170cb3f7c91
24+
* @testdox smaller number at left node
25+
*/
4026
public function testSmallNumberAtLeftNode(): void
4127
{
4228
$tree = new BinarySearchTree(4);
@@ -46,6 +32,10 @@ public function testSmallNumberAtLeftNode(): void
4632
$this->assertEquals(2, $tree->left->data);
4733
}
4834

35+
/**
36+
* uuid 22b89499-9805-4703-a159-1a6e434c1585
37+
* @testdox same number at left node
38+
*/
4939
public function testSameNumberLeftNodes(): void
5040
{
5141
$tree = new BinarySearchTree(4);
@@ -55,6 +45,10 @@ public function testSameNumberLeftNodes(): void
5545
$this->assertEquals(4, $tree->left->data);
5646
}
5747

48+
/**
49+
* uuid 2e85fdde-77b1-41ed-b6ac-26ce6b663e34
50+
* @testdox greater number at right node
51+
*/
5852
public function testGreaterNumberRightNode(): void
5953
{
6054
$tree = new BinarySearchTree(4);
@@ -64,6 +58,10 @@ public function testGreaterNumberRightNode(): void
6458
$this->assertEquals(5, $tree->right->data);
6559
}
6660

61+
/**
62+
* uuid dd898658-40ab-41d0-965e-7f145bf66e0b
63+
* @testdox can create complex tree
64+
*/
6765
public function testCreateComplexTree(): void
6866
{
6967
$tree = new BinarySearchTree(4);
@@ -83,13 +81,21 @@ public function testCreateComplexTree(): void
8381
$this->assertEquals(7, $tree->right->right->data);
8482
}
8583

84+
/**
85+
* uuid 9e0c06ef-aeca-4202-b8e4-97f1ed057d56
86+
* @testdox can sort single number
87+
*/
8688
public function testCanSortSingleNode(): void
8789
{
8890
$tree = new BinarySearchTree(2);
8991

9092
$this->assertEquals([2], $tree->getSortedData());
9193
}
9294

95+
/**
96+
* uuid 425e6d07-fceb-4681-a4f4-e46920e380bb
97+
* @testdox can sort if second number is smaller than first
98+
*/
9399
public function testCanSortSmallerSecondNumber(): void
94100
{
95101
$tree = new BinarySearchTree(2);
@@ -98,6 +104,10 @@ public function testCanSortSmallerSecondNumber(): void
98104
$this->assertEquals([1, 2], $tree->getSortedData());
99105
}
100106

107+
/**
108+
* uuid bd7532cc-6988-4259-bac8-1d50140079ab
109+
* @testdox can sort if second number is same as first
110+
*/
101111
public function testCanSortSameNumbers(): void
102112
{
103113
$tree = new BinarySearchTree(2);
@@ -106,6 +116,10 @@ public function testCanSortSameNumbers(): void
106116
$this->assertEquals([2, 2], $tree->getSortedData());
107117
}
108118

119+
/**
120+
* uuid b6d1b3a5-9d79-44fd-9013-c83ca92ddd36
121+
* @testdox can sort if second number is greater than first
122+
*/
109123
public function testCanSortGreaterSecondNumber(): void
110124
{
111125
$tree = new BinarySearchTree(2);
@@ -114,6 +128,10 @@ public function testCanSortGreaterSecondNumber(): void
114128
$this->assertEquals([2, 3], $tree->getSortedData());
115129
}
116130

131+
/**
132+
* uuid d00ec9bd-1288-4171-b968-d44d0808c1c8
133+
* @testdox can sort complex tree
134+
*/
117135
public function testCanSortComplexTree(): void
118136
{
119137
$tree = new BinarySearchTree(2);

0 commit comments

Comments
 (0)