           size
           (+ s (* (- size s) slope)))))))
 
-(defn gen-distinct-names [n]
+(defn gen-distinct-names
+  "Generate a list of names which are non-empty after trimming, and
+  are distinct after trimming."
+  [n]
   (gen/such-that
-    #(= (count %) (count (set %)))
+    #(= (count %) (count (set (map s/trim %))))
     (gen-vector-of-size
-      (gen/such-that not-empty gen/string-ascii)
+      (gen/such-that #(not-empty (s/trim %)) gen/string-ascii)
       n)))
 
 (defn scale-gen

  (ct/testing "detect tsv matrix"
    (let [{file-type :file-type} (detector "test/cavm/test_inputs/matrix")]
      (ct/is (= file-type :cgdata.core/tsv)))))

(defn matrix2 [db]
  (ct/testing "tsv matrix from file"

  (:require [clojure.test.check.clojure-test :as tcct :refer [defspec]])
  (:require [clojure.test.check.properties :as prop]))

; 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)) *eps*))))
               true
               (map vector a b))))

(defn- nearly-equal-matrix [a b]
  (and (= (count a) (count 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)]]))

; The conditional is necessary to smoothly handle small numbers.
; 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."
