MCPcopy
hub / github.com/cayleygraph/cayley / TestIterator

Function TestIterator

graph/graphtest/graphtest.go:525–602  ·  view source on GitHub ↗
(t testing.TB, gen testutil.DatabaseFunc, _ *Config)

Source from the content-addressed store, hash-verified

523}
524
525func TestIterator(t testing.TB, gen testutil.DatabaseFunc, _ *Config) {
526 ctx := context.TODO()
527 qs, opts, closer := gen(t)
528 defer closer()
529
530 testutil.MakeWriter(t, qs, opts, MakeQuadSet()...)
531
532 var it graph.Iterator
533
534 it = qs.NodesAllIterator()
535 require.NotNil(t, it)
536
537 size, _ := it.Size()
538 require.True(t, size > 0 && size < 23, "Unexpected size: %v", size)
539 // TODO: leveldb had this test
540 //if exact {
541 // t.Errorf("Got unexpected exact result.")
542 //}
543
544 optIt, changed := it.Optimize()
545 require.True(t, !changed && optIt == it, "Optimize unexpectedly changed iterator: %v, %T(%p) vs %T(%p)", changed, optIt, optIt, it, it)
546
547 expect := []string{
548 "A",
549 "B",
550 "C",
551 "D",
552 "E",
553 "F",
554 "G",
555 "follows",
556 "status",
557 "cool",
558 "status_graph",
559 }
560 sort.Strings(expect)
561 for i := 0; i < 2; i++ {
562 got := IteratedStrings(t, qs, it)
563 sort.Strings(got)
564 require.Equal(t, expect, got, "Unexpected iterated result on repeat %d", i)
565 it.Reset()
566 }
567
568 for _, pq := range expect {
569 ok := it.Contains(ctx, qs.ValueOf(quad.Raw(pq)))
570 require.NoError(t, it.Err())
571 require.True(t, ok, "Failed to find and check %q correctly", pq)
572
573 }
574 // FIXME(kortschak) Why does this fail?
575 /*
576 for _, pq := range []string{"baller"} {
577 if it.Contains(qs.ValueOf(pq)) {
578 t.Errorf("Failed to check %q correctly", pq)
579 }
580 }
581 */
582 it.Reset()

Callers

nothing calls this directly

Calls 15

SizeMethod · 0.95
OptimizeMethod · 0.95
ResetMethod · 0.95
ContainsMethod · 0.95
ErrMethod · 0.95
NextMethod · 0.95
ResultMethod · 0.95
MakeWriterFunction · 0.92
MakeQuadSetFunction · 0.85
IteratedStringsFunction · 0.85
NodesAllIteratorMethod · 0.65
ValueOfMethod · 0.65

Tested by

no test coverage detected