@@ -1622,7 +1622,7 @@ mod impl_schemars {
16221622 }
16231623}
16241624
1625- #[ cfg( all ( feature = "std" , feature = " rand") ) ]
1625+ #[ cfg( feature = "rand" ) ]
16261626mod impl_rand {
16271627 use super :: { NotNan , OrderedFloat } ;
16281628 use rand:: distributions:: uniform:: * ;
@@ -1720,63 +1720,67 @@ mod impl_rand {
17201720 impl_uniform_sampler ! { f32 }
17211721 impl_uniform_sampler ! { f64 }
17221722
1723- #[ cfg( test) ]
1724- fn sample_fuzz < T > ( )
1725- where
1726- Standard : Distribution < NotNan < T > > ,
1727- Open01 : Distribution < NotNan < T > > ,
1728- OpenClosed01 : Distribution < NotNan < T > > ,
1729- Standard : Distribution < OrderedFloat < T > > ,
1730- Open01 : Distribution < OrderedFloat < T > > ,
1731- OpenClosed01 : Distribution < OrderedFloat < T > > ,
1732- T : super :: Float ,
1733- {
1734- let mut rng = rand:: thread_rng ( ) ;
1735- let f1: NotNan < T > = rng. sample ( Standard ) ;
1736- let f2: NotNan < T > = rng. sample ( Open01 ) ;
1737- let f3: NotNan < T > = rng. sample ( OpenClosed01 ) ;
1738- let _: OrderedFloat < T > = rng. sample ( Standard ) ;
1739- let _: OrderedFloat < T > = rng. sample ( Open01 ) ;
1740- let _: OrderedFloat < T > = rng. sample ( OpenClosed01 ) ;
1741- assert ! ( !f1. into_inner( ) . is_nan( ) ) ;
1742- assert ! ( !f2. into_inner( ) . is_nan( ) ) ;
1743- assert ! ( !f3. into_inner( ) . is_nan( ) ) ;
1744- }
1723+ #[ cfg( all( test, feature = "randtest" ) ) ]
1724+ mod tests {
1725+ use super :: * ;
17451726
1746- #[ test]
1747- fn sampling_f32_does_not_panic ( ) {
1748- sample_fuzz :: < f32 > ( ) ;
1749- }
1727+ fn sample_fuzz < T > ( )
1728+ where
1729+ Standard : Distribution < NotNan < T > > ,
1730+ Open01 : Distribution < NotNan < T > > ,
1731+ OpenClosed01 : Distribution < NotNan < T > > ,
1732+ Standard : Distribution < OrderedFloat < T > > ,
1733+ Open01 : Distribution < OrderedFloat < T > > ,
1734+ OpenClosed01 : Distribution < OrderedFloat < T > > ,
1735+ T : crate :: Float ,
1736+ {
1737+ let mut rng = rand:: thread_rng ( ) ;
1738+ let f1: NotNan < T > = rng. sample ( Standard ) ;
1739+ let f2: NotNan < T > = rng. sample ( Open01 ) ;
1740+ let f3: NotNan < T > = rng. sample ( OpenClosed01 ) ;
1741+ let _: OrderedFloat < T > = rng. sample ( Standard ) ;
1742+ let _: OrderedFloat < T > = rng. sample ( Open01 ) ;
1743+ let _: OrderedFloat < T > = rng. sample ( OpenClosed01 ) ;
1744+ assert ! ( !f1. into_inner( ) . is_nan( ) ) ;
1745+ assert ! ( !f2. into_inner( ) . is_nan( ) ) ;
1746+ assert ! ( !f3. into_inner( ) . is_nan( ) ) ;
1747+ }
17501748
1751- #[ test]
1752- fn sampling_f64_does_not_panic ( ) {
1753- sample_fuzz :: < f64 > ( ) ;
1754- }
1749+ #[ test]
1750+ fn sampling_f32_does_not_panic ( ) {
1751+ sample_fuzz :: < f32 > ( ) ;
1752+ }
17551753
1756- #[ test]
1757- #[ should_panic]
1758- fn uniform_sampling_panic_on_infinity_notnan ( ) {
1759- let ( low, high) = (
1760- NotNan :: new ( 0f64 ) . unwrap ( ) ,
1761- NotNan :: new ( std:: f64:: INFINITY ) . unwrap ( ) ,
1762- ) ;
1763- let uniform = Uniform :: new ( low, high) ;
1764- let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1765- }
1754+ #[ test]
1755+ fn sampling_f64_does_not_panic ( ) {
1756+ sample_fuzz :: < f64 > ( ) ;
1757+ }
17661758
1767- #[ test]
1768- #[ should_panic]
1769- fn uniform_sampling_panic_on_infinity_ordered ( ) {
1770- let ( low, high) = ( OrderedFloat ( 0f64 ) , OrderedFloat ( std:: f64:: INFINITY ) ) ;
1771- let uniform = Uniform :: new ( low, high) ;
1772- let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1773- }
1759+ #[ test]
1760+ #[ should_panic]
1761+ fn uniform_sampling_panic_on_infinity_notnan ( ) {
1762+ let ( low, high) = (
1763+ NotNan :: new ( 0f64 ) . unwrap ( ) ,
1764+ NotNan :: new ( core:: f64:: INFINITY ) . unwrap ( ) ,
1765+ ) ;
1766+ let uniform = Uniform :: new ( low, high) ;
1767+ let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1768+ }
17741769
1775- #[ test]
1776- #[ should_panic]
1777- fn uniform_sampling_panic_on_nan_ordered ( ) {
1778- let ( low, high) = ( OrderedFloat ( 0f64 ) , OrderedFloat ( std:: f64:: NAN ) ) ;
1779- let uniform = Uniform :: new ( low, high) ;
1780- let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1770+ #[ test]
1771+ #[ should_panic]
1772+ fn uniform_sampling_panic_on_infinity_ordered ( ) {
1773+ let ( low, high) = ( OrderedFloat ( 0f64 ) , OrderedFloat ( core:: f64:: INFINITY ) ) ;
1774+ let uniform = Uniform :: new ( low, high) ;
1775+ let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1776+ }
1777+
1778+ #[ test]
1779+ #[ should_panic]
1780+ fn uniform_sampling_panic_on_nan_ordered ( ) {
1781+ let ( low, high) = ( OrderedFloat ( 0f64 ) , OrderedFloat ( core:: f64:: NAN ) ) ;
1782+ let uniform = Uniform :: new ( low, high) ;
1783+ let _ = uniform. sample ( & mut rand:: thread_rng ( ) ) ;
1784+ }
17811785 }
17821786}
0 commit comments