From 75c7a68a63bdb17b94e3d90beecfae25d2a1f615 Mon Sep 17 00:00:00 2001 From: David Rupp Date: Sun, 17 Mar 2013 17:27:43 -0700 Subject: [PATCH] Added edges function. --- src/graffy/core.clj | 4 ++++ test/graffy/core_test.clj | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/graffy/core.clj b/src/graffy/core.clj index 3ef937b..7ac5475 100644 --- a/src/graffy/core.clj +++ b/src/graffy/core.clj @@ -4,6 +4,7 @@ (add-node [this n]) (add-edge [this s d]) (nodes [this]) + (edges [this n]) (neighbors [this n])) (defn make-graph [] @@ -20,6 +21,9 @@ this) (nodes [this] (keys @state)) + (edges [this n] + (for [dest (neighbors this n)] + [n dest])) (neighbors [this n] (or (@state n) #{})) diff --git a/test/graffy/core_test.clj b/test/graffy/core_test.clj index d722043..5fc9dd1 100644 --- a/test/graffy/core_test.clj +++ b/test/graffy/core_test.clj @@ -16,3 +16,13 @@ (is (= #{:b} (into #{} (neighbors g :a)))) (is (= #{:a} (into #{} (neighbors g :b)))) (is (= #{} (into #{} (neighbors g :c))))))) + +(deftest test-edges + (testing "edges" + (let [g (make-graph)] + (-> g (add-edge :a :b) + (add-edge :a :c) + (add-edge :a :d) + (add-edge :b :d)) + (is (= #{[:a :b] [:a :c] [:a :d]} (into #{} (edges g :a)))) + (is (= #{[:d :a] [:d :b]} (into #{} (edges g :d)))))))