github.com/cayleygraph/cayley@v0.7.7/graph/iterator/skip_test.go (about) 1 package iterator_test 2 3 import ( 4 "context" 5 "reflect" 6 "testing" 7 8 . "github.com/cayleygraph/cayley/graph/iterator" 9 ) 10 11 func TestSkipIteratorBasics(t *testing.T) { 12 ctx := context.TODO() 13 allIt := NewFixed( 14 Int64Node(1), 15 Int64Node(2), 16 Int64Node(3), 17 Int64Node(4), 18 Int64Node(5), 19 ) 20 21 u := NewSkip(allIt, 0) 22 expectSz, _ := allIt.Size() 23 if sz, _ := u.Size(); sz != expectSz { 24 t.Errorf("Failed to check Skip size: got:%v expected:%v", sz, expectSz) 25 } 26 expect := []int{1, 2, 3, 4, 5} 27 if got := iterated(u); !reflect.DeepEqual(got, expect) { 28 t.Errorf("Failed to iterate Skip correctly: got:%v expected:%v", got, expect) 29 } 30 31 allIt.Reset() 32 33 u = NewSkip(allIt, 3) 34 expectSz = 2 35 if sz, _ := u.Size(); sz != expectSz { 36 t.Errorf("Failed to check Skip size: got:%v expected:%v", sz, expectSz) 37 } 38 expect = []int{4, 5} 39 if got := iterated(u); !reflect.DeepEqual(got, expect) { 40 t.Errorf("Failed to iterate Skip correctly: got:%v expected:%v", got, expect) 41 } 42 43 u.Reset() 44 for _, v := range []int{1, 2, 3} { 45 if u.Contains(ctx, Int64Node(v)) { 46 t.Errorf("Failed to find a correct value in the Skip iterator.") 47 } 48 } 49 for _, v := range []int{4, 5} { 50 if !u.Contains(ctx, Int64Node(v)) { 51 t.Errorf("Failed to find a correct value in the Skip iterator.") 52 } 53 } 54 55 u.Reset() 56 for _, v := range []int{5, 4, 3} { 57 if u.Contains(ctx, Int64Node(v)) { 58 t.Errorf("Failed to find a correct value in the Skip iterator.") 59 } 60 } 61 for _, v := range []int{1, 2} { 62 if !u.Contains(ctx, Int64Node(v)) { 63 t.Errorf("Failed to find a correct value in the Skip iterator.") 64 } 65 } 66 67 // TODO(dennwc): check with NextPath 68 }