github.com/cayleygraph/cayley@v0.7.7/graph/iterator/not_test.go (about) 1 package iterator_test 2 3 import ( 4 "context" 5 "errors" 6 "reflect" 7 "testing" 8 9 . "github.com/cayleygraph/cayley/graph/iterator" 10 ) 11 12 func TestNotIteratorBasics(t *testing.T) { 13 ctx := context.TODO() 14 allIt := NewFixed( 15 Int64Node(1), 16 Int64Node(2), 17 Int64Node(3), 18 Int64Node(4), 19 ) 20 21 toComplementIt := NewFixed( 22 Int64Node(2), 23 Int64Node(4), 24 ) 25 26 not := NewNot(toComplementIt, allIt) 27 28 if v, _ := not.Size(); v != 2 { 29 t.Errorf("Unexpected iterator size: got:%d, expected: %d", v, 2) 30 } 31 32 expect := []int{1, 3} 33 for i := 0; i < 2; i++ { 34 if got := iterated(not); !reflect.DeepEqual(got, expect) { 35 t.Errorf("Failed to iterate Not correctly on repeat %d: got:%v expected:%v", i, got, expect) 36 } 37 not.Reset() 38 } 39 40 for _, v := range []int{1, 3} { 41 if !not.Contains(ctx, Int64Node(v)) { 42 t.Errorf("Failed to correctly check %d as true", v) 43 } 44 } 45 46 for _, v := range []int{2, 4} { 47 if not.Contains(ctx, Int64Node(v)) { 48 t.Errorf("Failed to correctly check %d as false", v) 49 } 50 } 51 } 52 53 func TestNotIteratorErr(t *testing.T) { 54 ctx := context.TODO() 55 wantErr := errors.New("unique") 56 allIt := newTestIterator(false, wantErr) 57 58 toComplementIt := NewFixed() 59 60 not := NewNot(toComplementIt, allIt) 61 62 if not.Next(ctx) != false { 63 t.Errorf("Not iterator did not pass through initial 'false'") 64 } 65 if not.Err() != wantErr { 66 t.Errorf("Not iterator did not pass through underlying Err") 67 } 68 }