github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/algorithm/datastructures/tree/avl/avl_tree_test.go (about) 1 package avl 2 3 import "testing" 4 5 var intCmpFunc CompareFunc = func(v, nodeV interface{}) int { 6 vv := v.(int) 7 nv := nodeV.(int) 8 if vv > nv { 9 return 1 10 } else if vv < nv { 11 return -1 12 } else { 13 return 0 14 } 15 } 16 17 func TestAVLTree_Add(t *testing.T) { 18 tree := NewAVLTree(intCmpFunc) 19 for i := 0; i < 10; i++ { 20 tree.Add(i) 21 } 22 t.Log(tree) 23 t.Log(IsBST(tree)) 24 t.Log(IsBalanced(tree)) 25 }