Replace DebugString with Describe

This change makes tree description completely open to mechanical
analysis and ensures consistency between description formats for each of
the iterator types.

Renamed StatsContainer.(Kind -> Type) for consistency.
This commit is contained in:
kortschak 2014-09-05 09:05:02 +09:30
parent b5f113203d
commit 62013d3dfc
22 changed files with 186 additions and 162 deletions

View file

@ -15,9 +15,7 @@
package memstore
import (
"fmt"
"math"
"strings"
"github.com/google/cayley/graph"
"github.com/google/cayley/graph/iterator"
@ -159,9 +157,15 @@ func (it *Iterator) Contains(v graph.Value) bool {
return graph.ContainsLogOut(it, v, false)
}
func (it *Iterator) DebugString(indent int) string {
func (it *Iterator) Describe() graph.Description {
size, _ := it.Size()
return fmt.Sprintf("%s(%s tags:%s size:%d %s)", strings.Repeat(" ", indent), it.Type(), it.tags.Tags(), size, it.data)
return graph.Description{
UID: it.UID(),
Name: it.data,
Type: it.Type().String(),
Tags: it.tags.Tags(),
Size: size,
}
}
var memType graph.Type

View file

@ -165,8 +165,11 @@ func TestLinksToOptimization(t *testing.T) {
v := newIt.(*Iterator)
vClone := v.Clone()
if vClone.DebugString(0) != v.DebugString(0) {
t.Fatal("Wrong iterator. Got ", vClone.DebugString(0))
origDesc := v.Describe()
cloneDesc := vClone.Describe()
origDesc.UID, cloneDesc.UID = 0, 0 // We are more strict now, so fake UID equality.
if !reflect.DeepEqual(cloneDesc, origDesc) {
t.Fatalf("Unexpected iterator description.\ngot: %#v\nexpect: %#v", cloneDesc, origDesc)
}
vt := vClone.Tagger()
if len(vt.Tags()) < 1 || vt.Tags()[0] != "foo" {