From 07d04a9cd001c427e273d1ff03ed464da0a0e527 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 7 Jun 2022 13:48:32 +0800 Subject: [PATCH] refactor: change function name --- datastructure/tree/bstree.go | 4 +- datastructure/tree/bstree_test.go | 78 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/datastructure/tree/bstree.go b/datastructure/tree/bstree.go index 81ccaa5..58c6944 100644 --- a/datastructure/tree/bstree.go +++ b/datastructure/tree/bstree.go @@ -24,7 +24,7 @@ func NewBSTree[T any](rootData T, comparator lancetconstraints.Comparator) *BSTr } // InsertNode insert data into BSTree -func (t *BSTree[T]) InsertNode(data T) { +func (t *BSTree[T]) Insert(data T) { root := t.root newNode := datastructure.NewTreeNode(data) if root == nil { @@ -35,7 +35,7 @@ func (t *BSTree[T]) InsertNode(data T) { } // DeletetNode delete data into BSTree -func (t *BSTree[T]) DeletetNode(data T) { +func (t *BSTree[T]) Delete(data T) { deleteTreeNode(t.root, data, t.comparator) } diff --git a/datastructure/tree/bstree_test.go b/datastructure/tree/bstree_test.go index 79212ed..962d0fd 100644 --- a/datastructure/tree/bstree_test.go +++ b/datastructure/tree/bstree_test.go @@ -20,13 +20,13 @@ func (c *intComparator) Compare(v1, v2 any) int { return 0 } -func TestBSTree_InsertNode(t *testing.T) { +func TestBSTree_Insert(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) bstree.Print() } @@ -36,10 +36,10 @@ func TestBSTree_PreOrderTraverse(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) acturl := bstree.PreOrderTraverse() t.Log(acturl) @@ -51,10 +51,10 @@ func TestBSTree_PostOrderTraverse(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) acturl := bstree.PostOrderTraverse() t.Log(acturl) @@ -66,10 +66,10 @@ func TestBSTree_InOrderTraverse(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) acturl := bstree.InOrderTraverse() t.Log(acturl) @@ -81,10 +81,10 @@ func TestBSTree_LevelOrderTraverse(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) bstree.Print() @@ -93,19 +93,19 @@ func TestBSTree_LevelOrderTraverse(t *testing.T) { assert.Equal([]int{6, 5, 7, 2, 4}, acturl) } -func TestBSTree_DeletetNode(t *testing.T) { - assert := internal.NewAssert(t, "TestBSTree_DeletetNode") +func TestBSTree_Delete(t *testing.T) { + assert := internal.NewAssert(t, "TestBSTree_Delete") bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) bstree.Print() - bstree.DeletetNode(4) + bstree.Delete(4) bstree.Print() acturl1 := bstree.InOrderTraverse() t.Log(acturl1) @@ -124,10 +124,10 @@ func TestBSTree_Depth(t *testing.T) { bstree := NewBSTree(6, &intComparator{}) - bstree.InsertNode(7) - bstree.InsertNode(5) - bstree.InsertNode(2) - bstree.InsertNode(4) + bstree.Insert(7) + bstree.Insert(5) + bstree.Insert(2) + bstree.Insert(4) bstree.Print() @@ -138,17 +138,17 @@ func TestBSTree_IsSubTree(t *testing.T) { assert := internal.NewAssert(t, "TestBSTree_IsSubTree") superTree := NewBSTree(8, &intComparator{}) - superTree.InsertNode(4) - superTree.InsertNode(5) - superTree.InsertNode(6) - superTree.InsertNode(9) - superTree.InsertNode(4) + superTree.Insert(4) + superTree.Insert(5) + superTree.Insert(6) + superTree.Insert(9) + superTree.Insert(4) superTree.Print() subTree := NewBSTree(5, &intComparator{}) - subTree.InsertNode(4) - subTree.InsertNode(6) + subTree.Insert(4) + subTree.Insert(6) subTree.Print()