@@ -1622,7 +1622,7 @@ mod impl_schemars {
1622
1622
}
1623
1623
}
1624
1624
1625
- #[ cfg( all ( feature = "std" , feature = " rand") ) ]
1625
+ #[ cfg( feature = "rand" ) ]
1626
1626
mod impl_rand {
1627
1627
use super :: { NotNan , OrderedFloat } ;
1628
1628
use rand:: distributions:: uniform:: * ;
@@ -1720,63 +1720,67 @@ mod impl_rand {
1720
1720
impl_uniform_sampler ! { f32 }
1721
1721
impl_uniform_sampler ! { f64 }
1722
1722
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 :: * ;
1745
1726
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
+ }
1750
1748
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
+ }
1755
1753
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
+ }
1766
1758
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
+ }
1774
1769
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
+ }
1781
1785
}
1782
1786
}
0 commit comments