-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathundirected_test.ex
More file actions
73 lines (57 loc) · 1.77 KB
/
undirected_test.ex
File metadata and controls
73 lines (57 loc) · 1.77 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
defmodule Graph.UndirectedTest do
use ExUnit.Case, async: true
describe "Graph.reachable/2" do
test "reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :c}])
assert [:a, :b, :c] = Graph.reachable(g, [:c])
assert [:c, :b, :a] = Graph.reachable(g, [:a])
end
test "parts reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :c}, {:d, :e}])
assert [:d, :e] = Graph.reachable(g, [:e])
assert [:c, :a, :b] = Graph.reachable(g, [:b])
end
test "nothing reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :d}])
|> Graph.add_vertex(:c)
assert [:c] = Graph.reachable(g, [:c])
end
test "unknown vertex" do
g = Graph.new(type: :undirected)
assert [nil] = Graph.reachable(g, [:a])
end
end
describe "Graph.reachable_neighbours/2" do
test "reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :c}])
assert [:a, :b] = Graph.reachable_neighbors(g, [:c])
end
@tag :only
test "parts reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :c}, {:d, :e}, {:e, :f}])
assert [:d, :e] = Graph.reachable_neighbors(g, [:f])
assert [] = Graph.reachable_neighbors(g, [:b])
end
test "nothing reachable" do
g =
Graph.new(type: :undirected)
|> Graph.add_edges([{:a, :b}, {:b, :d}])
|> Graph.add_vertex(:c)
assert [] = Graph.reachable_neighbors(g, [:c])
end
test "unknown vertex" do
g = Graph.new(type: :undirected)
assert [] = Graph.reachable_neighbors(g, [:a])
end
end
end