示例#1
0
func TestKids_1(x *testing.T) {
	t := assert.New(x)
	nodes, dt, sup := startingPoints(t)
	n1 := nodes[0]
	kids, err := n1.Children(sup, dt)
	t.Nil(err)
	expected := set.FromSlice([]types.Hashable{
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(2)}),
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(3)}),
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(10)}),
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(11)}),
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(12)}),
	})
	var next *Node = nil
	for _, kid := range kids {
		if kid.(*Node).items.Has(types.Int32(2)) {
			next = kid.(*Node)
		}
		has := expected.Has(kid.(*Node).items)
		t.True(has, "%v not in %v", kid.(*Node).items, expected)
	}
	kids, err = next.Children(sup, dt)
	t.Nil(err)
	t.True(len(kids) == 1, "len(kids) %d != 1", len(kids))
	t.True(kids[0].(*Node).items.Equals(
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(2),
			types.Int32(3)})))
}
示例#2
0
func TestParents_123(x *testing.T) {
	t := assert.New(x)
	_, dt, sup := startingPoints(t)
	n123 := &Node{
		items: set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(2), types.Int32(3)}),
		txs:   []int32{1, 2, 3},
	}
	parents, err := n123.Parents(sup, dt)
	t.Nil(err, "%v", err)
	expected := set.FromSlice([]types.Hashable{
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(2)}),
		set.FromSlice([]types.Hashable{types.Int32(1), types.Int32(3)}),
		set.FromSlice([]types.Hashable{types.Int32(2), types.Int32(3)}),
	})
	for _, p := range parents {
		has := expected.Has(p.(*Node).items)
		t.True(has, "%v not in %v", p.(*Node).items, expected)
	}
}
示例#3
0
文件: loader.go 项目: timtadh/sfp
func (l *IntLoader) startingPoints(items itemsIter) ([]lattice.Node, error) {
	idx, inv, err := l.indices(items)
	if err != nil {
		return nil, err
	}
	l.sets.Index = idx
	l.sets.InvertedIndex = inv
	nodes := make([]lattice.Node, 0, 10)
	for item, txs := range inv {
		if len(txs) >= l.sets.Support() {
			errors.Logf("INFO", "item %d len(txs) %d", item, len(txs))
			n := &Node{
				pat: Pattern{set.FromSlice([]types.Hashable{types.Int32(item)})},
				dt:  l.sets,
				txs: txs,
			}
			nodes = append(nodes, n)
		}
	}
	return nodes, nil
}
func makeSet() *set.SortedSet {
	return set.FromSlice([]types.Hashable{types.Int(1), types.Int(-1), types.Int(3)})
}