Module zebra_test::prelude::prop::result
Expand description
Strategies for combining delegate strategies into std::Result
s.
That is, the strategies here are for producing Ok
and Err
cases. To
simply adapt a strategy producing T
into Result<T, something>
which is
always Ok
, you can do something like base_strategy.prop_map(Ok)
to
simply wrap the generated values.
Note that there are two nearly identical APIs for doing this, termed “maybe
ok” and “maybe err”. The difference between the two is in how they shrink;
“maybe ok” treats Ok
as the special case and shrinks to Err
;
conversely, “maybe err” treats Err
as the special case and shrinks to
Ok
. Which to use largely depends on the code being tested; if the code
typically handles errors by immediately bailing out and doing nothing else,
“maybe ok” is likely more suitable, as shrinking will cause the code to
take simpler paths. On the other hand, functions that need to make a
complicated or fragile “back out” process on error are better tested with
“maybe err” since the success case results in an easier to understand code
path.
Structs§
- Strategy which generates
Result
s usingOk
andErr
values from two delegate strategies. ValueTree
type corresponding toMaybeErr
.- Strategy which generates
Result
s usingOk
andErr
values from two delegate strategies. ValueTree
type corresponding toMaybeOk
.- A probability in the range
[0.0, 1.0]
with a default of0.5
.
Functions§
- Create a strategy for
Result
s whereOk
values are taken fromt
andErr
values are taken frome
. - Create a strategy for
Result
s whereOk
values are taken fromt
andErr
values are taken frome
. - Create a strategy for
Result
s whereOk
values are taken fromt
andErr
values are taken frome
. - Create a strategy for
Result
s whereOk
values are taken fromt
andErr
values are taken frome
. - Creates a
Probability
from some value that is convertible into it.