@@ -87,6 +87,7 @@ where F: Float, OpenClosed01: Distribution<F>
8787#[ cfg( test) ]
8888mod tests {
8989 use super :: * ;
90+ use core:: fmt:: { Debug , Display } ;
9091
9192 #[ test]
9293 #[ should_panic]
@@ -108,21 +109,20 @@ mod tests {
108109
109110 #[ test]
110111 fn value_stability ( ) {
111- fn test_samples < F : Float + core :: fmt :: Debug , D : Distribution < F > > (
112- distr : D , zero : F , expected : & [ F ] ,
112+ fn test_samples < F : Float + Debug + Display , D : Distribution < F > > (
113+ distr : D , thresh : F , expected : & [ F ] ,
113114 ) {
114115 let mut rng = crate :: test:: rng ( 213 ) ;
115- let mut buf = [ zero ; 4 ] ;
116- for x in & mut buf {
117- * x = rng . sample ( & distr ) ;
116+ for v in expected {
117+ let x = rng . sample ( & distr ) ;
118+ assert ! ( ( x - * v ) . abs ( ) < thresh , "not approx eq: {}, {}" , x , * v ) ;
118119 }
119- assert_eq ! ( buf, expected) ;
120120 }
121121
122- test_samples ( Pareto :: new ( 1.0 , 1.0 ) . unwrap ( ) , 0f32 , & [
122+ test_samples ( Pareto :: new ( 1f32 , 1.0 ) . unwrap ( ) , 1e-6 , & [
123123 1.0423688 , 2.1235929 , 4.132709 , 1.4679428 ,
124124 ] ) ;
125- test_samples ( Pareto :: new ( 2.0 , 0.5 ) . unwrap ( ) , 0f64 , & [
125+ test_samples ( Pareto :: new ( 2.0 , 0.5 ) . unwrap ( ) , 1e-14 , & [
126126 9.019295276219136 ,
127127 4.3097126018270595 ,
128128 6.837815045397157 ,
0 commit comments