Skip to content

Commit 687a17d

Browse files
committed
Rename test predicates to indicate that we are operating at the tree-level, rather than the node-level
1 parent 27cd32d commit 687a17d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

binarytree.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,9 @@ func (n *Node[T]) FindNode(predicate FindFunc[T]) (*Node[T], bool) {
338338
return nil, false
339339
}
340340

341-
// IsFull returns true, if the binary tree is full. A full binary tree
341+
// IsFullTree returns true, if the binary tree is full. A full binary tree
342342
// is a tree in which every node has either 0 or 2 children.
343-
func (n *Node[T]) IsFull() bool {
343+
func (n *Node[T]) IsFullTree() bool {
344344
stack := deque.New[*Node[T]]()
345345
stack.PushFront(n)
346346

@@ -365,8 +365,8 @@ func (n *Node[T]) IsFull() bool {
365365
return true
366366
}
367367

368-
// IsDegenerate returns true, if each parent has only one child node.
369-
func (n *Node[T]) IsDegenerate() bool {
368+
// IsDegenerateTree returns true, if each parent has only one child node.
369+
func (n *Node[T]) IsDegenerateTree() bool {
370370
stack := deque.New[*Node[T]]()
371371
stack.PushFront(n)
372372

@@ -394,10 +394,10 @@ func (n *Node[T]) IsDegenerate() bool {
394394
return true
395395
}
396396

397-
// IsBalanced returns true, if the tree is balanced. A balanced tree
397+
// IsBalancedTree returns true, if the tree is balanced. A balanced tree
398398
// is such a tree, for which the height of the left and right
399399
// sub-trees of each node differ by no more than 1.
400-
func (n *Node[T]) IsBalanced() bool {
400+
func (n *Node[T]) IsBalancedTree() bool {
401401
if n.Left == nil && n.Right == nil {
402402
return true
403403
}

binarytree_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestIsFullTree(t *testing.T) {
299299
two.InsertLeft(4)
300300
two.InsertRight(5)
301301

302-
if !root.IsFull() {
302+
if !root.IsFullTree() {
303303
t.Fatal("tree should be full")
304304
}
305305
}
@@ -318,12 +318,12 @@ func TestIsNotFullTree(t *testing.T) {
318318
two.InsertLeft(4)
319319
two.InsertRight(5)
320320

321-
if root.IsFull() {
321+
if root.IsFullTree() {
322322
t.Fatal("tree should not be full")
323323
}
324324
}
325325

326-
func TestTreeIsDegenerate(t *testing.T) {
326+
func TestTreeIsDegenerateTree(t *testing.T) {
327327
// Our test tree
328328
//
329329
// 1
@@ -339,7 +339,7 @@ func TestTreeIsDegenerate(t *testing.T) {
339339
three := two.InsertRight(3)
340340
three.InsertLeft(4)
341341

342-
if !root.IsDegenerate() {
342+
if !root.IsDegenerateTree() {
343343
t.Fatal("tree should be degenerate")
344344
}
345345
}
@@ -358,12 +358,12 @@ func TestTreeIsNotDegenerate(t *testing.T) {
358358
two.InsertLeft(4)
359359
two.InsertRight(5)
360360

361-
if root.IsDegenerate() {
361+
if root.IsDegenerateTree() {
362362
t.Fatal("tree should not be degenerate")
363363
}
364364
}
365365

366-
func TestIsBalanced(t *testing.T) {
366+
func TestIsBalancedTree(t *testing.T) {
367367
// Unbalanced tree
368368
//
369369
// 1
@@ -376,7 +376,7 @@ func TestIsBalanced(t *testing.T) {
376376
two := unbalanced_root.InsertLeft(2)
377377
two.InsertLeft(3)
378378

379-
if unbalanced_root.IsBalanced() {
379+
if unbalanced_root.IsBalancedTree() {
380380
t.Fatal("tree should not be balanced")
381381
}
382382

@@ -397,13 +397,13 @@ func TestIsBalanced(t *testing.T) {
397397
four.InsertLeft(6)
398398
four.InsertRight(7)
399399

400-
if unbalanced_root.IsBalanced() {
400+
if unbalanced_root.IsBalancedTree() {
401401
t.Fatal("tree should not be balanced")
402402
}
403403

404404
// A single root node is a balanced tree
405405
leaf := binarytree.NewNode(1)
406-
if !leaf.IsBalanced() {
406+
if !leaf.IsBalancedTree() {
407407
t.Fatal("single leaf node should be balanced")
408408
}
409409

@@ -420,12 +420,12 @@ func TestIsBalanced(t *testing.T) {
420420
two.InsertLeft(4)
421421
two.InsertRight(5)
422422

423-
if unbalanced_root.IsBalanced() {
423+
if unbalanced_root.IsBalancedTree() {
424424
t.Fatal("tree should not be balanced")
425425
}
426426

427427
// The sub-tree with root node (2) is balanced
428-
if !two.IsBalanced() {
428+
if !two.IsBalancedTree() {
429429
t.Fatal("tree with root (2) should be balanced")
430430
}
431431

@@ -442,7 +442,7 @@ func TestIsBalanced(t *testing.T) {
442442
three.InsertLeft(4)
443443
three.InsertRight(5)
444444

445-
if !balanced_root.IsBalanced() {
445+
if !balanced_root.IsBalancedTree() {
446446
t.Fatal("tree should be balanced")
447447
}
448448
}

0 commit comments

Comments
 (0)