jldb/mdb/equality_test.go

57 lines
1.1 KiB
Go

package mdb
import (
"reflect"
"testing"
)
func (i Index[T]) AssertEqual(t *testing.T, tx1, tx2 *Snapshot) {
t.Helper()
state1 := i.getState(tx1)
state2 := i.getState(tx2)
if state1.BTree.Len() != state2.BTree.Len() {
t.Fatalf("(%s) Unequal lengths: %d != %d",
i.name,
state1.BTree.Len(),
state2.BTree.Len())
}
errStr := ""
iter := i.Ascend(tx1)
for item1 := range iter {
item2 := i.Get(tx2, item1)
if item2 == nil {
t.Fatalf("Indices don't match. %v not found.", item1)
}
if !reflect.DeepEqual(item1, item2) {
t.Fatalf("%v != %v", item1, item2)
}
}
if errStr != "" {
t.Fatal(errStr)
}
}
func (c *Collection[T]) AssertEqual(t *testing.T, tx1, tx2 *Snapshot) {
t.Helper()
c.ByID.AssertEqual(t, tx1, tx2)
for _, idx := range c.indices {
idx.AssertEqual(t, tx1, tx2)
}
}
func (db *Database) AssertEqual(t *testing.T, db2 *Database) {
tx1 := db.Snapshot()
tx2 := db.Snapshot()
for _, c := range db.collections {
cc := c.(interface {
AssertEqual(t *testing.T, tx1, tx2 *Snapshot)
})
cc.AssertEqual(t, tx1, tx2)
}
}