Hello I’m trying to use test.check to generate a string that is formatted as MM/dd/yyyy.
I have the following function
(defn- gen-date [start end]
(tgen/let [months (tgen/choose 1 12)
days (tgen/choose 1 31)
years (tgen/choose start end)
padding (fn [num-to-pad]
(if (< 1 num-to-pad 9)
(clojure.string/join "" [0 num-to-pad])
(str num-to-pad)))
month-str (tgen/fmap #(padding %) months)
day-str (tgen/fmap #(padding %) days)
year-str (tgen/fmap str years)]
(let [m (tgen/one-of [month-str])
d (tgen/one-of [day-str])
y (tgen/one-of [year-str])]
(tgen/fmap clojure.string/join "/" [m d y]))))
I can’t seem to wrap my head around the last step which is to merge all the generators into a generator that will produce the final string.
tgen is an alias for test.check.generators. Any insight will be greatly appreciated.
2 posts - 2 participants