Skip to content

Commit

Permalink
dfs 2
Browse files Browse the repository at this point in the history
  • Loading branch information
djnzx committed Jan 8, 2024
1 parent 7ac6e4d commit da1294b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion algorithms/src/main/scala/graphs/dfs/DfsImplSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DfsImplSpec extends AnyFunSuite with Matchers {
println(g)
}

test("dfs") {
test("dfs 1") {
val g = DiGraph(
1 -> 4,
1 -> 2,
Expand All @@ -98,4 +98,34 @@ class DfsImplSpec extends AnyFunSuite with Matchers {
)
}

test("dfs 2") {
val g = DiGraph(
1 -> 2,
1 -> 6,
1 -> 10,
2 -> 3,
2 -> 4,
6 -> 7,
6 -> 9,
3 -> 11,
4 -> 5,
5 -> 11,
7 -> 8,
9 -> 5,
8 -> 11,
10 -> 11
)
val dfs = new DFS(g)
val paths = dfs.traverse(1, 11)
paths.foreach(x => pprint.pprintln(x))

paths shouldEqual Set(
List(1, 2, 3, 11),
List(1, 2, 4, 5, 11),
List(1, 6, 7, 8, 11),
List(1, 6, 9, 5, 11),
List(1, 10, 11)
)
}

}

0 comments on commit da1294b

Please sign in to comment.