github.com/cayleygraph/cayley@v0.7.7/graph/iterator/limit_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 TestLimitIteratorBasics(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 := NewLimit(allIt, 0) 22 expectSz, _ := allIt.Size() 23 if sz, _ := u.Size(); sz != expectSz { 24 t.Errorf("Failed to check Limit 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 Limit correctly: got:%v expected:%v", got, expect) 29 } 30 31 allIt.Reset() 32 33 u = NewLimit(allIt, 3) 34 expectSz = 3 35 if sz, _ := u.Size(); sz != expectSz { 36 t.Errorf("Failed to check Limit size: got:%v expected:%v", sz, expectSz) 37 } 38 expect = []int{1, 2, 3} 39 if got := iterated(u); !reflect.DeepEqual(got, expect) { 40 t.Errorf("Failed to iterate Limit correctly: got:%v expected:%v", got, expect) 41 } 42 43 for _, v := range []int{1, 2, 3} { 44 if !u.Contains(ctx, Int64Node(v)) { 45 t.Errorf("Failed to find a correct value in the Limit iterator.") 46 } 47 } 48 if u.Contains(ctx, Int64Node(4)) { 49 t.Error("should have no more results") 50 } 51 u.Reset() 52 for _, v := range []int{5, 4, 3} { 53 if !u.Contains(ctx, Int64Node(v)) { 54 t.Errorf("Failed to find a correct value in the Limit iterator.") 55 } 56 } 57 if u.Contains(ctx, Int64Node(2)) { 58 t.Error("should have no more results") 59 } 60 }