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)))))))