@@ -5,7 +5,7 @@ extern crate ordered_float;
55extern crate num_traits;
66
77pub use ordered_float:: * ;
8- pub use num_traits:: { Bounded , Float , One , Zero } ;
8+ pub use num_traits:: { Bounded , Float , FromPrimitive , One , Zero } ;
99pub use std:: cmp:: Ordering :: * ;
1010pub use std:: { f32, f64, panic} ;
1111
@@ -118,6 +118,25 @@ describe! not_nan32 {
118118 assert_eq!( NotNaN :: <f32 >:: min_value( ) , NotNaN :: from( <f32 as Bounded >:: min_value( ) ) ) ;
119119 assert_eq!( NotNaN :: <f32 >:: max_value( ) , NotNaN :: from( <f32 as Bounded >:: max_value( ) ) ) ;
120120 }
121+
122+ it "should implement FromPrimitive" {
123+ assert_eq!( NotNaN :: <f32 >:: from_i8( 42i8 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
124+ assert_eq!( NotNaN :: <f32 >:: from_u8( 42u8 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
125+ assert_eq!( NotNaN :: <f32 >:: from_i16( 42i16 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
126+ assert_eq!( NotNaN :: <f32 >:: from_u16( 42u16 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
127+ assert_eq!( NotNaN :: <f32 >:: from_i32( 42i32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
128+ assert_eq!( NotNaN :: <f32 >:: from_u32( 42u32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
129+ assert_eq!( NotNaN :: <f32 >:: from_i64( 42i64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
130+ assert_eq!( NotNaN :: <f32 >:: from_u64( 42u64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
131+ assert_eq!( NotNaN :: <f32 >:: from_isize( 42isize ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
132+ assert_eq!( NotNaN :: <f32 >:: from_usize( 42usize ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
133+ assert_eq!( NotNaN :: <f32 >:: from_f32( 42f32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
134+ assert_eq!( NotNaN :: <f32 >:: from_f32( 42f32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
135+ assert_eq!( NotNaN :: <f32 >:: from_f64( 42f64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
136+ assert_eq!( NotNaN :: <f32 >:: from_f64( 42f64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
137+ assert_eq!( NotNaN :: <f32 >:: from_f32( Float :: nan( ) ) , None ) ;
138+ assert_eq!( NotNaN :: <f32 >:: from_f64( Float :: nan( ) ) , None ) ;
139+ }
121140}
122141
123142describe ! not_nan64 {
@@ -195,6 +214,25 @@ describe! not_nan64 {
195214 assert_eq!( NotNaN :: <f64 >:: min_value( ) , NotNaN :: from( <f64 as Bounded >:: min_value( ) ) ) ;
196215 assert_eq!( NotNaN :: <f64 >:: max_value( ) , NotNaN :: from( <f64 as Bounded >:: max_value( ) ) ) ;
197216 }
217+
218+ it "should implement FromPrimitive" {
219+ assert_eq!( NotNaN :: <f64 >:: from_i8( 42i8 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
220+ assert_eq!( NotNaN :: <f64 >:: from_u8( 42u8 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
221+ assert_eq!( NotNaN :: <f64 >:: from_i16( 42i16 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
222+ assert_eq!( NotNaN :: <f64 >:: from_u16( 42u16 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
223+ assert_eq!( NotNaN :: <f64 >:: from_i32( 42i32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
224+ assert_eq!( NotNaN :: <f64 >:: from_u32( 42u32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
225+ assert_eq!( NotNaN :: <f64 >:: from_i64( 42i64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
226+ assert_eq!( NotNaN :: <f64 >:: from_u64( 42u64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
227+ assert_eq!( NotNaN :: <f64 >:: from_isize( 42isize ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
228+ assert_eq!( NotNaN :: <f64 >:: from_usize( 42usize ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
229+ assert_eq!( NotNaN :: <f64 >:: from_f32( 42f32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
230+ assert_eq!( NotNaN :: <f64 >:: from_f32( 42f32 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
231+ assert_eq!( NotNaN :: <f64 >:: from_f64( 42f64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
232+ assert_eq!( NotNaN :: <f64 >:: from_f64( 42f64 ) , Some ( NotNaN :: from( 42.0 ) ) ) ;
233+ assert_eq!( NotNaN :: <f64 >:: from_f32( Float :: nan( ) ) , None ) ;
234+ assert_eq!( NotNaN :: <f64 >:: from_f64( Float :: nan( ) ) , None ) ;
235+ }
198236}
199237
200238describe ! hashing {
0 commit comments