Stream: general

Topic: repeatable arbitrary


Jake Goulding (Jan 11 2019 at 00:08, on Zulip):

@centril If I wanted to use Arbitraryoutside of proptest to generate test data, how could I make it repeatable? For example, is there a way I can control the RNG and its seed?

centril (Jan 11 2019 at 00:11, on Zulip):

@Jake Goulding so what Arbitrary::arbitrary does is merely return a type that implements Strategy; A strategy then defines how to generate a ValueTree (which defines how to shrink + produce values) based on a TestRunner that it gets as an argument to new_tree; what the proptest! { .. } macro does is the setup of the test runner and such behind the scenes

centril (Jan 11 2019 at 00:11, on Zulip):

https://altsysrq.github.io/rustdoc/proptest/latest/proptest/strategy/trait.Strategy.html#tymethod.new_tree

centril (Jan 11 2019 at 00:12, on Zulip):

https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.TestRunner.html

centril (Jan 11 2019 at 00:12, on Zulip):

you can tweak the Config there for example

Jake Goulding (Jan 11 2019 at 00:12, on Zulip):

outside of proptest

Jake Goulding (Jan 11 2019 at 00:13, on Zulip):

i.e. the arbitrary crate (that is related, yeah?)

centril (Jan 11 2019 at 00:13, on Zulip):

@Jake Goulding no, that has nothing to do with proptest's version of Arbitrary

Jake Goulding (Jan 11 2019 at 00:14, on Zulip):

that's unfortunate. Now I need to read different docs

Jake Goulding (Jan 11 2019 at 00:14, on Zulip):

Maybe my question would then be... "is it useful to use proptest's Arbitrary to generate test data outside of directly used in proptest"

centril (Jan 11 2019 at 00:15, on Zulip):

proptest and the quickcheck crate's model of property based testing differ entirely; proptest uses value based integrated shrinking and then uses Arbitrary to define canonical strategies for a type whereas the quickcheck crate uses type based shrinking

Jake Goulding (Jan 11 2019 at 00:15, on Zulip):

I am aware of that, but I do not see how that relates to the topic at hand

centril (Jan 11 2019 at 00:15, on Zulip):

hmm, lemme think about it a bit

Jake Goulding (Jan 11 2019 at 00:15, on Zulip):

one step higher: I'd like to be able to generate 100MB of XML easily and test speed between my library and libxml

Jake Goulding (Jan 11 2019 at 00:16, on Zulip):

I don't want to check in 100MB files

centril (Jan 11 2019 at 00:16, on Zulip):

@Jake Goulding you don't care about shrinking then?

Jake Goulding (Jan 11 2019 at 00:16, on Zulip):

For that, no. But I would love to be able to reuse this code for actual proptesting

Jake Goulding (Jan 11 2019 at 00:16, on Zulip):

where shrinking is much more useful

Jake Goulding (Jan 11 2019 at 00:17, on Zulip):

For speed tests, I'd just want control over the "size"

centril (Jan 11 2019 at 00:20, on Zulip):

OK; so outside of the definition of a Strategy, the only control over generation you have is the parameters you can set in https://altsysrq.github.io/rustdoc/proptest/latest/proptest/test_runner/struct.Config.html, e.g. cases: u32 -- if you want to just generate a bunch of <Foo as Strategy>::Value objects, then you can make a TestRunner::new(my_config), instantiate your strategy, and then call new_tree(the_runner).unwrap().current() a bunch of times

centril (Jan 11 2019 at 00:21, on Zulip):

current() should always give you the same thing, so new_tree is what you use to change the value generated

centril (Jan 11 2019 at 00:22, on Zulip):

actually if you want to do this you don't need to touch cases at all since you are deciding how many to generate

centril (Jan 11 2019 at 00:22, on Zulip):

might be useful to add a facility like this to proptest upstream

centril (Jan 11 2019 at 00:23, on Zulip):

There will be some overhead cause proptest will include state that is only useful to shrinking

centril (Jan 11 2019 at 00:23, on Zulip):

(but useless if you are not interested in shrinking)

centril (Jan 11 2019 at 00:23, on Zulip):

@Jake Goulding does that answer the question?

centril (Jan 11 2019 at 00:28, on Zulip):

maybe it would be good to have fn values<S: Strategy>(self, strat: S) -> impl Iterator<Item = S::Value> or something in TestRunner

Jake Goulding (Jan 11 2019 at 02:29, on Zulip):

It sounds like I should file an issue, to see if folk would find this or something similar useful

centril (Jan 11 2019 at 02:30, on Zulip):

@Jake Goulding yeah please do

centril (Jan 11 2019 at 02:30, on Zulip):

(and cc me)

Last update: Nov 22 2019 at 00:00UTC