MCPcopy Create free account
hub / github.com/arnauddri/algorithms / TestTree

Function TestTree

data-structures/binary-tree/bst_test.go:8–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestTree(t *testing.T) {
9 n := NewNode(1)
10 m := NewNode(2)
11
12 // Test compare
13 if n.Compare(m) != -1 || m.Compare(n) != 1 || n.Compare(n) != 0 {
14 fmt.Println(n.Compare(m))
15 t.Error()
16 }
17
18 tree := NewTree(n)
19
20 tree.Insert(4)
21 tree.Insert(2)
22 tree.Insert(5)
23 tree.Insert(3)
24 tree.Insert(6)
25
26 if tree.Size != 6 {
27 fmt.Println(tree.Size)
28 t.Error()
29 }
30
31 five := tree.Search(5)
32
33 if five.Value != 5 ||
34 five.Parent.Value != 4 ||
35 five.Right.Value != 6 ||
36 five.Left != nil {
37 fmt.Println(*tree.Search(5))
38 t.Error()
39 }
40
41 tree.Delete(5)
42
43 if tree.Size != 5 {
44 t.Error()
45 }
46
47 four := *tree.Search(4)
48 if four.Right.Value != 6 ||
49 four.Left.Value != 2 ||
50 four.Parent.Value != 1 {
51 fmt.Println(*tree.Search(4))
52 t.Error()
53 }
54}

Callers

nothing calls this directly

Calls 6

CompareMethod · 0.95
InsertMethod · 0.95
SearchMethod · 0.95
DeleteMethod · 0.95
NewTreeFunction · 0.85
NewNodeFunction · 0.70

Tested by

no test coverage detected