-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathdirected_test.exs
More file actions
36 lines (30 loc) · 1 KB
/
directed_test.exs
File metadata and controls
36 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
defmodule DirectedTest do
use ExUnit.Case, async: true
describe "reachable/2" do
test "returns empty list for empty graph" do
assert Graph.new() |> Graph.reachable([]) == []
end
test "returns starting vertex if no edges" do
graph = Graph.new() |> Graph.add_vertex(:a)
assert Graph.reachable(graph, [:a]) == [:a]
end
test "returns reachable vertices" do
graph =
Graph.new()
|> Graph.add_edge(:a, :b)
|> Graph.add_edge(:b, :c)
|> Graph.add_edge(:d, :e)
assert Graph.reachable(graph, [:a]) |> Enum.sort() == [:a, :b, :c]
assert Graph.reachable(graph, [:d]) |> Enum.sort() == [:d, :e]
assert Graph.reachable(graph, [:a, :d]) |> Enum.sort() == [:a, :b, :c, :d, :e]
end
test "handles cycles" do
graph =
Graph.new()
|> Graph.add_edge(:a, :b)
|> Graph.add_edge(:b, :c)
|> Graph.add_edge(:c, :a)
assert Graph.reachable(graph, [:a]) |> Enum.sort() == [:a, :b, :c]
end
end
end