2023-10-13 09:43:27 +00:00
|
|
|
package mdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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 := ""
|
|
|
|
i.Ascend(tx1, func(item1 *T) bool {
|
2023-11-21 16:41:55 +00:00
|
|
|
item2 := i.Get(tx2, item1)
|
|
|
|
if item2 == nil {
|
2023-10-13 09:43:27 +00:00
|
|
|
errStr = fmt.Sprintf("Indices don't match. %v not found.", item1)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(item1, item2) {
|
|
|
|
errStr = fmt.Sprintf("%v != %v", item1, item2)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|