From 846b08899fde9febc0142babdcca757e568d2344 Mon Sep 17 00:00:00 2001 From: mrkaspa Date: Sun, 13 Mar 2016 20:16:19 -0500 Subject: [PATCH] graph test added --- lib/exstreme/graph.ex | 3 ++- test/exstreme/graph_test.exs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/exstreme/graph.ex b/lib/exstreme/graph.ex index 889f1c7..48cec9c 100644 --- a/lib/exstreme/graph.ex +++ b/lib/exstreme/graph.ex @@ -20,7 +20,8 @@ defmodule Exstreme.Graph do @spec count_connections(t) :: non_neg_integer def count_connections(%Graph{connections: connections}) do connections - |> Map.keys + |> Map.values + |> List.flatten |> Enum.count end diff --git a/test/exstreme/graph_test.exs b/test/exstreme/graph_test.exs index 7b47a5d..0001ec5 100644 --- a/test/exstreme/graph_test.exs +++ b/test/exstreme/graph_test.exs @@ -4,4 +4,16 @@ defmodule Exstreme.GraphTest do alias Exstreme.Graph doctest Exstreme.Graph + test "graph with many nodes has 7 nodes and 7 connections" do + assert Graph.count_nodes(graph_many_nodes) == 7 + assert Graph.count_connections(graph_many_nodes) == 7 + end + + test "connection stats for graph with many nodes" do + assert Graph.connections_stats(graph_many_nodes) == %{begin: 1, connected: 5, end: 1} + end + + test "the start node is n1" do + assert Graph.find_start_node(graph_many_nodes) == [:n1] + end end