_Comment made by: alexmiller_
[Original description from ticket:]
I created a generator that did not conform to the spec (doh!). The generator contained the such-that predicate. When I tried creating a sample from the generator I got this error:
ExceptionInfo Couldn't satisfy such-that predicate after 100 tries. clojure.core/ex-info (core.clj:4725)
I assumed that it referred to my custom generator but that was a red herring because in fact spec must be using such-that to ensure that the generated value conforms to the spec, and it was this such-that that generated the failure, not the one in my custom generator.
Code (with the problem corrected but showing the such-that in my generator:
"Calculate the checkdigit see http://freagra.com/imthealth/mitNNC.html"
(let [x (->> (map #(Integer/parseInt (str %)) (take 9 n))
(map * (range 10 1 -1))
y (mod x 11)
c (- 11 y)]
(cond (== 10 c) nil
(== 11 c) 0
"Generates a valid NHS number"
(gen/fmap #(str (+ (* 10 %) (mod11-checkdigit (str %))))
(gen/such-that #(mod11-checkdigit (str %))
(gen/choose 100000000 999999999))))
"Returns true if passed a valid nhs number else returns false"
(and (string? n) (= 10 (count n)) (= (str (mod11-checkdigit n)) (str (last n)))))
(s/def ::nhs-number (s/with-gen nhs-number?
(fn  nhs-number-gen)))
It would be nicer if the error thrown due to the generated value being non-conformant with the spec stated this.