Any time you're using gen, you will also need to include the (optional) 
library org.clojure/test.check "0.9.0".

On Sunday, November 5, 2017 at 9:19:22 PM UTC-6, Melk Thor wrote:
>
> Hi.
> I am trying to implement a spec for finite numbers, but I am getting 
> ExceptionInfo Unable to construct gen.
> This is my approach:
>
> (ns myns
> (:require
>           [clojure.spec.alpha :as spec]
>           [clojure.spec.gen.alpha :as gen]
>           [clojure.spec.test.alpha :as stest]
>           [incanter.core :refer [save-div]]
>          ))
>
> (defn is-finite?
>   [num]
>   (Double/isFinite num))
>
> (spec/def ::finite-num is-finite?)
>
> (defn finite-div
>   [a b]
>   (safe-div a b))
>
> (spec/fdef finite-div
>   :args (spec/cat :a ::finite-num :b ::finite-num)
>   :ret number?)
>
> -----------------
>
> when I check for ::finite-num spec  validation, it works:
>
> (spec/valid? ::finite-num 3)
> => true
>
> (spec/valid? ::finite-num Double/POSITIVE_INFINITY)
> => false
>
> (spec/valid? ::finite-num Double/NEGATIVE_INFINITY)
> => false
>
> So far so good. But when I want to check it:
>
> (stest/check `finite-div)
> =>
> ({:spec #object[clojure.spec.alpha$fspec_impl$reify__1355
>                 0x190f4a67
>                 "clojure.spec.alpha$fspec_impl$reify__1355@190f4a67"],
>   :clojure.spec.test.check/ret {:result #error{:cause "Unable to construct 
> gen at: [:a] for: :myns/finite-num",
>                                                :data 
> #:clojure.spec.alpha{:path [:a],
>                                                                           
> :form :myns/finite-num,
>                                                                           
> :failure :no-gen},
>                                                :via [{:type 
> clojure.lang.ExceptionInfo,
>                                                       :message "Unable to 
> construct gen at: [:a] for: :myns/finite-num",
>                                                       :data 
> #:clojure.spec.alpha{:path [:a],
>                                                                           
>        :form :myns/finite-num,
>                                                                           
>        :failure :no-gen},
>                                                       :at 
> [clojure.core$ex_info invokeStatic "core.clj" 4725]}],
>                                                :trace 
> [[clojure.core$ex_info invokeStatic "core.clj" 4725]
>                                                       
>  [clojure.core$ex_info invoke "core.clj" 4725]
>                                                       
>  [clojure.spec.alpha$gensub invokeStatic "alpha.clj" 272]
>                                                       
>  [clojure.spec.alpha$gensub invoke "alpha.clj" 262]
>                                                       
>  [clojure.spec.alpha$re_gen invokeStatic "alpha.clj" 1586]
>                                                       
>  [clojure.spec.alpha$re_gen invoke "alpha.clj" 1560]
>                                                       
>  [clojure.spec.alpha$re_gen$ggens__1296$gen__1297
>                                                         invoke
>                                                         "alpha.clj"
>                                                         1571]
>                                                       
>  [clojure.core$map$fn__6873 invoke "core.clj" 2739]
>                                                       
>  [clojure.lang.LazySeq sval "LazySeq.java" 40]
>                                                       
>  [clojure.lang.LazySeq seq "LazySeq.java" 49]
>                                                        [clojure.lang.RT 
> seq "RT.java" 525]
>                                                       
>  [clojure.core$seq__6407 invokeStatic "core.clj" 137]
>                                                       
>  [clojure.core$every_QMARK_ invokeStatic "core.clj" 2652]
>                                                       
>  [clojure.core$every_QMARK_ invoke "core.clj" 2645]
>                                                       
>  [clojure.spec.alpha$re_gen invokeStatic "alpha.clj" 1590]
>                                                       
>  [clojure.spec.alpha$re_gen invoke "alpha.clj" 1560]
>                                                       
>  [clojure.spec.alpha$regex_spec_impl$reify__1340
>                                                         gen_STAR_
>                                                         "alpha.clj"
>                                                         1661]
>                                                       
>  [clojure.spec.alpha$gensub invokeStatic "alpha.clj" 269]
>                                                       
>  [clojure.spec.alpha$gensub invoke "alpha.clj" 262]
>                                                       
>  [clojure.spec.alpha$gen invokeStatic "alpha.clj" 286]
>                                                       
>  [clojure.spec.alpha$gen invoke "alpha.clj" 275]
>                                                       
>  [clojure.spec.test.alpha$quick_check$fn__2427
>                                                         invoke
>                                                         "alpha.clj"
>                                                         305]
>                                                       
>  [clojure.spec.test.alpha$quick_check
>                                                         invokeStatic
>                                                         "alpha.clj"
>                                                         305]
>                                                       
>  [clojure.spec.test.alpha$quick_check invoke "alpha.clj" 302]
>                                                       
>  [clojure.spec.test.alpha$check_1 invokeStatic "alpha.clj" 335]
>                                                       
>  [clojure.spec.test.alpha$check_1 invoke "alpha.clj" 323]
>                                                       
>  [clojure.spec.test.alpha$check$fn__2448 invoke "alpha.clj" 411]
>                                                       
>  [clojure.core$pmap$fn__9370$fn__9371 invoke "core.clj" 6897]
>                                                       
>  [clojure.core$binding_conveyor_fn$fn__6757
>                                                         invoke
>                                                         "core.clj"
>                                                         2020]
>                                                        [clojure.lang.AFn 
> call "AFn.java" 18]
>                                                       
>  [java.util.concurrent.FutureTask run "FutureTask.java" 266]
>                                                       
>  [java.util.concurrent.ThreadPoolExecutor
>                                                         runWorker
>                                                         
> "ThreadPoolExecutor.java"
>                                                         1149]
>                                                       
>  [java.util.concurrent.ThreadPoolExecutor$Worker
>                                                         run
>                                                         
> "ThreadPoolExecutor.java"
>                                                         624]
>                                                        [java.lang.Thread 
> run "Thread.java" 748]]}},
>   :sym myns/finite-div,
>   :failure #error{:cause "Unable to construct gen at: [:a] for: 
> :myns/finite-num",
>                   :data #:clojure.spec.alpha{:path [:a], :form 
> :myns/finite-num, :failure :no-gen},
>                   :via [{:type clojure.lang.ExceptionInfo,
>                          :message "Unable to construct gen at: [:a] for: 
> :myns/finite-num",
>                          :data #:clojure.spec.alpha{:path [:a], :form 
> :myns/finite-num, :failure :no-gen},
>                          :at [clojure.core$ex_info invokeStatic "core.clj" 
> 4725]}],
>                   :trace [[clojure.core$ex_info invokeStatic "core.clj" 
> 4725]
>                           [clojure.core$ex_info invoke "core.clj" 4725]
>                           [clojure.spec.alpha$gensub invokeStatic 
> "alpha.clj" 272]
>                           [clojure.spec.alpha$gensub invoke "alpha.clj" 
> 262]
>                           [clojure.spec.alpha$re_gen invokeStatic 
> "alpha.clj" 1586]
>                           [clojure.spec.alpha$re_gen invoke "alpha.clj" 
> 1560]
>                           [clojure.spec.alpha$re_gen$ggens__1296$gen__1297 
> invoke "alpha.clj" 1571]
>                           [clojure.core$map$fn__6873 invoke "core.clj" 
> 2739]
>                           [clojure.lang.LazySeq sval "LazySeq.java" 40]
>                           [clojure.lang.LazySeq seq "LazySeq.java" 49]
>                           [clojure.lang.RT seq "RT.java" 525]
>                           [clojure.core$seq__6407 invokeStatic "core.clj" 
> 137]
>                           [clojure.core$every_QMARK_ invokeStatic 
> "core.clj" 2652]
>                           [clojure.core$every_QMARK_ invoke "core.clj" 
> 2645]
>                           [clojure.spec.alpha$re_gen invokeStatic 
> "alpha.clj" 1590]
>                           [clojure.spec.alpha$re_gen invoke "alpha.clj" 
> 1560]
>                           [clojure.spec.alpha$regex_spec_impl$reify__1340 
> gen_STAR_ "alpha.clj" 1661]
>                           [clojure.spec.alpha$gensub invokeStatic 
> "alpha.clj" 269]
>                           [clojure.spec.alpha$gensub invoke "alpha.clj" 
> 262]
>                           [clojure.spec.alpha$gen invokeStatic "alpha.clj" 
> 286]
>                           [clojure.spec.alpha$gen invoke "alpha.clj" 275]
>                           [clojure.spec.test.alpha$quick_check$fn__2427 
> invoke "alpha.clj" 305]
>                           [clojure.spec.test.alpha$quick_check 
> invokeStatic "alpha.clj" 305]
>                           [clojure.spec.test.alpha$quick_check invoke 
> "alpha.clj" 302]
>                           [clojure.spec.test.alpha$check_1 invokeStatic 
> "alpha.clj" 335]
>                           [clojure.spec.test.alpha$check_1 invoke 
> "alpha.clj" 323]
>                           [clojure.spec.test.alpha$check$fn__2448 invoke 
> "alpha.clj" 411]
>                           [clojure.core$pmap$fn__9370$fn__9371 invoke 
> "core.clj" 6897]
>                           [clojure.core$binding_conveyor_fn$fn__6757 
> invoke "core.clj" 2020]
>                           [clojure.lang.AFn call "AFn.java" 18]
>                           [java.util.concurrent.FutureTask run 
> "FutureTask.java" 266]
>                           [java.util.concurrent.ThreadPoolExecutor 
> runWorker "ThreadPoolExecutor.java" 1149]
>                           [java.util.concurrent.ThreadPoolExecutor$Worker 
> run "ThreadPoolExecutor.java" 624]
>                           [java.lang.Thread run "Thread.java" 748]]}})
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to