Skip to content

Instantly share code, notes, and snippets.

@lgrapenthin
Created August 5, 2013 15:10
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 lgrapenthin/6156677 to your computer and use it in GitHub Desktop.
Save lgrapenthin/6156677 to your computer and use it in GitHub Desktop.
Two possible datomic bugs for datomic user-group
(ns dt-bugs.core-test
(:require [clojure.test :refer :all]
[dt-bugs.core :refer :all]
[datomic.api :as d]))
(defn- new-conn
[]
(let [uri (str "datomic:mem://" (d/squuid))]
(d/delete-database uri)
(d/create-database uri)
(d/connect uri)))
;; ================= TEST 1 ======================
(defn- transact-schema-test-1
[conn]
(d/transact conn [{:db/id (d/tempid :db.part/db)
:db/ident :test1/id
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "A simple long."
:db.install/_attribute :db.part/db}]))
(defn- transact-data-test-1
[conn]
(let [tx (mapv #(vector :db/add (d/tempid :db.part/user) :test1/id %)
(range 10))]
(d/transact conn tx)))
(deftest test-1
(testing "Querying non-existing negative attribute values should not return
existing postive attribute values = (dec (- neg-v))"
(let [conn (doto (new-conn)
transact-schema-test-1
transact-data-test-1)
neg-v -6]
(is (not=
(d/q `[:find ?e
:where
[?e :test1/id ~neg-v]] (d/db conn))
(d/q `[:find ?e
:where
[?e :test1/id ~(dec (- neg-v))]] (d/db conn))))
(is (empty?
(d/q `[:find ?e
:where
[?e :test1/id ~neg-v]] (d/db conn)))))))
;; ================= TEST 2 ======================
(deftest test-2
(testing "Querying for the division of two-values should not return the result
of clojure.core/quot. Using clojure.tools.trace, I found that / is
resolved from datomic.extensions// where it is defined as
clojure.core/quot."
(is (not=
(-> (d/q '[:find ?r
:where [(/ 3 4) ?r]])
ffirst)
(clojure.core/quot 3 4)))
(is (not=
(-> (d/q `[:find ?r
:where [(/ 3 4) ?r]])
ffirst)
(clojure.core/quot 3 4))) ;; Passes because thanks to ` / is
;; resolved to clojure.core//
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment