Skip to content

Commit 416f99e

Browse files
committed
pass properties through add_edge of struct
1 parent 5aaabff commit 416f99e

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

lib/graph.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,14 @@ defmodule Graph do
11391139
[%Graph.Edge{v1: :a, v2: :b}]
11401140
"""
11411141
@spec add_edge(t, Edge.t()) :: t
1142-
def add_edge(%__MODULE__{} = g, %Edge{v1: v1, v2: v2, label: label, weight: weight}) do
1143-
add_edge(g, v1, v2, label: label, weight: weight)
1142+
def add_edge(%__MODULE__{} = g, %Edge{
1143+
v1: v1,
1144+
v2: v2,
1145+
label: label,
1146+
weight: weight,
1147+
properties: properties
1148+
}) do
1149+
add_edge(g, v1, v2, label: label, weight: weight, properties: properties)
11441150
end
11451151

11461152
@doc """

test/graph_test.exs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,30 @@ defmodule GraphTest do
156156
assert Map.has_key?(g.edge_index[:baz], g.vertex_identifier.(:a))
157157
end
158158

159-
test "traversal using indexed keys" do
160-
end
159+
# test "BFS traversal using multigraph partitions" do
160+
# graph =
161+
# Graph.new(multigraph: true)
162+
# |> Graph.add_edges([
163+
# {:a, :b, label: :foo},
164+
# {:a, :b, label: :bar},
165+
# {:b, :c, weight: 3},
166+
# {:b, :a, label: {:complex, :label}}
167+
# ])
168+
169+
# assert Graph.bfs(graph, :a) == [:a, :b, :c]
170+
# end
171+
172+
# test "DFS traversal using multigraph partitions" do
173+
# end
174+
175+
# test "Dijkstra traversal using multigraph partitions" do
176+
# end
177+
178+
# test "A* traversal using multigraph partitions" do
179+
# end
180+
181+
# test "Bellman-Ford traversal using multigraph partitions" do
182+
# end
161183
end
162184

163185
describe "edge properties" do
@@ -190,6 +212,19 @@ defmodule GraphTest do
190212
%Edge{v1: :a, v2: :b, label: :foo, properties: %{potato: :ham}}
191213
] = Graph.out_edges(g, :a)
192214
end
215+
216+
test "adding edge struct with properties" do
217+
g =
218+
Graph.new()
219+
220+
edge = Edge.new(:a, :b, properties: %{foo: :bar})
221+
222+
g = Graph.add_edge(g, edge)
223+
224+
assert [
225+
%Edge{v1: :a, v2: :b, properties: %{foo: :bar}}
226+
] = Graph.out_edges(g, :a)
227+
end
193228
end
194229

195230
test "delete vertex" do

0 commit comments

Comments
 (0)