Skip to content

Commit

Permalink
Added edges function.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrupp committed Mar 18, 2013
1 parent 9f313c1 commit 75c7a68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/graffy/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(add-node [this n])
(add-edge [this s d])
(nodes [this])
(edges [this n])
(neighbors [this n]))

(defn make-graph []
Expand All @@ -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)
#{}))
Expand Down
10 changes: 10 additions & 0 deletions test/graffy/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))))

0 comments on commit 75c7a68

Please sign in to comment.