Im trying to experiment with test.check and Clojure, however im not an expert in either, or math. However it is my understanding that the following code and test should always succeed. Can someone help to clarify if it is my math understanding or my impl that is wrong.
(defn minmax-norm
[xs]
(let [min (apply min xs)
max (apply max xs)]
(map (fn [x] (/ (- x min) (+ (- max min) (math/pow 10 -100)))) xs)))
(defn euclidean-distance
[fr fc]
(->> (minmax-norm fc)
(map - (minmax-norm fr))
(map #(math/pow % 2))
(reduce +)
math/sqrt))
(defspec preference-fn
(prop/for-all [[xs ys] (gen/bind (gen/such-that pos? gen/nat) (fn [x]
(gen/tuple
(gen/not-empty (gen/vector gen/large-integer x))
(gen/not-empty (gen/vector gen/large-integer x)))))]
(let [s (sut/euclidean-distance xs ys)]
(t/testing "For any two non-empty vectors of equal length s is bounded between 0-2"
(and (<= 0 s) (>= 2 s))))))