   (:require [clojure.test.check.clojure-test :as tcct :refer [defspec]])
   (:require [clojure.test.check.properties :as prop]))
 
-(def eps 0.000001)
-
-(defn- nearly-equal [e a b]
+; XXX fix nearly-equal-matrix to also log failures
+(def ^:dynamic *verbose* false)
+
+(defmacro is= [a b]
+  `(let [a# ~a
+         b# ~b
+         r# (= a# b#)]
+    (when (and (not r#) *verbose*)
+      (println "expected (=" ~(str a) ~(str b) ")")
+      (print "actual (not (=")
+      (clojure.pprint/write a#)
+      (print " ")
+      (clojure.pprint/write b#)
+      (println "))"))
+     r#))
+
+(def ^:dynamic *eps* 0.0001)
+
+(defn- nearly-equal [a b]
   (and (= (count a) (count b))
        (reduce (fn [acc pair]
                  (or (let [[x y] pair]
                        (and
                          (Double/isNaN x)
                          (Double/isNaN y)))
-                     (and acc (< (java.lang.Math/abs (apply - pair)) e))))
+                     (and acc (< (java.lang.Math/abs (apply - pair)) *eps*))))
                true
                (map vector a b))))
 
-(defn- nearly-equal-matrix [e a b]
+(defn- nearly-equal-matrix [a b]
   (and (= (count a) (count b))
-       (every? (fn [[a1 b1]] (nearly-equal e a1 b1)) (map vector a b))))
+       (every? (fn [[a1 b1]] (nearly-equal a1 b1)) (map vector a b))))
 
 (def gen-mostly-ints
   (gen/frequency [[9 gen/int] [1 (gen/return Double/NaN)]]))
 
-; work-around for broken gen/vector, which will stack-overflow.
 ; The conditional is necessary to smoothly handle small numbers.
-; Otherwise we only do squares, like 1,4,9.
+; Otherwise we only do squares, like 1,4,9. Above the threshold we
+; are not perfectly accurate. This can't be avoided.
 (defn gen-vector-of-size
   "Generate vector of given size, working-around gen/vector
   stackoverflow problem."

                 {:name "probe5" :id 12 :dataset_id 1} ]))
      (let [[probe1 probe2]
            (vec (map #(into [] %) (map ((first data) :data) ["probe1" "probe2"])))]
        (ct/is (nearly-equal 0.0001 probe1 [2.1 1.1]))
        (ct/is (nearly-equal 0.0001 probe2 [2.2 1.2]))))))

(defn detect-cgdata-genomic [db]
  (ct/testing "detect cgdata genomic"

                 {:field_id 3 :row 1 :gene "BLAH"}]))
      (let [[probe1 probe2]
            (vec (map #(into [] %) (map ((first data) :data) ["probe1" "probe2"])))]
        (ct/is (nearly-equal probe1 [1.2 1.1]))
        (ct/is (nearly-equal probe2 [2.2 2.1])))
      (let [[probe1 probe2]
            (vec (map #(into [] %) (map ((first data2) :data) ["probe1" "probe2"])))]
        (ct/is (nearly-equal probe1 [1.1 Double/NaN]))
        (ct/is (nearly-equal probe2 [2.1 Double/NaN]))))))

(def docroot "test/cavm/test_inputs")

