@@ -6,14 +6,15 @@ use rand::prelude::Distribution;
6
6
use rand:: { Rng , SeedableRng } ;
7
7
use rand_chacha:: ChaCha8Rng ;
8
8
9
+ use super :: KnownSize ;
9
10
use crate :: run_cfg:: { int_range, iteration_count} ;
10
11
use crate :: { CheckCtx , GeneratorKind } ;
11
12
12
13
const SEED : [ u8 ; 32 ] = * b"3.141592653589793238462643383279" ;
13
14
14
15
/// Generate a sequence of random values of this type.
15
16
pub trait RandomInput {
16
- fn get_cases ( ctx : & CheckCtx ) -> impl Iterator < Item = Self > ;
17
+ fn get_cases ( ctx : & CheckCtx ) -> impl ExactSizeIterator < Item = Self > ;
17
18
}
18
19
19
20
/// Generate a sequence of deterministically random floats.
@@ -37,52 +38,57 @@ fn random_ints(count: u64, range: RangeInclusive<i32>) -> impl Iterator<Item = i
37
38
macro_rules! impl_random_input {
38
39
( $fty: ty) => {
39
40
impl RandomInput for ( $fty, ) {
40
- fn get_cases( ctx: & CheckCtx ) -> impl Iterator <Item = Self > {
41
+ fn get_cases( ctx: & CheckCtx ) -> impl ExactSizeIterator <Item = Self > {
41
42
let count = iteration_count( ctx, GeneratorKind :: Random , 0 ) ;
42
- random_floats( count) . map( |f: $fty| ( f, ) )
43
+ let iter = random_floats( count) . map( |f: $fty| ( f, ) ) ;
44
+ KnownSize :: new( iter, count)
43
45
}
44
46
}
45
47
46
48
impl RandomInput for ( $fty, $fty) {
47
- fn get_cases( ctx: & CheckCtx ) -> impl Iterator <Item = Self > {
49
+ fn get_cases( ctx: & CheckCtx ) -> impl ExactSizeIterator <Item = Self > {
48
50
let count0 = iteration_count( ctx, GeneratorKind :: Random , 0 ) ;
49
51
let count1 = iteration_count( ctx, GeneratorKind :: Random , 1 ) ;
50
- random_floats( count0)
51
- . flat_map( move |f1: $fty| random_floats( count1) . map( move |f2: $fty| ( f1, f2) ) )
52
+ let iter = random_floats( count0)
53
+ . flat_map( move |f1: $fty| random_floats( count1) . map( move |f2: $fty| ( f1, f2) ) ) ;
54
+ KnownSize :: new( iter, count0 * count1)
52
55
}
53
56
}
54
57
55
58
impl RandomInput for ( $fty, $fty, $fty) {
56
- fn get_cases( ctx: & CheckCtx ) -> impl Iterator <Item = Self > {
59
+ fn get_cases( ctx: & CheckCtx ) -> impl ExactSizeIterator <Item = Self > {
57
60
let count0 = iteration_count( ctx, GeneratorKind :: Random , 0 ) ;
58
61
let count1 = iteration_count( ctx, GeneratorKind :: Random , 1 ) ;
59
62
let count2 = iteration_count( ctx, GeneratorKind :: Random , 2 ) ;
60
- random_floats( count0) . flat_map( move |f1: $fty| {
63
+ let iter = random_floats( count0) . flat_map( move |f1: $fty| {
61
64
random_floats( count1) . flat_map( move |f2: $fty| {
62
65
random_floats( count2) . map( move |f3: $fty| ( f1, f2, f3) )
63
66
} )
64
- } )
67
+ } ) ;
68
+ KnownSize :: new( iter, count0 * count1 * count2)
65
69
}
66
70
}
67
71
68
72
impl RandomInput for ( i32 , $fty) {
69
- fn get_cases( ctx: & CheckCtx ) -> impl Iterator <Item = Self > {
73
+ fn get_cases( ctx: & CheckCtx ) -> impl ExactSizeIterator <Item = Self > {
70
74
let count0 = iteration_count( ctx, GeneratorKind :: Random , 0 ) ;
71
75
let count1 = iteration_count( ctx, GeneratorKind :: Random , 1 ) ;
72
76
let range0 = int_range( ctx, 0 ) ;
73
- random_ints( count0, range0)
74
- . flat_map( move |f1: i32 | random_floats( count1) . map( move |f2: $fty| ( f1, f2) ) )
77
+ let iter = random_ints( count0, range0)
78
+ . flat_map( move |f1: i32 | random_floats( count1) . map( move |f2: $fty| ( f1, f2) ) ) ;
79
+ KnownSize :: new( iter, count0 * count1)
75
80
}
76
81
}
77
82
78
83
impl RandomInput for ( $fty, i32 ) {
79
- fn get_cases( ctx: & CheckCtx ) -> impl Iterator <Item = Self > {
84
+ fn get_cases( ctx: & CheckCtx ) -> impl ExactSizeIterator <Item = Self > {
80
85
let count0 = iteration_count( ctx, GeneratorKind :: Random , 0 ) ;
81
86
let count1 = iteration_count( ctx, GeneratorKind :: Random , 1 ) ;
82
87
let range1 = int_range( ctx, 1 ) ;
83
- random_floats( count0) . flat_map( move |f1: $fty| {
88
+ let iter = random_floats( count0) . flat_map( move |f1: $fty| {
84
89
random_ints( count1, range1. clone( ) ) . map( move |f2: i32 | ( f1, f2) )
85
- } )
90
+ } ) ;
91
+ KnownSize :: new( iter, count0 * count1)
86
92
}
87
93
}
88
94
} ;
0 commit comments