Skip to content

Commit 9a9eae3

Browse files
committed
Rename node-level test predicates to make it clearer they operate on the node-level
1 parent 687a17d commit 9a9eae3

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

binarytree.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ func (n *Node[T]) Height() int {
287287
return max_height
288288
}
289289

290-
// IsLeaf returns true, if the node is a leaf, false otherwise.
291-
func (n *Node[T]) IsLeaf() bool {
290+
// IsLeafNode returns true, if the node is a leaf, false otherwise.
291+
func (n *Node[T]) IsLeafNode() bool {
292292
return n.Left == nil && n.Right == nil
293293
}
294294

@@ -349,7 +349,7 @@ func (n *Node[T]) IsFullTree() bool {
349349
if err != nil {
350350
panic(err)
351351
}
352-
if node.IsLeaf() {
352+
if node.IsLeafNode() {
353353
continue
354354
}
355355

@@ -375,7 +375,7 @@ func (n *Node[T]) IsDegenerateTree() bool {
375375
if err != nil {
376376
panic(err)
377377
}
378-
if node.IsLeaf() {
378+
if node.IsLeafNode() {
379379
continue
380380
}
381381
both := node.Left != nil && node.Right != nil

binarytree_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestHeightAndSize(t *testing.T) {
4141
}
4242
}
4343

44-
func TestIsLeaf(t *testing.T) {
44+
func TestIsLeafNode(t *testing.T) {
4545
// Our test tree
4646
//
4747
// __1
@@ -56,23 +56,23 @@ func TestIsLeaf(t *testing.T) {
5656
four := two.InsertLeft(4)
5757
five := two.InsertRight(5)
5858

59-
if root.IsLeaf() {
59+
if root.IsLeafNode() {
6060
t.Fatal("root node should not be a leaf")
6161
}
6262

63-
if two.IsLeaf() {
63+
if two.IsLeafNode() {
6464
t.Fatal("node (2) should not be a leaf")
6565
}
6666

67-
if !three.IsLeaf() {
67+
if !three.IsLeafNode() {
6868
t.Fatal("node (3) should be a leaf")
6969
}
7070

71-
if !four.IsLeaf() {
71+
if !four.IsLeafNode() {
7272
t.Fatal("node (4) should not be a leaf")
7373
}
7474

75-
if !five.IsLeaf() {
75+
if !five.IsLeafNode() {
7676
t.Fatal("node (5) should be a leaf")
7777
}
7878
}

0 commit comments

Comments
 (0)