rbt: add more test cases

This commit is contained in:
c9s 2021-06-07 02:23:18 +08:00
parent 9622956c71
commit 3b0ed4e3dc

View File

@ -10,14 +10,18 @@ import (
func TestRBTree_InsertAndDelete(t *testing.T) { func TestRBTree_InsertAndDelete(t *testing.T) {
tree := NewRBTree() tree := NewRBTree()
node := tree.Rightmost()
assert.Nil(t, node)
tree.Insert(fixedpoint.NewFromInt(10), 10) tree.Insert(fixedpoint.NewFromInt(10), 10)
tree.Insert(fixedpoint.NewFromInt(9), 9) tree.Insert(fixedpoint.NewFromInt(9), 9)
tree.Insert(fixedpoint.NewFromInt(12), 12) tree.Insert(fixedpoint.NewFromInt(12), 12)
tree.Insert(fixedpoint.NewFromInt(11), 11) tree.Insert(fixedpoint.NewFromInt(11), 11)
tree.Insert(fixedpoint.NewFromInt(13), 13) tree.Insert(fixedpoint.NewFromInt(13), 13)
node := tree.Rightmost() node = tree.Rightmost()
assert.Equal(t, fixedpoint.NewFromInt(13), node.Key) assert.Equal(t, fixedpoint.NewFromInt(13), node.Key)
assert.Equal(t, fixedpoint.Value(13), node.Value)
ok := tree.Delete(fixedpoint.NewFromInt(12)) ok := tree.Delete(fixedpoint.NewFromInt(12))
assert.True(t, ok, "should delete the node successfully") assert.True(t, ok, "should delete the node successfully")