feat: try to add test for node merge

上级 842ac705
......@@ -152,23 +152,6 @@ func (fullGraph *FullGraph) ToDot(split string, include func(string) bool) *gogr
return graph
}
type GraphNode struct {
text string
children []*GraphNode
}
func (fullGraph *FullGraph) BuildMapTree(split string, include func(key string) bool) *GraphNode {
graphNode := &GraphNode{}
for nodeKey := range fullGraph.NodeList {
tmp := strings.Split(nodeKey, split)
graphNode.text = tmp[0]
graphNode = buildNode(tmp[1:], graphNode)
}
return graphNode
}
func (fullGraph *FullGraph) ToMapDot(node *GraphNode) *gographviz.Graph {
graph := gographviz.NewGraph()
_ = graph.SetName("G")
......@@ -211,6 +194,23 @@ func (fullGraph *FullGraph) buildGraphNode(subgraph string, current *GraphNode,
}
}
type GraphNode struct {
text string
children []*GraphNode
}
func (fullGraph *FullGraph) BuildMapTree(split string, include func(key string) bool) *GraphNode {
graphNode := &GraphNode{}
for nodeKey := range fullGraph.NodeList {
tmp := strings.Split(nodeKey, split)
graphNode.text = tmp[0]
graphNode = buildNode(tmp[1:], graphNode)
}
return graphNode
}
func buildNode(arr []string, node *GraphNode) *GraphNode {
if node.text == arr[0] {
return node
......
......@@ -6,6 +6,13 @@ import (
)
func createBasicMap() (*GraphNode, *FullGraph) {
fullGraph, nodeFilter := createGraph()
node := fullGraph.BuildMapTree(".", nodeFilter)
return node, fullGraph
}
func createGraph() (*FullGraph, func(key string) bool) {
fullGraph := &FullGraph{
NodeList: make(map[string]string),
RelationList: make(map[string]*Relation),
......@@ -26,9 +33,7 @@ func createBasicMap() (*GraphNode, *FullGraph) {
var nodeFilter = func(key string) bool {
return true
}
node := fullGraph.BuildMapTree(".", nodeFilter)
return node, fullGraph
return fullGraph, nodeFilter
}
func Test_BuildGraphNode(t *testing.T) {
......@@ -38,8 +43,17 @@ func Test_BuildGraphNode(t *testing.T) {
g.Expect(node.text).To(Equal("com"))
children := node.children
g.Expect(len(children)).To(Equal(2))
//g.Expect(children[0].text).To(Equal("phodal"))
//g.Expect(children[1].text).To(Equal("spring"))
}
func Test_ShouldMergeSameMap(t *testing.T) {
g := NewGomegaWithT(t)
fullGraph, nodeFilter := createGraph()
fullGraph.NodeList["com.phodal.coca"] = "com.phodal.coca"
node := fullGraph.BuildMapTree(".", nodeFilter)
g.Expect(node.text).To(Equal("com"))
children := node.children
g.Expect(len(children)).To(Equal(3))
}
func Test_BuildNodeDot(t *testing.T) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册