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 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