1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crateBoxGen;
use crateBoxIter;
use crateExampleSize;
use crateGen;
use crateSeed;
/// Create a new generator where each request for examples-iterator calls the
/// provided closure `F: Fn(Seed, ExampleSize) -> Iterator<Item=E> + Clone + 'static`.
///
/// The argument to the closure is the randomisation seed provided by
/// Monkey Test.
///
/// Please note! No shrinker is associated with the resulting generator, so
/// shrinker need to be provided too. That can be done by using either
/// [Gen::with_shrinker] or [crate::gens::other_shrinker], alternatively provide
/// at place of testing the propery with [crate::ConfAndGen::with_shrinker]
///
/// For alternatives, see [from_fn_boxed].
///
/// ```rust
/// use monkey_test::*;
///
/// // Creating a generator by providing closure returning an iterator.
/// let my_gen = gens::from_fn(|seed, _size| std::iter::repeat(42));
///
/// // First alternative for providing a shrinker - attaching it to the generator.
/// let my_shrinking_gen = my_gen.with_shrinker(shrinks::int_to_zero());
/// monkey_test()
/// .with_generator(my_shrinking_gen)
/// .test_true(|n| n <= 10)
/// .assert_minimum_failure(11);
///
/// // Second alternative for providing a shrinker - explicitly providing it at
/// // point of property testing.
/// monkey_test()
/// .with_generator(my_gen)
/// .with_shrinker(shrinks::int_to_zero())
/// .test_true(|n| n <= 10)
/// .assert_minimum_failure(11);
/// ```
///
/// Create a new generator where each request for examples-iterator calls the
/// provided closure `F: Fn(Seed, ExampleSize) -> BoxIter<E> + Clone + 'static`.
///
/// This function does the same thing as [from_fn], but with the exception that
/// the returned iterator must be boxed, as in being a trait object. This can
/// be convenient when the closure want to return one of several different
/// iterator implementations, hence iterator type being unclear.
///
/// For more details see [from_fn].
///
/// ```rust
/// use monkey_test::*;
///
/// // Creating a generator by providing closure returning a boxed iterator.
/// let my_gen: BoxGen<i64> =
/// gens::from_fn_boxed(|seed, _size| Box::new(std::iter::repeat(42)));
/// ```
///
+ Clone + 'static,