Hi Gary,
Thanks for the feedback. I've tried it with test.check itself and I get
better results (see below). So I'm guessing clojure.spec needs different
input or it works differently underneath.
Thanks,
Jeroen
(require '[clojure.test.check :as tc])
(require '[clojure.test.check.generators :as gen])
(require '[clojure.test.check.properties :as prop])
(def gen-atom (gen/elements (mapcat (juxt (partial str "f_a")
(partial str "t_a")) (range 10))))
(def gen-atom (gen/elements (mapcat (juxt (partial str "f_a")
(partial str "t_a")) (range 10))))
(defn gen-cat
"Returns a generator of a sequence catenated from results of
gens, each of which should generate something sequential."
[& gens]
(gen/fmap #(vec (apply concat %))
(apply gen/tuple gens)))
(def compound (fn [inner-gen]
(gen/one-of [(gen-cat (gen/elements [[:not]]) (gen/tuple
inner-gen))
(gen-cat (gen/elements [[:or]]) (gen/tuple
inner-gen) (gen/not-empty (gen/list inner-gen)))
(gen-cat (gen/elements [[:and]]) (gen/tuple
inner-gen) (gen/not-empty (gen/list inner-gen)))])))
(def gen-predicate (gen/recursive-gen compound gen-atom))
([:or [:and [:or "t_a3" "f_a5"] [:and "t_a5" "t_a6"]] [:or [:not "t_a5"]
[:not "t_a1"]]] [:and [:and [:and "f_a4" "f_a4" "f_a9"] [:or "f_a2"
"t_a5"]] [:and [:not "f_a3"] [:not "f_a1"]]] [:or "t_a5" "f_a6" "t_a7"
"t_a3"] [:not [:and [:and [:not [:not "t_a5"]] [:and [:or "t_a4" "f_a7"]
[:not "t_a2"] [:not "f_a6"] [:and "t_a5" "t_a4"] [:or "t_a8" "f_a0"]] [:not
[:or "f_a8" "f_a2"]]] [:or [:or [:not "f_a0"] [:or "t_a9" "t_a7"]] [:not
[:or "t_a5" "f_a6" "f_a1"]]] [:not [:and [:and "t_a0" "t_a3"] [:or "f_a2"
"t_a5"]]]]] [:or [:not [:and [:or [:not "f_a1"] [:and "f_a0" "t_a8"]] [:not
[:not "t_a7"]] [:or [:or "f_a1" "f_a8" "f_a7"] [:and "f_a9" "t_a2"]]]]
[:not [:or [:or [:not "t_a7"] [:not "t_a8"]] [:or [:and "t_a3" "t_a0"]
[:not "t_a6"]]]] [:not [:and [:and [:and "f_a9" "t_a7"] [:and "f_a6"
"f_a9"] [:or "f_a9" "t_a0" "t_a8"]] [:and [:not "f_a4"] [:or "t_a3" "f_a4"]
[:or "t_a3" "f_a3"]]]]])
On Tue, May 31, 2016 at 3:14 AM, Gary Fredericks <[email protected]>
wrote:
> At a glance, this is probably the normal increasing-size behavior of
> test.check, and the bias should only be present for the first few samples.
> E.g., if you do a (take 1000 (gen/sample ...)), it should be more uniform.
>
> Whether it's a real problem depends on how you're running your tests. I
> haven't yet looked into whether clojure.spec provides some default way of
> running test.check properties, so I'm not sure about that. But as long as
> you're running "enough" tests, e.g. >100, it should be fine.
>
>
> On Monday, May 30, 2016 at 4:05:52 PM UTC-5, Jeroen van Dijk wrote:
>>
>> I'm trying to generate logical predicates in order to test a function
>> that should return the predicate in DNF. The generation seems to be biased
>> towards one of the predicates. What am I doing wrong?
>>
>> (require '[clojure.spec :as s])
>> (require '[clojure.spec.gen :as gen])
>>
>> (s/def ::atom string?)
>>
>> (s/def ::predicate (s/or
>> ::not-predicate
>> ::and-predicate
>> ::or-predicate
>> ::atom))
>>
>> (s/def ::and-predicate (s/cat :pred #{:and} :args (s/+ ::predicate)))
>> (s/def ::or-predicate (s/cat :pred #{:or} :args (s/+ ::predicate)))
>> (s/def ::not-predicate (s/tuple :pred #{:not} ::predicate))
>>
>> (prn (take 5 (gen/sample (s/gen ::predicate))))
>> ;;=>
>> ((:and (:and "")) "" "X" "G" (:and "yd" (:and "c" "" (:and "F" (:and ""
>> "8" "Hb" "U0d")) "C") (:and (:and "1" "e" (:and "ME01" "w" "Y4" "" "P4")
>> "J4m4" "8") "Q7c" "") (:and (:and (:and "" "dG"))) "gw5"))
>>
>>
>> No :or's or :not's here. If I change the order of s/or above the bias
>> changes. What's a better approach?
>>
>> Thanks,
>> Jeroen
>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.