MCPcopy
hub / github.com/TheAlgorithms/Go / TestBinarySearch

Function TestBinarySearch

structure/tree/example_test.go:38–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36var tree TestTree[int]
37
38func TestBinarySearch(t *testing.T) {
39 tree = bt.NewBinarySearch[int]()
40
41 if tree.Empty() {
42 t.Log("Binary Search Tree is empty now.")
43 }
44
45 tree.Push(1, 4, 10)
46 tree.Push(-8)
47 nums := []int{87, 18, 10, -34}
48 tree.Push(nums...)
49 tree.Push(4) // duplicate key, dismiss it
50
51 if tree.Has(4) {
52 t.Logf("There is a node of 4")
53 }
54
55 if n, ok := tree.Get(10); ok {
56 t.Logf("node of 10: %T", n)
57 }
58
59 if ret, ok := tree.Min(); ok {
60 t.Logf("tree.Min() = %v", ret)
61 }
62
63 if ret, ok := tree.Max(); ok {
64 t.Logf("tree.Max() = %v", ret)
65 }
66
67 if ret, ok := tree.Predecessor(1); ok {
68 t.Logf("tree.Preducessor(1) = %v", ret)
69 }
70
71 if ret, ok := tree.Successor(18); ok {
72 t.Logf("tree.Successor(18) = %v", ret)
73 }
74
75 fmt.Println(tree.InOrder())
76 fmt.Println(tree.AccessNodesByLayer())
77
78 tree.Delete(18)
79 fmt.Println("Delete 18")
80 fmt.Println(tree.InOrder())
81}
82
83func TestAVL(t *testing.T) {
84 tree = bt.NewAVL[int]()

Callers

nothing calls this directly

Calls 11

EmptyMethod · 0.65
PushMethod · 0.65
HasMethod · 0.65
GetMethod · 0.65
MinMethod · 0.65
MaxMethod · 0.65
PredecessorMethod · 0.65
SuccessorMethod · 0.65
InOrderMethod · 0.65
AccessNodesByLayerMethod · 0.65
DeleteMethod · 0.65

Tested by

no test coverage detected