chore: add more tests (#3338)
This commit is contained in:
@@ -171,11 +171,11 @@ func add(nd *node, route string, item any) error {
|
||||
token := route[:i]
|
||||
children := nd.getChildren(token)
|
||||
if child, ok := children[token]; ok {
|
||||
if child != nil {
|
||||
return add(child, route[i+1:], item)
|
||||
if child == nil {
|
||||
return errInvalidState
|
||||
}
|
||||
|
||||
return errInvalidState
|
||||
return add(child, route[i+1:], item)
|
||||
}
|
||||
|
||||
child := newNode(nil)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
type mockedRoute struct {
|
||||
route string
|
||||
value int
|
||||
value any
|
||||
}
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
@@ -187,6 +187,12 @@ func TestSearchInvalidItem(t *testing.T) {
|
||||
assert.Equal(t, errEmptyItem, err)
|
||||
}
|
||||
|
||||
func TestSearchInvalidState(t *testing.T) {
|
||||
nd := newNode("0")
|
||||
nd.children[0]["1"] = nil
|
||||
assert.Error(t, add(nd, "1/2", "2"))
|
||||
}
|
||||
|
||||
func BenchmarkSearchTree(b *testing.B) {
|
||||
const (
|
||||
avgLen = 1000
|
||||
|
||||
Reference in New Issue
Block a user