github.com/cayleygraph/cayley@v0.7.7/graph/kv/indexing_test.go (about) 1 package kv 2 3 import "testing" 4 5 func TestIntersectSorted(t *testing.T) { 6 tt := []struct { 7 a []uint64 8 b []uint64 9 expect []uint64 10 }{ 11 { 12 a: []uint64{1, 2, 3, 4, 5, 6}, 13 b: []uint64{2, 4, 6, 8, 10}, 14 expect: []uint64{2, 4, 6}, 15 }, 16 { 17 a: []uint64{6, 7, 8, 9, 10, 11}, 18 b: []uint64{1, 2, 3, 4, 5, 6}, 19 expect: []uint64{6}, 20 }, 21 } 22 23 for i, x := range tt { 24 c := intersectSortedUint64(x.a, x.b) 25 if len(c) != len(x.expect) { 26 t.Errorf("unexpected length: %d expected %d for test %d", len(c), len(x.expect), i) 27 } 28 for i, y := range c { 29 if y != x.expect[i] { 30 t.Errorf("unexpected entry: %#v expected %#v for test %d", c, x.expect, i) 31 } 32 } 33 } 34 } 35 36 func TestIndexlist(t *testing.T) { 37 init := []uint64{5, 10, 2340, 32432, 3243366} 38 b := appendIndex(nil, init) 39 out, err := decodeIndex(b) 40 if err != nil { 41 t.Fatalf("couldn't decodeIndex: %s", err) 42 } 43 if len(out) != len(init) { 44 t.Fatalf("mismatched lengths. got %#v expected %#v", out, init) 45 } 46 for i := 0; i < len(out); i++ { 47 if out[i] != init[i] { 48 t.Fatalf("mismatched element %d. got %#v expected %#v", i, out, init) 49 } 50 } 51 }