From da1294b6fc2ab32c69d64b94ab70b35bfc84d826 Mon Sep 17 00:00:00 2001 From: Alexey Rykhalskiy Date: Mon, 8 Jan 2024 16:37:19 +0200 Subject: [PATCH] dfs 2 --- .../main/scala/graphs/dfs/DfsImplSpec.scala | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/algorithms/src/main/scala/graphs/dfs/DfsImplSpec.scala b/algorithms/src/main/scala/graphs/dfs/DfsImplSpec.scala index 4874a6e4..7586cb60 100644 --- a/algorithms/src/main/scala/graphs/dfs/DfsImplSpec.scala +++ b/algorithms/src/main/scala/graphs/dfs/DfsImplSpec.scala @@ -73,7 +73,7 @@ class DfsImplSpec extends AnyFunSuite with Matchers { println(g) } - test("dfs") { + test("dfs 1") { val g = DiGraph( 1 -> 4, 1 -> 2, @@ -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) + ) + } + }