mdb/btreeiterator_test.go

50 lines
1022 B
Go

package mdb
/*Copyright (c) 2022, John David Lee
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
*/
import (
"reflect"
"testing"
)
func TestBTreeIterator(t *testing.T) {
testWithDB(t, "min/max matches iterator", func(t *testing.T, db *DB) {
users := []User{
{ID: db.Users.c.NextID(), Email: "a@b.com", Name: "aaa"},
{ID: db.Users.c.NextID(), Email: "e@f.com", Name: "bbb"},
{ID: db.Users.c.NextID(), Email: "c@d.com", Name: "ccc"},
}
for _, u := range users {
if _, err := db.Users.c.Insert(u); err != nil {
t.Fatal(err)
}
}
it := db.Users.nameBTree.Ascend()
if !it.Next() {
t.Fatal("No next")
}
u := it.Value()
if !reflect.DeepEqual(u, users[0]) {
t.Fatal(u, users[0])
}
it.Close()
it = db.Users.nameBTree.Descend()
if !it.Next() {
t.Fatal("No next")
}
u = it.Value()
if !reflect.DeepEqual(u, users[2]) {
t.Fatal(u, users[2])
}
it.Close()
})
}