@@ -934,11 +934,8 @@ impl UniformSampler for UniformDuration {
934
934
935
935
#[ cfg( test) ]
936
936
mod tests {
937
- use crate :: Rng ;
937
+ use super :: * ;
938
938
use crate :: rngs:: mock:: StepRng ;
939
- use crate :: distributions:: uniform:: Uniform ;
940
- use crate :: distributions:: utils:: FloatAsSIMD ;
941
- #[ cfg( feature="simd_support" ) ] use packed_simd:: * ;
942
939
943
940
#[ should_panic]
944
941
#[ test]
@@ -1268,4 +1265,42 @@ mod tests {
1268
1265
assert ! ( r. 0 . scale > 5.0 ) ;
1269
1266
assert ! ( r. 0 . scale < 5.0 + 1e-14 ) ;
1270
1267
}
1268
+
1269
+ #[ test]
1270
+ fn value_stability ( ) {
1271
+ fn test_samples < T : SampleUniform + Copy + core:: fmt:: Debug + PartialEq > (
1272
+ lb : T , ub : T , expected_single : & [ T ] , expected_multiple : & [ T ]
1273
+ )
1274
+ where Uniform < T > : Distribution < T >
1275
+ {
1276
+ let mut rng = crate :: test:: rng ( 897 ) ;
1277
+ let mut buf = [ lb; 3 ] ;
1278
+
1279
+ for x in & mut buf {
1280
+ * x = T :: Sampler :: sample_single ( lb, ub, & mut rng) ;
1281
+ }
1282
+ assert_eq ! ( & buf, expected_single) ;
1283
+
1284
+ let distr = Uniform :: new ( lb, ub) ;
1285
+ for x in & mut buf {
1286
+ * x = rng. sample ( & distr) ;
1287
+ }
1288
+ assert_eq ! ( & buf, expected_multiple) ;
1289
+ }
1290
+
1291
+ // We test on a sub-set of types; possibly we should do more.
1292
+ // TODO: SIMD types
1293
+
1294
+ test_samples ( 11u8 , 219 , & [ 17 , 66 , 214 ] , & [ 181 , 93 , 165 ] ) ;
1295
+ test_samples ( 11u32 , 219 , & [ 17 , 66 , 214 ] , & [ 181 , 93 , 165 ] ) ;
1296
+
1297
+ test_samples ( 0f32 , 1e-2f32 , & [ 0.0003070104 , 0.0026630748 , 0.00979833 ] ,
1298
+ & [ 0.008194133 , 0.00398172 , 0.007428536 ] ) ;
1299
+ test_samples ( -1e10f64 , 1e10f64 ,
1300
+ & [ -4673848682.871551 , 6388267422.932352 , 4857075081.198343 ] ,
1301
+ & [ 1173375212.1808167 , 1917642852.109581 , 2365076174.3153973 ] ) ;
1302
+
1303
+ test_samples ( Duration :: new ( 2 , 0 ) , Duration :: new ( 4 , 0 ) ,
1304
+ & [ Duration :: new ( 2 , 532615131 ) , Duration :: new ( 3 , 638826742 ) , Duration :: new ( 3 , 485707508 ) ] , & [ Duration :: new ( 3 , 117337521 ) , Duration :: new ( 3 , 191764285 ) , Duration :: new ( 3 , 236507617 ) ] ) ;
1305
+ }
1271
1306
}
0 commit comments