Skip to content

Commit

Permalink
connections changed from keyword to map
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkaspa committed Mar 7, 2016
1 parent 7a8abd7 commit c7e7c89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/exstreme/stream_graph.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Exstreme.StreamGraph do
@moduledoc """
"""
defmodule Graph do
defstruct params: [], nodes: %{}, connections: []
defstruct params: [], nodes: %{}, connections: %{}
end

@doc """
Expand Down Expand Up @@ -49,7 +49,7 @@ defmodule Exstreme.StreamGraph do
defp store_connection_fn(start, finish) do
fn(connections) ->
add_connection = fn(keywords, start, finish) ->
Keyword.update(keywords, start, finish, fn(value)->
Map.update(keywords, start, finish, fn(value)->
if is_list(value) do
[finish | value]
else
Expand Down Expand Up @@ -107,7 +107,7 @@ defmodule Exstreme.StreamGraph do
defp validate_position_start(connections, node, msg) do
exist =
connections
|> Keyword.has_key?(node)
|> Map.has_key?(node)
if exist do
raise ArgumentError, message: msg
else
Expand All @@ -118,7 +118,7 @@ defmodule Exstreme.StreamGraph do
defp validate_position_end(connections, node, msg) do
exist =
connections
|> Keyword.values
|> Map.values
|> Enum.member?(node)
if exist do
raise ArgumentError, message: msg
Expand Down
8 changes: 4 additions & 4 deletions test/exstreme/stream_graph_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Exstreme.StreamGraphTest do
test "creates a valid graph struct" do
compare_graph = %Graph{
nodes: %{n1: [], n2: []},
connections: [{:n1, :n2}]
connections: %{n1: :n2}
}
assert create_graph == compare_graph
end
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule Exstreme.StreamGraphTest do
test "can create n3 and add a relation between n2 and n3" do
compare_graph = %Graph{
nodes: %{n1: [], n2: [], n3: []},
connections: [{:n1, :n2}, {:n2, :n3}]
connections: %{n1: :n2, n2: :n3}
}

new_graph =
Expand All @@ -62,7 +62,7 @@ defmodule Exstreme.StreamGraphTest do
test "can add a broadcast an many nodes to the broadcast" do
compare_graph = %Graph{
nodes: %{n1: [], n2: [], b1: [], n3: [], n4: []},
connections: [{:n1, :n2}, {:n2, :b1}, {:b1, [:n4, :n3]}]
connections: %{n1: :n2, n2: :b1, b1: [:n4, :n3]}
}

new_graph =
Expand All @@ -83,7 +83,7 @@ defmodule Exstreme.StreamGraphTest do
test "can add a funnel" do
compare_graph = %Graph{
nodes: %{n1: [], n2: [], b1: [], n3: [], n4: [], f1: [], n5: []},
connections: [{:n1, :n2}, {:n2, :b1}, {:b1, [:n4, :n3]}, {:n3, :f1}, {:n4, :f1}, {:f1, :n5}]
connections: %{n1: :n2, n2: :b1, b1: [:n4, :n3], n3: :f1, n4: :f1, f1: :n5}
}

new_graph =
Expand Down

0 comments on commit c7e7c89

Please sign in to comment.