Open arichiardi opened 8 years ago
The best option here (when you have a constraint that's hard to satisfy via random generation) is to pass a custom generator into the generation process for the constrained schema which always produces values that satisfy the constraints. generate
takes a map of leaf generators for this purpose, you can see examples in the test. Happy to elaborate if you like.
Ok thanks, let me check the tests first, I am now familiar with leaf generator. I just need to know in my case which is the leaf, I guess s/constrained
returns a map so I will put directly the (lt NonEmptyStr 40)
as key right?
I would recommend def
ing the schema you want to generate (e.g. (def UserId (lt NonEmptyStr 40))
) and then using the var UserId
as the key -- that way there won't be any potential issues with equality, especially if you update the schema later.
Very often I receive the dreaded:
Especially with this schema:
I was checking and
such-that
can increase the number of tries: https://clojure.github.io/test.check/clojure.test.check.generators.html#var-such-thatMaybe we can have a dynamic var to pass in there?
PS: Is the above a good way to handle that case? I am still pretty new to
schema
.