Skip to content

Instantly share code, notes, and snippets.

@bdaniels
Created August 7, 2012 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdaniels/3287562 to your computer and use it in GitHub Desktop.
Save bdaniels/3287562 to your computer and use it in GitHub Desktop.
I thought that the first constraint on design would cause all to fail if null, but I'm getting results from the conde statement afterwards in my unit tests.
; Logic Code
(defn uri-path [design view search path]
(logic/!= nil design)
(logic/conde
[(logic/!= nil view) (logic/== ["_design" design "_view" view] path)]))
; Unit test
(test/deftest test-path
(test/is (= '()
(logic/run* [q] (db/uri-path nil "view" "search" q))))
(test/is (= '(["_design" "design" "_view" "view"])
(logic/run* [q] (db/uri-path "design" "view" nil q)))))
; Test results
; FAIL in (test-path) (db_test.clj:24)
; expected: (= (quote ()) (logic/run* [q] (db/uri-path nil "view" "search" q)))
; actual: (not (= () (["_design" nil "_view" "view"])))
; The solution
(defn uri-path [design view search path]
(logic/fresh [x]
(logic/== x design)
(logic/!= x nil)
(logic/conde
[(logic/!= nil view) (logic/== ["_design" x "_view" view] path)])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment