diff options
| author | Chick Markley | 2019-02-26 16:07:33 -0800 |
|---|---|---|
| committer | mergify[bot] | 2019-02-27 00:07:33 +0000 |
| commit | aec54ed72d02932f8fdb3aa857e82a23507aecd2 (patch) | |
| tree | 82c3ed54187dda79aeecf7614d494295c67ca8eb /src/test | |
| parent | dbe404460fd3062d940f86a02df044b8cc4be0fd (diff) | |
Create a simple generic GraphViz renderer for DiGraph (#1034)
* Create a simple generic graphviz renderer for DiGraph
There are three basic kinds
- A simple default renderer
- A ranked renderer that places nodes in columns based on depth from sources
- A sub-graph render for graphs that contain a loop
- Renders just nodes that are part of first loop found
- Plus the neighbors of the loop
- Loop edges are shown in red.
* Create a simple generic graphviz renderer for DiGraph
- Moved the graph loop finder into DiGraph
- Fixed scala doc per Edward's comments
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/scala/firrtlTests/graph/DiGraphTests.scala | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/test/scala/firrtlTests/graph/DiGraphTests.scala b/src/test/scala/firrtlTests/graph/DiGraphTests.scala index 52ded253..d3553a23 100644 --- a/src/test/scala/firrtlTests/graph/DiGraphTests.scala +++ b/src/test/scala/firrtlTests/graph/DiGraphTests.scala @@ -2,13 +2,10 @@ package firrtlTests.graph -import java.io._ -import org.scalatest._ -import org.scalatest.prop._ -import org.scalatest.Matchers._ import firrtl.graph._ import firrtlTests._ +//scalastyle:off magic.number class DiGraphTests extends FirrtlFlatSpec { val acyclicGraph = DiGraph(Map( @@ -110,4 +107,47 @@ class DiGraphTests extends FirrtlFlatSpec { val graph = DiGraph(Map("a" -> Set[String](), "b" -> Set[String]())) graph.linearize.toSet should be (graph.getVertices) } + + "acyclic graph" should "be rendered" in { + val acyclicGraph2 = DiGraph(Map( + "a" -> Set("b","c"), + "b" -> Set("d", "x", "z"), + "c" -> Set("d", "x"), + "d" -> Set("e", "k", "l"), + "x" -> Set("e"), + "z" -> Set("e", "j"), + "j" -> Set("k", "l", "c"), + "k" -> Set("l"), + "l" -> Set("e"), + "e" -> Set.empty[String] + )) + val render = new RenderDiGraph(acyclicGraph2) + val dotLines = render.toDotRanked.split("\n") + + dotLines.count(s => s.contains("rank=same")) should be (4) + dotLines.exists(s => s.contains(""""b" -> { "d" "x" "z" };""")) should be (true) + dotLines.exists(s => s.contains("""rankdir="LR";""")) should be (true) + } + + "subgraphs containing cycles" should "be rendered with loop edges in red, can override orientation" in { + val cyclicGraph2 = DiGraph(Map( + "a" -> Set("b","c"), + "b" -> Set("d", "x", "z"), + "c" -> Set("d", "x"), + "d" -> Set("e", "k", "l"), + "x" -> Set("e"), + "z" -> Set("e", "j"), + "j" -> Set("k", "l", "c"), + "k" -> Set("l"), + "l" -> Set("e"), + "e" -> Set("c") + )) + val render = new RenderDiGraph(cyclicGraph2, rankDir = "TB") + val dotLines = render.showOnlyTheLoopAsDot.split("\n") + + dotLines.count(s => s.contains("rank=same")) should be (4) + dotLines.count(s => s.contains("""[color=red,penwidth=3.0];""")) should be (3) + dotLines.exists(s => s.contains(""""d" -> "k";""")) should be (true) + dotLines.exists(s => s.contains("""rankdir="TB";""")) should be (true) + } } |
