Skip to content

Commit

Permalink
02/clj: add some basic graph unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjl committed Oct 13, 2011
1 parent b9ea77f commit ec5bcbb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions unit02/clojure/unit02/test/unit02/test/graphs.clj
@@ -0,0 +1,44 @@
(ns unit02.test.graphs
(:use [unit02.graphs])
(:use [clojure.test]))

(def graph-1
(make-graph [:buffalo :rochester :syracuse :binghamton :new-york-city]
{[:buffalo :rochester] 75
[:syracuse :rochester] 90
[:ithaca :rochester] 90
[:ithaca :binghamton] 50
[:ithaca :syracuse] 60
[:binghamton :syracuse] 75
[:binghamton :rochester] 141
[:binghamton :new-york-city] 176
[:syracuse :new-york-city] 247
[:albany :new-york-city] 150
[:albany :syracuse] 150}))

(deftest test-bf-paths
(is (= (:path (search-breadth graph-1 :buffalo :rochester))
[:buffalo :rochester])
"Bad path for breadth-first search.")

(is (= (:path (search-breadth graph-1 :buffalo :binghamton))
[:buffalo :rochester :binghamton])
"Bad path for breadth-first search.")

(is (= (:path (search-breadth graph-1 :buffalo :albany))
[:buffalo :rochester :syracuse :albany])
"Bad path for breadth-first search."))

(deftest test-df-paths
(is (#{[:buffalo :rochester]}
(:path (search-depth graph-1 :buffalo :rochester)))
"Bad path for depth-first search.")

(is (#{[:binghamton :ithaca]}
(:path (search-depth graph-1 :binghamton :ithaca)))
"Bad path for depth-first search.")

(is (#{[:buffalo :rochester :syracuse :albany]
[:buffalo :rochester :syracuse :new-york-city :albany]}
(:path (search-depth graph-1 :buffalo :albany)))
"Bad path for depth-first search."))

0 comments on commit ec5bcbb

Please sign in to comment.