Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make real tests out of documentation comments in 'dependency'

  • Loading branch information...
commit b103afcebcdefd816bfbf63c56f018aa496c3847 1 parent b1a151f
@stuartsierra stuartsierra authored
View
61 src/main/clojure/clojure/tools/namespace/dependency.clj
@@ -139,64 +139,3 @@
(compare (get pos a Long/MAX_VALUE)
(get pos b Long/MAX_VALUE)))))
-(comment
- ;; example usage: building a graph like:
- ;;
- ;; :a
- ;; / |
- ;; :b |
- ;; \ |
- ;; :c
- ;; |
- ;; :d
- ;;
- (def g (-> (graph)
- (depend :b :a) ; "B depends on A"
- (depend :c :b) ; "C depends on B"
- (depend :c :a) ; "C depends on A"
- (depend :d :c))) ; "D depends on C"
-
- (transitive-dependencies g :d)
- ;;=> #{:a :c :b}
-
- (sort (topo-comparator g) [:d :a :b :foo])
- ;;=> (:a :b :d :foo)
-
- ;; 'one 'five
- ;; | |
- ;; 'two |
- ;; / \ |
- ;; / \ |
- ;; / \ /
- ;; 'three 'four
- ;; | /
- ;; 'six /
- ;; | /
- ;; | /
- ;; | /
- ;; 'seven
- ;;
- (def g2 (-> (graph)
- (depend 'two 'one)
- (depend 'three 'two)
- (depend 'four 'two)
- (depend 'four 'five)
- (depend 'six 'three)
- (depend 'seven 'six)
- (depend 'seven 'four)))
-
- (transitive-dependencies g2 'seven)
- ;;=> #{two four six one five three}
-
- (transitive-dependents g2 'five)
- ;;=> #{four seven}
-
- (transitive-dependents g2 'two)
- ;;=> #{four seven six three}
-
- (topo-sort g2)
- ;;=> (one two three five six four seven)
-
- (sort (topo-comparator g2) '[three seven nine eight five])
- ;;=> (three five seven nine eight)
-)
View
64 src/test/clojure/clojure/tools/namespace/dependency_test.clj
@@ -0,0 +1,64 @@
+(ns clojure.tools.namespace.dependency-test
+ (:use clojure.test
+ clojure.tools.namespace.dependency))
+
+;; building a graph like:
+;;
+;; :a
+;; / |
+;; :b |
+;; \ |
+;; :c
+;; |
+;; :d
+;;
+(def g1 (-> (graph)
+ (depend :b :a) ; "B depends on A"
+ (depend :c :b) ; "C depends on B"
+ (depend :c :a) ; "C depends on A"
+ (depend :d :c))) ; "D depends on C"
+
+;; 'one 'five
+;; | |
+;; 'two |
+;; / \ |
+;; / \ |
+;; / \ /
+;; 'three 'four
+;; | /
+;; 'six /
+;; | /
+;; | /
+;; | /
+;; 'seven
+;;
+(def g2 (-> (graph)
+ (depend 'two 'one)
+ (depend 'three 'two)
+ (depend 'four 'two)
+ (depend 'four 'five)
+ (depend 'six 'three)
+ (depend 'seven 'six)
+ (depend 'seven 'four)))
+
+(deftest t-transitive-dependencies
+ (is (= #{:a :c :b}
+ (transitive-dependencies g1 :d)))
+ (is (= '#{two four six one five three}
+ (transitive-dependencies g2 'seven))))
+
+(deftest t-transitive-dependents
+ (is (= '#{four seven}
+ (transitive-dependents g2 'five)))
+ (is (= '#{four seven six three}
+ (transitive-dependents g2 'two))))
+
+(deftest t-topo-comparator
+ (is (= '(:a :b :d :foo)
+ (sort (topo-comparator g1) [:d :a :b :foo])))
+ (is (= '(three five seven nine eight)
+ (sort (topo-comparator g2) '[three seven nine eight five]))))
+
+(deftest t-topo-sort
+ (is (= '(one two three five six four seven)
+ (topo-sort g2))))
Please sign in to comment.
Something went wrong with that request. Please try again.