@@ -202,6 +202,35 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
202
202
total
203
203
}
204
204
205
+ #[ cfg( test) ]
206
+ fn test_num < T : Num + NumCast > ( ten : T , two : T ) {
207
+ assert ! ( ten. add( & two) == cast( 12 ) ) ;
208
+ assert ! ( ten. sub( & two) == cast( 8 ) ) ;
209
+ assert ! ( ten. mul( & two) == cast( 20 ) ) ;
210
+ assert ! ( ten. div( & two) == cast( 5 ) ) ;
211
+ assert ! ( ten. modulo( & two) == cast( 0 ) ) ;
212
+
213
+ assert ! ( ten. add( & two) == ten + two) ;
214
+ assert ! ( ten. sub( & two) == ten - two) ;
215
+ assert ! ( ten. mul( & two) == ten * two) ;
216
+ assert ! ( ten. div( & two) == ten / two) ;
217
+ assert ! ( ten. modulo( & two) == ten % two) ;
218
+ }
219
+
220
+ #[ test] fn test_u8_num ( ) { test_num ( 10u8 , 2u8 ) }
221
+ #[ test] fn test_u16_num ( ) { test_num ( 10u16 , 2u16 ) }
222
+ #[ test] fn test_u32_num ( ) { test_num ( 10u32 , 2u32 ) }
223
+ #[ test] fn test_u64_num ( ) { test_num ( 10u64 , 2u64 ) }
224
+ #[ test] fn test_uint_num ( ) { test_num ( 10 u, 2 u) }
225
+ #[ test] fn test_i8_num ( ) { test_num ( 10i8 , 2i8 ) }
226
+ #[ test] fn test_i16_num ( ) { test_num ( 10i16 , 2i16 ) }
227
+ #[ test] fn test_i32_num ( ) { test_num ( 10i32 , 2i32 ) }
228
+ #[ test] fn test_i64_num ( ) { test_num ( 10i64 , 2i64 ) }
229
+ #[ test] fn test_int_num ( ) { test_num ( 10 i, 2 i) }
230
+ #[ test] fn test_f32_num ( ) { test_num ( 10f32 , 2f32 ) }
231
+ #[ test] fn test_f64_num ( ) { test_num ( 10f64 , 2f64 ) }
232
+ #[ test] fn test_float_num ( ) { test_num ( 10 f, 2 f) }
233
+
205
234
macro_rules! test_cast_20(
206
235
( $_20: expr) => ( {
207
236
let _20 = $_20;
@@ -263,26 +292,3 @@ macro_rules! test_cast_20(
263
292
#[ test] fn test_f32_cast ( ) { test_cast_20 ! ( 20f32 ) }
264
293
#[ test] fn test_f64_cast ( ) { test_cast_20 ! ( 20f64 ) }
265
294
#[ test] fn test_float_cast ( ) { test_cast_20 ! ( 20 f) }
266
-
267
- #[ test]
268
- fn test_generic_cast ( ) {
269
- use ops:: Add ;
270
-
271
- fn add_2 < T : Add < T , T > + NumCast > ( n : T ) -> T {
272
- n + cast ( 2 )
273
- }
274
-
275
- assert ! ( add_2( 1 u) == 3 u) ;
276
- assert ! ( add_2( 1u8 ) == 3u8 ) ;
277
- assert ! ( add_2( 1u16 ) == 3u16 ) ;
278
- assert ! ( add_2( 1u32 ) == 3u32 ) ;
279
- assert ! ( add_2( 1u64 ) == 3u64 ) ;
280
- assert ! ( add_2( 1 i) == 3 i) ;
281
- assert ! ( add_2( 1i8 ) == 3i8 ) ;
282
- assert ! ( add_2( 1i16 ) == 3i16 ) ;
283
- assert ! ( add_2( 1i32 ) == 3i32 ) ;
284
- assert ! ( add_2( 1i64 ) == 3i64 ) ;
285
- assert ! ( add_2( 1 f) == 3 f) ;
286
- assert ! ( add_2( 1f32 ) == 3f32 ) ;
287
- assert ! ( add_2( 1f64 ) == 3f64 ) ;
288
- }
0 commit comments