aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/graph
diff options
context:
space:
mode:
authorchick2020-08-14 19:47:53 -0700
committerJack Koenig2020-08-14 19:47:53 -0700
commit6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch)
tree2ed103ee80b0fba613c88a66af854ae9952610ce /src/test/scala/firrtlTests/graph
parentb516293f703c4de86397862fee1897aded2ae140 (diff)
All of src/ formatted with scalafmt
Diffstat (limited to 'src/test/scala/firrtlTests/graph')
-rw-r--r--src/test/scala/firrtlTests/graph/DiGraphTests.scala140
-rw-r--r--src/test/scala/firrtlTests/graph/EulerTourTests.scala20
2 files changed, 80 insertions, 80 deletions
diff --git a/src/test/scala/firrtlTests/graph/DiGraphTests.scala b/src/test/scala/firrtlTests/graph/DiGraphTests.scala
index 0f8c7193..0f5cf09c 100644
--- a/src/test/scala/firrtlTests/graph/DiGraphTests.scala
+++ b/src/test/scala/firrtlTests/graph/DiGraphTests.scala
@@ -7,32 +7,24 @@ import firrtl.testutils._
class DiGraphTests extends FirrtlFlatSpec {
- val acyclicGraph = DiGraph(Map(
- "a" -> Set("b","c"),
- "b" -> Set("d"),
- "c" -> Set("d"),
- "d" -> Set("e"),
- "e" -> Set.empty[String]))
-
- val reversedAcyclicGraph = DiGraph(Map(
- "a" -> Set.empty[String],
- "b" -> Set("a"),
- "c" -> Set("a"),
- "d" -> Set("b", "c"),
- "e" -> Set("d")))
-
- val cyclicGraph = DiGraph(Map(
- "a" -> Set("b","c"),
- "b" -> Set("d"),
- "c" -> Set("d"),
- "d" -> Set("a")))
-
- val tupleGraph = DiGraph(Map(
- ("a", 0) -> Set(("b", 2)),
- ("a", 1) -> Set(("c", 3)),
- ("b", 2) -> Set.empty[(String, Int)],
- ("c", 3) -> Set.empty[(String, Int)]
- ))
+ val acyclicGraph = DiGraph(
+ Map("a" -> Set("b", "c"), "b" -> Set("d"), "c" -> Set("d"), "d" -> Set("e"), "e" -> Set.empty[String])
+ )
+
+ val reversedAcyclicGraph = DiGraph(
+ Map("a" -> Set.empty[String], "b" -> Set("a"), "c" -> Set("a"), "d" -> Set("b", "c"), "e" -> Set("d"))
+ )
+
+ val cyclicGraph = DiGraph(Map("a" -> Set("b", "c"), "b" -> Set("d"), "c" -> Set("d"), "d" -> Set("a")))
+
+ val tupleGraph = DiGraph(
+ Map(
+ ("a", 0) -> Set(("b", 2)),
+ ("a", 1) -> Set(("c", 3)),
+ ("b", 2) -> Set.empty[(String, Int)],
+ ("c", 3) -> Set.empty[(String, Int)]
+ )
+ )
val degenerateGraph = DiGraph(Map("a" -> Set.empty[String]))
@@ -45,109 +37,113 @@ class DiGraphTests extends FirrtlFlatSpec {
}
"Asking a DiGraph for a path that exists" should "work" in {
- acyclicGraph.path("a","e") should not be empty
+ acyclicGraph.path("a", "e") should not be empty
}
"Asking a DiGraph for a path from one node to another with no path" should "error" in {
- an [PathNotFoundException] should be thrownBy acyclicGraph.path("e","a")
+ an[PathNotFoundException] should be thrownBy acyclicGraph.path("e", "a")
}
"The first element in a linearized graph with a single root node" should "be the root" in {
- acyclicGraph.linearize.head should equal ("a")
+ acyclicGraph.linearize.head should equal("a")
}
"A DiGraph with a cycle" should "error when linearized" in {
- a [CyclicException] should be thrownBy cyclicGraph.linearize
+ a[CyclicException] should be thrownBy cyclicGraph.linearize
}
"CyclicExceptions" should "contain information about the cycle" in {
- val c = the [CyclicException] thrownBy {
+ val c = the[CyclicException] thrownBy {
cyclicGraph.linearize
}
- c.getMessage.contains("found at a") should be (true)
- c.node.asInstanceOf[String] should be ("a")
+ c.getMessage.contains("found at a") should be(true)
+ c.node.asInstanceOf[String] should be("a")
}
"Reversing a graph" should "reverse all of the edges" in {
- acyclicGraph.reverse.getEdgeMap should equal (reversedAcyclicGraph.getEdgeMap)
+ acyclicGraph.reverse.getEdgeMap should equal(reversedAcyclicGraph.getEdgeMap)
}
"Reversing a graph with no edges" should "equal the graph itself" in {
- degenerateGraph.getEdgeMap should equal (degenerateGraph.reverse.getEdgeMap)
+ degenerateGraph.getEdgeMap should equal(degenerateGraph.reverse.getEdgeMap)
}
"transformNodes" should "combine vertices that collide, not drop them" in {
- tupleGraph.transformNodes(_._1).getEdgeMap should contain ("a" -> Set("b", "c"))
+ tupleGraph.transformNodes(_._1).getEdgeMap should contain("a" -> Set("b", "c"))
}
"Graph summation" should "be order-wise equivalent to original" in {
val first = acyclicGraph.subgraph(Set("a", "b", "c"))
val second = acyclicGraph.subgraph(Set("b", "c", "d", "e"))
- (first + second).getEdgeMap should equal (acyclicGraph.getEdgeMap)
+ (first + second).getEdgeMap should equal(acyclicGraph.getEdgeMap)
}
it should "be idempotent" in {
val first = acyclicGraph.subgraph(Set("a", "b", "c"))
val second = acyclicGraph.subgraph(Set("b", "c", "d", "e"))
- (first + second + second + second).getEdgeMap should equal (acyclicGraph.getEdgeMap)
+ (first + second + second + second).getEdgeMap should equal(acyclicGraph.getEdgeMap)
}
"linearize" should "not cause a stack overflow on very large graphs" in {
// Graph of 0 -> 1, 1 -> 2, etc.
val N = 10000
- val edges = (1 to N).zipWithIndex.map({ case (n, idx) => idx -> Set(n)}).toMap
+ val edges = (1 to N).zipWithIndex.map({ case (n, idx) => idx -> Set(n) }).toMap
val bigGraph = DiGraph(edges + (N -> Set.empty[Int]))
- bigGraph.linearize should be (0 to N)
+ bigGraph.linearize should be(0 to N)
}
it should "work on multi-rooted graphs" in {
val graph = DiGraph(Map("a" -> Set[String](), "b" -> Set[String]()))
- graph.linearize.toSet should be (graph.getVertices)
+ 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 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)
+ 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 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)
+ 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)
}
"reachableFrom" should "omit the queried node if no self-path exists" in {
diff --git a/src/test/scala/firrtlTests/graph/EulerTourTests.scala b/src/test/scala/firrtlTests/graph/EulerTourTests.scala
index f6deb721..703235af 100644
--- a/src/test/scala/firrtlTests/graph/EulerTourTests.scala
+++ b/src/test/scala/firrtlTests/graph/EulerTourTests.scala
@@ -11,26 +11,30 @@ class EulerTourTests extends FirrtlFlatSpec {
val third_layer = Set("3a", "3b", "3c")
val last_null = Set.empty[String]
- val m = Map(top -> first_layer) ++ first_layer.map{
- case x => Map(x -> second_layer) }.flatten.toMap ++ second_layer.map{
- case x => Map(x -> third_layer) }.flatten.toMap ++ third_layer.map{
- case x => Map(x -> last_null) }.flatten.toMap
+ val m = Map(top -> first_layer) ++ first_layer.map {
+ case x => Map(x -> second_layer)
+ }.flatten.toMap ++ second_layer.map {
+ case x => Map(x -> third_layer)
+ }.flatten.toMap ++ third_layer.map {
+ case x => Map(x -> last_null)
+ }.flatten.toMap
val graph = DiGraph(m)
val instances = graph.pathsInDAG(top).values.flatten
val tour = EulerTour(graph, top)
it should "show equivalency of Berkman--Vishkin and naive RMQs" in {
- instances.toSeq.combinations(2).toList.map { case Seq(a, b) =>
- tour.rmqNaive(a, b) should be (tour.rmqBV(a, b))
+ instances.toSeq.combinations(2).toList.map {
+ case Seq(a, b) =>
+ tour.rmqNaive(a, b) should be(tour.rmqBV(a, b))
}
}
it should "determine naive RMQs of itself correctly" in {
- instances.toSeq.map { case a => tour.rmqNaive(a, a) should be (a) }
+ instances.toSeq.map { case a => tour.rmqNaive(a, a) should be(a) }
}
it should "determine Berkman--Vishkin RMQs of itself correctly" in {
- instances.toSeq.map { case a => tour.rmqNaive(a, a) should be (a) }
+ instances.toSeq.map { case a => tour.rmqNaive(a, a) should be(a) }
}
}