@@ -115,7 +115,7 @@ impl_tuple_vec!((i32, f32): x: x.0, x.1);
115
115
impl_tuple_vec ! ( ( f32 , f32 , f32 ) : x: x. 0 , x. 1 , x. 2 ) ;
116
116
impl_tuple_vec ! ( ( f64 , f64 , f64 ) : x: x. 0 , x. 1 , x. 2 ) ;
117
117
118
- /// Kind of LibmApi - used to handle generating tests
118
+ /// Kind of libm API - used to handle generating tests
119
119
/// for some functions slightly differently.
120
120
#[ derive( Copy , Clone , Debug , PartialEq ) ]
121
121
pub enum ApiKind {
@@ -155,7 +155,7 @@ macro_rules! assert_approx_eq {
155
155
if !$crate:: WithinUlps :: within_ulps( $result, $expected, $ulps) {
156
156
panic!( "{:?} != {:?}" , $result, $expected) ;
157
157
}
158
- }
158
+ } ;
159
159
}
160
160
161
161
pub trait Toward : Sized {
@@ -190,8 +190,10 @@ pub trait RandSeq: Sized {
190
190
191
191
macro_rules! impl_rand_seq_f {
192
192
( $float_ty: ident) => {
193
+ #[ allow( clippy:: use_self) ]
193
194
impl RandSeq for $float_ty {
194
195
fn rand_seq<R : rand:: Rng >( rng: & mut R , _api_kind: ApiKind , len: usize ) -> Vec <Self > {
196
+ use rand:: seq:: SliceRandom ;
195
197
use std:: $float_ty:: * ;
196
198
let mut vec = Vec :: with_capacity( len) ;
197
199
@@ -212,12 +214,12 @@ macro_rules! impl_rand_seq_f {
212
214
const NSTEPS : usize = 1_000 ;
213
215
vec. extend( INFINITY . toward( 0. , NSTEPS ) ) ;
214
216
vec. extend( NEG_INFINITY . toward( 0. , NSTEPS ) ) ;
215
- vec. extend( ( 0. as $float_ty ) . toward( MIN_POSITIVE , NSTEPS ) ) ;
216
- vec. extend( ( 0. as $float_ty ) . toward( -MIN_POSITIVE , NSTEPS ) ) ;
217
+ vec. extend( ( 0. as Self ) . toward( MIN_POSITIVE , NSTEPS ) ) ;
218
+ vec. extend( ( 0. as Self ) . toward( -MIN_POSITIVE , NSTEPS ) ) ;
217
219
218
220
for i in 0 ..=NSTEPS {
219
- let dx = 2. / NSTEPS as $float_ty ;
220
- let next = ( -1. as $float_ty ) + ( i as $float_ty ) * dx;
221
+ let dx = 2. / NSTEPS as Self ;
222
+ let next = ( -1. as Self ) + ( i as Self ) * dx;
221
223
vec. push( next) ;
222
224
}
223
225
@@ -227,10 +229,18 @@ macro_rules! impl_rand_seq_f {
227
229
let remaining_len = len. checked_sub( current_len) . unwrap( ) ;
228
230
229
231
for _ in 0 ..remaining_len {
230
- let n = rng. gen :: <$float_ty >( ) ;
232
+ let n = rng. gen :: <Self >( ) ;
231
233
vec. push( n) ;
232
234
}
233
235
assert_eq!( vec. len( ) , len) ;
236
+
237
+ // Duplicate the vector, randomly shuffle it, and
238
+ // concatenate it. Otherwise for n-ary functions
239
+ // all vectors might have the same values. But
240
+ // testing with the same values is also worth doing.
241
+ let mut vec2 = vec. clone( ) ;
242
+ vec2. shuffle( rng) ;
243
+ vec. extend( vec2) ;
234
244
vec
235
245
}
236
246
}
@@ -242,15 +252,24 @@ impl_rand_seq_f!(f64);
242
252
243
253
impl RandSeq for i32 {
244
254
fn rand_seq < R : rand:: Rng > ( rng : & mut R , api_kind : ApiKind , len : usize ) -> Vec < Self > {
255
+ use rand:: seq:: SliceRandom ;
245
256
let mut v = Vec :: with_capacity ( len) ;
246
257
for _ in 0 ..len {
247
- let mut r = rng. gen :: < i32 > ( ) ;
258
+ let mut r = rng. gen :: < Self > ( ) ;
248
259
if let ApiKind :: Jx = api_kind {
249
260
r &= 0xffff ;
250
261
}
251
262
v. push ( r) ;
252
263
}
253
264
assert_eq ! ( v. len( ) , len) ;
265
+
266
+ // Duplicate the vector, randomly shuffle it, and
267
+ // concatenate it. Otherwise for n-ary functions
268
+ // all vectors might have the same values. But
269
+ // testing with the same values is also worth doing.
270
+ let mut v2 = v. clone ( ) ;
271
+ v2. shuffle ( rng) ;
272
+ v. extend ( v2) ;
254
273
v
255
274
}
256
275
}
0 commit comments