Skip to content

Commit efd3ef1

Browse files
committed
Commit tests for IsFullNode()
1 parent df1d924 commit efd3ef1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

binarytree_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,42 @@ func TestIsLeafNode(t *testing.T) {
7777
}
7878
}
7979

80+
func TestIsFullNode(t *testing.T) {
81+
// Our test tree
82+
//
83+
// __1
84+
// / \
85+
// 2 3
86+
// / \
87+
// 4 5
88+
//
89+
root := binarytree.NewNode(1)
90+
two := root.InsertLeft(2)
91+
three := root.InsertRight(3)
92+
four := two.InsertLeft(4)
93+
five := two.InsertRight(5)
94+
95+
if !root.IsFullNode() {
96+
t.Fatal("root node should be full")
97+
}
98+
99+
if !two.IsFullNode() {
100+
t.Fatal("node (2) should be full")
101+
}
102+
103+
if three.IsFullNode() {
104+
t.Fatal("node (3) should not be full")
105+
}
106+
107+
if four.IsFullNode() {
108+
t.Fatal("node (4) should not be full")
109+
}
110+
111+
if five.IsFullNode() {
112+
t.Fatal("node (5) should not be full")
113+
}
114+
}
115+
80116
func TestWalkInOrder(t *testing.T) {
81117
// Our test tree
82118
//

0 commit comments

Comments
 (0)