@@ -115,7 +115,7 @@ impl_tuple_vec!((i32, f32): x: x.0, x.1);
115115impl_tuple_vec ! ( ( f32 , f32 , f32 ) : x: x. 0 , x. 1 , x. 2 ) ;
116116impl_tuple_vec ! ( ( f64 , f64 , f64 ) : x: x. 0 , x. 1 , x. 2 ) ;
117117
118- /// Kind of LibmApi - used to handle generating tests
118+ /// Kind of libm API - used to handle generating tests
119119/// for some functions slightly differently.
120120#[ derive( Copy , Clone , Debug , PartialEq ) ]
121121pub enum ApiKind {
@@ -155,7 +155,7 @@ macro_rules! assert_approx_eq {
155155 if !$crate:: WithinUlps :: within_ulps( $result, $expected, $ulps) {
156156 panic!( "{:?} != {:?}" , $result, $expected) ;
157157 }
158- }
158+ } ;
159159}
160160
161161pub trait Toward : Sized {
@@ -190,8 +190,10 @@ pub trait RandSeq: Sized {
190190
191191macro_rules! impl_rand_seq_f {
192192 ( $float_ty: ident) => {
193+ #[ allow( clippy:: use_self) ]
193194 impl RandSeq for $float_ty {
194195 fn rand_seq<R : rand:: Rng >( rng: & mut R , _api_kind: ApiKind , len: usize ) -> Vec <Self > {
196+ use rand:: seq:: SliceRandom ;
195197 use std:: $float_ty:: * ;
196198 let mut vec = Vec :: with_capacity( len) ;
197199
@@ -212,12 +214,12 @@ macro_rules! impl_rand_seq_f {
212214 const NSTEPS : usize = 1_000 ;
213215 vec. extend( INFINITY . toward( 0. , NSTEPS ) ) ;
214216 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 ) ) ;
217219
218220 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;
221223 vec. push( next) ;
222224 }
223225
@@ -227,10 +229,18 @@ macro_rules! impl_rand_seq_f {
227229 let remaining_len = len. checked_sub( current_len) . unwrap( ) ;
228230
229231 for _ in 0 ..remaining_len {
230- let n = rng. gen :: <$float_ty >( ) ;
232+ let n = rng. gen :: <Self >( ) ;
231233 vec. push( n) ;
232234 }
233235 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) ;
234244 vec
235245 }
236246 }
@@ -242,15 +252,24 @@ impl_rand_seq_f!(f64);
242252
243253impl RandSeq for i32 {
244254 fn rand_seq < R : rand:: Rng > ( rng : & mut R , api_kind : ApiKind , len : usize ) -> Vec < Self > {
255+ use rand:: seq:: SliceRandom ;
245256 let mut v = Vec :: with_capacity ( len) ;
246257 for _ in 0 ..len {
247- let mut r = rng. gen :: < i32 > ( ) ;
258+ let mut r = rng. gen :: < Self > ( ) ;
248259 if let ApiKind :: Jx = api_kind {
249260 r &= 0xffff ;
250261 }
251262 v. push ( r) ;
252263 }
253264 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) ;
254273 v
255274 }
256275}
0 commit comments