rbt: add rbt insert test

This commit is contained in:
c9s 2021-06-06 18:00:45 +08:00
parent 7512f56b84
commit 103b1ea560

View File

@ -1,12 +1,30 @@
package types
import (
"math/rand"
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/stretchr/testify/assert"
)
func TestTree_InsertAndDelete(t *testing.T) {
var keys []fixedpoint.Value
tree := NewRBTree()
for i := 1; i < 10.0; i++ {
v := fixedpoint.NewFromFloat(rand.Float64())
keys = append(keys, v)
tree.Insert(v, fixedpoint.NewFromFloat(float64(i)))
}
for _, key := range keys {
ok := tree.Delete(key)
assert.True(t, ok, "should find and delete the node")
}
}
func TestTree_CopyInorder(t *testing.T) {
tree := NewRBTree()
for i := 1.0; i < 10.0; i += 1.0 {