Skip to content

Commit

Permalink
add graph topology test
Browse files Browse the repository at this point in the history
  • Loading branch information
email2liyang committed Jan 30, 2019
1 parent a5f9749 commit efeef70
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scala/src/test/scala/ch43_topology_sort/GraphTopologyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,23 @@ class GraphTopologyTest extends FlatSpec with Matchers {
val seq = graphTopology.topologySortByKahn()
seq.map(nodes(_)).mkString(",") should equal("a,b,d,e,c")
}

/*
a -> d <- b
| /|\
\|/ |
e -> c
*/
it should "topologySortByKahn - 3" in {
val nodes = Array("a", "b", "c", "d", "e")
val graphTopology = new GraphTopology(nodes.length)
graphTopology.addEdge(0, 3)
graphTopology.addEdge(3, 4)
graphTopology.addEdge(4, 2)
graphTopology.addEdge(2, 1)
graphTopology.addEdge(1, 3)

val seq = graphTopology.topologySortByKahn()
seq.map(nodes(_)).mkString(",") should equal("a")
}
}

0 comments on commit efeef70

Please sign in to comment.