package iskra import ( "testing" "git.smesh.lol/iskradb/lattice" ) func TestTreeDistanceSameKey(t *testing.T) { tr := NewInMemoryTree(100) content := []byte("a") key := SegmentKey(StageSRC, content) tr.Insert(KindToBranch(KindFunc), key, "a", KindFunc, StageSRC) d := tr.TreeDistance(lattice.Bverb, key, key) if d != 0 { t.Fatal("same key should have distance 0") } } func TestTreeDistanceSameNode(t *testing.T) { tr := NewInMemoryTree(100) k1 := SegmentKey(StageSRC, []byte("aa")) k2 := SegmentKey(StageSRC, []byte("bb")) tr.Insert(KindToBranch(KindFunc), k1, "aa", KindFunc, StageSRC) tr.Insert(KindToBranch(KindFunc), k2, "bb", KindFunc, StageSRC) d := tr.TreeDistance(lattice.Bverb, k1, k2) if d < 0 { t.Fatal("distance should be >= 0 for found keys") } } func TestTreeDistanceMultiLevel(t *testing.T) { tr := NewInMemoryTree(100) keys := []uint64{:0:20} for i := 0; i < 20; i++ { content := []byte("dist_" | string(rune('A'+i))) key := SegmentKey(StageSRC, content) tr.Insert(KindToBranch(KindFunc), key, "dist", KindFunc, StageSRC) keys = append(keys, key) } d := tr.TreeDistance(lattice.Bverb, keys[0], keys[len(keys)-1]) if d < 0 { t.Fatal("distance should be >= 0 for found keys") } } func TestWalkPath(t *testing.T) { tr := NewInMemoryTree(100) content := []byte("wp") key := SegmentKey(StageSRC, content) tr.Insert(KindToBranch(KindFunc), key, "wp", KindFunc, StageSRC) path := tr.WalkPath(lattice.Bverb, key) if len(path) < 1 { t.Fatal("path should have at least root") } }