Codebase list test-check-clojure / 94ed7e3
Include generated-so-far when throwing for not-enough-distinct Gary Fredericks 8 years ago
2 changed file(s) with 12 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
550550 (throw (ex-info "Couldn't generate enough distinct elements!"
551551 {:gen gen
552552 :max-tries max-tries
553 :num-elements num-elements}))
553 :num-elements num-elements
554 :so-far (->> rose-trees
555 (persistent!)
556 (core/map rose/root))}))
554557
555558
556559 (or (= max-tries tries)
422422 (= 4 (count (distinct boolean-sets)))))
423423
424424 (deftest can't-generate-set-of-five-booleans
425 (is (thrown-with-msg? #?(:clj Exception :cljs js/Error)
426 #"Couldn't generate enough distinct elements"
427 (gen/generate (gen/set gen/boolean {:num-elements 5})))))
425 (let [ex (try
426 (gen/generate (gen/set gen/boolean {:num-elements 5}))
427 (is false)
428 (catch #?(:clj Exception :cljs js/Error) e
429 e))]
430 (is (re-find #"Couldn't generate enough distinct elements"
431 #? (:clj (.getMessage ^Exception ex) :cljs (.-message ex))))
432 (is (#{[true false] [false true]} (-> ex ex-data :so-far)))))
428433
429434 ;; Generating proper matrices
430435 ;; ---------------------------------------------------------------------------