From 9b9742bdb82677a9e57948e6019142d2af7204e6 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sun, 19 Jul 2020 22:53:44 +0800 Subject: [PATCH] feat: try to add test for node merge --- pkg/application/arch/tequila/incl_viz.go | 34 +++++++++---------- pkg/application/arch/tequila/incl_viz_test.go | 24 ++++++++++--- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/pkg/application/arch/tequila/incl_viz.go b/pkg/application/arch/tequila/incl_viz.go index 49a3269..23cbf6e 100644 --- a/pkg/application/arch/tequila/incl_viz.go +++ b/pkg/application/arch/tequila/incl_viz.go @@ -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 diff --git a/pkg/application/arch/tequila/incl_viz_test.go b/pkg/application/arch/tequila/incl_viz_test.go index 06c27fc..a897f18 100644 --- a/pkg/application/arch/tequila/incl_viz_test.go +++ b/pkg/application/arch/tequila/incl_viz_test.go @@ -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) { -- GitLab