Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Comparing `-coll-gen` and `-coll-gen-distict` in the `malli.generator`
namespace, it seems there was no reason for the latter to handle
recursive generation any different. Both implementations now create a
generator based on the same initial conditions.
  • Loading branch information
helins committed Apr 27, 2021
1 parent 821c0ca commit fca90f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/malli/generator.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
(let [{:keys [min max]} (-min-max schema options)
[continue options] (-recur schema options)
child (-> schema m/children first)
gen (if continue (generator child options))]
gen (when continue (generator child options))]
(gen/fmap f (cond
(not gen) (gen/vector gen/any 0 0)
(and min (= min max)) (gen/vector gen min)
Expand All @@ -63,8 +63,7 @@
(let [{:keys [min max]} (-min-max schema options)
[continue options] (-recur schema options)
child (-> schema m/children first)
gen (if-not (and (= :ref (m/type child)) continue (<= (or min 0) 0))
(generator child options))]
gen (when continue (generator child options))]
(gen/fmap f (if gen
(gen/vector-distinct gen {:min-elements min, :max-elements max, :max-tries 100})
(gen/vector gen/any 0 0)))))
Expand Down
7 changes: 7 additions & 0 deletions test/malli/generator_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,10 @@
::E]
valid? (m/validator schema)]
(is (every? valid? (mg/sample schema {:size 10000})))))

(deftest recursive-distinct-col-test
(is (not (every? empty?
(mg/sample [:set
{:registry {::foo :int}}
[:ref ::foo]]
{:size 1000})))))

0 comments on commit fca90f9

Please sign in to comment.